From 7eff6adfe294038c723c8059a5993a533551f6cc Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 13 Aug 2019 21:32:05 +0300 Subject: Add load_default_options() function template overload that accepts tracing function --- libbutl/default-options.txx | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'libbutl/default-options.txx') diff --git a/libbutl/default-options.txx b/libbutl/default-options.txx index 42dd585..2ed12e4 100644 --- a/libbutl/default-options.txx +++ b/libbutl/default-options.txx @@ -17,14 +17,15 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // in both the directory itself and its local/ subdirectory are considered // remote (see load_default_options() for details). // - template + template void load_default_options_files (const dir_path& d, bool remote, const small_vector& fs, + F&& fn, default_options& r) { - auto load = [&fs, &r] (const dir_path& d, bool remote) + auto load = [&fs, &fn, &r] (const dir_path& d, bool remote) { using namespace std; @@ -34,6 +35,8 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. if (file_exists (p)) // Follows symlinks. { + fn (p, remote); + S s (p.string ()); // @@ Note that the potentially thrown exceptions (unknown option, @@ -63,11 +66,12 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // to the resulting list. Return true if the directory is "remote" (i.e., // belongs to a VCS repository). // - template + template bool load_default_options_files (const dir_path& start_dir, const optional& home_dir, const small_vector& fs, + F&& fn, default_options& r) { if (start_dir.root () || (home_dir && start_dir == *home_dir)) @@ -76,22 +80,28 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. bool remote (load_default_options_files (start_dir.directory (), home_dir, fs, + std::forward (fn), r) || git_repository (start_dir)); dir_path d (start_dir / dir_path (".build2")); if (dir_exists (d)) - load_default_options_files (d, remote, fs, r); + load_default_options_files (d, + remote, + fs, + std::forward (fn), + r); return remote; } - template + template default_options load_default_options (const optional& sys_dir, const optional& home_dir, - const default_options_files& ofs) + const default_options_files& ofs, + F&& fn) { default_options r; @@ -103,6 +113,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. load_default_options_files (*sys_dir, false /* remote */, ofs.files, + std::forward (fn), r); } @@ -116,6 +127,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. load_default_options_files (d, false /* remote */, ofs.files, + std::forward (fn), r); } @@ -126,6 +138,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. load_default_options_files (*ofs.start_dir, home_dir, ofs.files, + std::forward (fn), r); } @@ -136,7 +149,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. O merge_default_options (const default_options& def_ops, const O& cmd_ops, - F&& f) + F&& fn) { // Optimize for the common case. // @@ -146,21 +159,11 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. O r; for (const default_options_entry& e: def_ops) { - f (e, cmd_ops); + fn (e, cmd_ops); r.merge (e.options); } r.merge (cmd_ops); return r; } - - template - inline O - merge_default_options (const default_options& def_ops, const O& cmd_ops) - { - return merge_default_options ( - def_ops, - cmd_ops, - [] (const default_options_entry&, const O&) {}); - } } -- cgit v1.1