# # # patch "ChangeLog" # from [b3f45e326894ef89cbbd6522453ab23954db2f98] # to [a1f7b2243077ef938275e11bf3110a6bea874b1b] # # patch "option.hh" # from [7c985660c7dfa7b4bea1150175668ce131c5a9ed] # to [455df218328d318a9d31e93f84044545719bb6b3] # # patch "unit_tests.cc" # from [5f4ecf5b5eb1281973649b1cfa39077880d5e422] # to [bc945be846ca5608c6bb05e8462262c69827b681] # ============================================================ --- ChangeLog b3f45e326894ef89cbbd6522453ab23954db2f98 +++ ChangeLog a1f7b2243077ef938275e11bf3110a6bea874b1b @@ -1,3 +1,10 @@ +2006-10-22 Timothy Brownawell + + Rewrite options handling. Options are listed in options_list.hh. + options.{cc,hh} is support for this; option.{cc,hh} is options + infrastructure. unit_tests.cc uses this infrastructure directly for + handling the options that it accepts. + 2006-10-22 Matthew Nicholson * debian/monotone-server.postinst: Swap execution of 'set +e' and 'set ============================================================ --- option.hh 7c985660c7dfa7b4bea1150175668ce131c5a9ed +++ option.hh 455df218328d318a9d31e93f84044545719bb6b3 @@ -116,11 +116,6 @@ namespace option { fun(obj); } }; - template - binder_only bind_only(boost::function const & f, T * o) - { - return binder_only(f, o); - } // Options that need to be attached to some other object // in order for set and reset to be meaningful. @@ -157,7 +152,7 @@ namespace option { if (setter) out.setter = std::bind1st(setter, obj); if (resetter) - out.resetter = bind_only(resetter, obj); + out.resetter = binder_only(resetter, obj); return out; } ============================================================ --- unit_tests.cc 5f4ecf5b5eb1281973649b1cfa39077880d5e422 +++ unit_tests.cc bc945be846ca5608c6bb05e8462262c69827b681 @@ -17,8 +17,6 @@ #include #include -#include -#include #include #include @@ -149,6 +147,55 @@ namespace { typedef basic_teebuf teebuf; } +template +struct setter_class +{ + T & item; + setter_class(T & i) + : item(i) + {} + void operator()(string s) + { + item = boost::lexical_cast(s); + } +}; + +template<> +struct setter_class +{ + bool & item; + setter_class(bool & i) + : item(i) + {} + void operator()() + { + item = true; + } +}; +template +struct setter_class > +{ + vector & items; + setter_class(vector & i) + : items(i) + {} + void operator()(string s) + { + items.push_back(boost::lexical_cast(s)); + } +}; + +template +boost::function setter(T & item) +{ + return setter_class(item); +} + +boost::function setter(bool & item) +{ + return setter_class(item); +} + test_suite * init_unit_test_suite(int argc, char * argv[]) { bool help(false); @@ -157,26 +204,16 @@ test_suite * init_unit_test_suite(int ar bool debug(false); string log; vector tests; - using boost::lambda::var; - using boost::lambda::bind; - using boost::lambda::_1; - using boost::function; try { option::concrete_option_set os; - os("help,h", "display help message", - function(var(help) = true)) - ("list-groups,l", "list all test groups", - function(var(list_groups) = true)) - ("list-tests,L", "list all test cases", - function(var(list_tests) = true)) - ("debug", "write verbose debug log to stderr", - function(var(debug) = true)) + os("help,h", "display help message", setter(help)) + ("list-groups,l", "list all test groups", setter(list_groups)) + ("list-tests,L", "list all test cases", setter(list_tests)) + ("debug", "write verbose debug log to stderr", setter(debug)) ("log", "write verbose debug log to this file" - " (default is unit_tests.log)", - function(var(log) = _1)) - ("--", "", function(bind(&vector::push_back, - &tests, _1))); + " (default is unit_tests.log)", setter(log)) + ("--", "", setter(tests)); os.from_command_line(argc, argv);