[complement-svn] SF.net SVN: complement: [1881] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <Dmi...@us...> - 2008-05-24 10:09:52
|
Revision: 1881 http://complement.svn.sourceforge.net/complement/?rev=1881&view=rev Author: DmitryOsmakov Date: 2008-05-24 03:09:48 -0700 (Sat, 24 May 2008) Log Message: ----------- fixed lib Opts : bad_usage is changed to logic_error everywhere , getting option by token is added , all get is summerized in on template , get option position is added , 2 ut to enforce program correctness and help ut is added (need to later modify help func) Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/misc/ut/opts_test.h Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-05-23 10:41:10 UTC (rev 1880) +++ trunk/complement/explore/include/misc/opts.h 2008-05-24 10:09:48 UTC (rev 1881) @@ -12,20 +12,28 @@ #include <exception> #include <stdexcept> +const char* OPT_DEFAULT_DESCRIPTION = "(no description)"; +const char* OPT_DEFAULT_LONGNAME = "(no longname)"; + class Opt { public: - Opt() { cnt = 0; } + Opt() { cnt = 0 , shortname = ' '; } char shortname; std::string longname; std::string desc; std::string default_v; + int token; std::vector< std::string > args; + std::vector< int > pos; bool has_arg; bool is_set; int cnt; // number of times this option was encounterd in command line + bool operator==( const std::string& _longname ) const { return longname == _longname; } + bool operator==( char _shortname ) const { return shortname == _shortname; } + bool operator==( int _token ) const { return token == _token; } }; class Opts @@ -37,48 +45,47 @@ Opts( const std::string& _brief = "", const std::string& _author = "", const std::string& _copyright = "") : brief(_brief), author(_author), - copyright(_copyright) - { } + copyright(_copyright) + { free_token = 0; } - // adding option / flag + // adding option / flag (option that doesn't need arguments) template <class T> - void add( char _shortname,T _default_value,const std::string& _longname = "", const std::string& _desc = "" ); - void addflag( char _shortname,const std::string& _longname = "",const std::string& _desc = "" ); + int add( const std::string& _longname,T _default_value,const std::string& _desc = OPT_DEFAULT_DESCRIPTION ); - // getting option template <class T> - T get( char _shortname ); + int add( char _shortname,T _default_value,const std::string& _longname = OPT_DEFAULT_LONGNAME, const std::string& _desc = OPT_DEFAULT_DESCRIPTION ); - template <class T> - T get( const std::string& _longname ); + int addflag( const std::string& _longname,const std::string& desc = OPT_DEFAULT_DESCRIPTION); - template <class T> - T get_default( char _shorname ); + int addflag( char _shortname,const std::string& _longname = OPT_DEFAULT_LONGNAME,const std::string& _desc = OPT_DEFAULT_DESCRIPTION ); + + // getting option + + template < class T ,class V > + T get( V field ); - template <class T> - T get_default( const std::string& _longname ); + template <class T , class V> + T get_default( V field ); - template <class BackInsertIterator> - void getemall(char _shortname,BackInsertIterator bi); + template < class V , class BackInsertIterator> + void getemall( V field , BackInsertIterator bi); - template <class BackInsertIterator> - void getemall(const std::string& _longname,BackInsertIterator bi); - bool is_set( char _shortname ); - bool is_set( const std::string& _longname ); + template < class T > + bool is_set( T field ) const; - int get_cnt( char _shortname ) const; - int get_cnt( const std::string& _longname ) const; + template < class T > + int get_cnt( T field ) const; + template < class V , class BackInsertIterator > + void get_pos( V field , BackInsertIterator bi); + // parse void parse(int& ac, const char** av); // stuff void help(std::ostream& out); std::string get_pname() const; - std::string get_brief() const; - std::string get_author() const; - std::string get_copyright() const; // error handling struct unknown_option : @@ -97,22 +104,15 @@ { } }; - struct invalid_arg : + struct arg_typemismatch : public std::invalid_argument { - invalid_arg( const std::string& _optname, const std::string& _argname) : - std::invalid_argument(std::string("invalid argument [").append(_argname).append("] for option ").append(_optname)) + arg_typemismatch( const std::string& _optname, const std::string& _argname) : + std::invalid_argument(std::string("argument [").append(_argname).append("] doesn't match by type for option ").append(_optname)) { } }; - struct bad_usage : - public std::invalid_argument - { - bad_usage( const std::string& descr ) : - std::invalid_argument( descr ) - { } - }; - + int free_token; private: std::string pname; std::string brief; @@ -127,55 +127,97 @@ }; template <class T> -void Opts::add(char _shortname,T _default_value,const std::string& _longname,const std::string& _desc) +int Opts::add(char _shortname,T _default_value,const std::string& _longname,const std::string& _desc) { addflag(_shortname,_longname,_desc); std::stringstream ss; ss << _default_value; storage[storage.size() - 1].default_v = ss.str(); storage[storage.size() - 1].has_arg = true; + return storage[storage.size() - 1].token; } template <class T> -T Opts::get( char _shortname ) +int Opts::add(const std::string& _longname,T _default_value,const std::string& _desc) { + addflag(_longname,_desc); + std::stringstream ss; + ss << _default_value; + storage[storage.size() - 1].default_v = ss.str(); + storage[storage.size() - 1].has_arg = true; + return storage[storage.size() - 1].token; +} + +template <class T> +bool Opts::is_set(T field) const +{ options_container_type::const_iterator i; + for (i = storage.begin();i != storage.end();++i) + if (*i == field) + return i->is_set; + return false; +} + +template <class T> +int Opts::get_cnt(T field) const +{ + options_container_type::const_iterator i; + for (i = storage.begin();i != storage.end();++i) + if (*i == field) + return i->cnt; + return 0; +} + +template < class T , class V > +T Opts::get( V field ) +{ + options_container_type::const_iterator i; T res; - for ( i = storage.begin(); i != storage.end(); ++i ) { - if ( i->shortname == _shortname ) { - if ( !i->has_arg ) { - throw bad_usage("using Opts::get for option without arguments"); + for ( i = storage.begin(); i != storage.end(); ++i ) + { + if ( *i == field ) + { + if ( !i->has_arg ) + { + throw std::logic_error("using Opts::get for option without arguments"); } std::stringstream ss; ss << (i->args.empty() ? i->default_v : i->args[0]); ss >> res; - if (ss.fail()) { - throw invalid_arg(std::string("-") + std::string(1,_shortname), i->args[0]); + if (ss.fail()) + { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->args[0]); } break; } } - if ( i == storage.end() ) { - throw unknown_option( std::string("-") + _shortname ); + if ( i == storage.end() ) + { + std::stringstream ss1; + ss1 << field; + throw unknown_option( ss1.str() ); } return res; } -template <class T> -T Opts::get_default( char _shortname ) + +template <class T , class V> +T Opts::get_default( V field ) { options_container_type::const_iterator i; T res; for (i = storage.begin();i != storage.end();++i) - if (i->shortname == _shortname) + if (*i == field) { if (!i->has_arg) - throw bad_usage("using Opts::get for option without arguments"); + throw std::logic_error("using Opts::get for option without arguments"); std::stringstream ss; ss << i->default_v; @@ -183,137 +225,84 @@ ss >> res; if (ss.fail()) - throw invalid_arg(std::string("-") + std::string(1,_shortname),i->default_v); + { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->default_v); + } break; } if (i == storage.end()) - throw unknown_option(std::string("-") + std::string(1,_shortname)); + { + std::stringstream ss1; + ss1 << field; + throw unknown_option( ss1.str() ); + } return res; } -template <class T> -T Opts::get( const std::string& _longname ) +template <class V , class BackInsertIterator> +void Opts::getemall( V field , BackInsertIterator bi) { options_container_type::const_iterator i; - T res; for (i = storage.begin();i != storage.end();++i) - if (i->longname == _longname) + if (*i == field) { if (!i->has_arg) - throw bad_usage("using Opts::get for option without arguments"); + throw std::logic_error("using Opts::getemall for option without arguments"); - std::stringstream ss; - ss << (i->args.empty() ? i->default_v : i->args[0]); - - ss >> res; - - if (ss.fail()) // need to recover stream? - throw invalid_arg(std::string("--") + _longname,i->args[0]); - - break; - } - - if (i == storage.end()) - throw unknown_option(std::string("--") + _longname); - return res; -} - -template <class T> -T Opts::get_default( const std::string& _longname ) -{ - options_container_type::const_iterator i; - T res; - for (i = storage.begin();i != storage.end();++i) - if (i->longname == _longname) - { - if (!i->has_arg) - throw bad_usage("using Opts::get for option without arguments"); - - std::stringstream ss(i->default_v); - - ss >> res; - - if (ss.fail()) // need to recover stream? - throw invalid_arg(std::string("--") + _longname,i->default_v); - - break; - } - - if (i == storage.end()) - throw unknown_option(std::string("--") + _longname); - return res; -} - -template <class BackInsertIterator> -void Opts::getemall( char _shortname , BackInsertIterator bi) -{ - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (i->shortname == _shortname) - { - if (!i->has_arg) - throw bad_usage("using Opts::getemall for option without arguments"); - if (!i->args.empty()) for (int j = 0;j < i->args.size();j++) { std::stringstream ss(i->args[j]); - try - { - ss >> *bi++; - } - catch(...) - { - throw invalid_arg(std::string("-") + std::string(1,_shortname),i->args[j]); - } + ss >> *bi++; if (ss.fail()) - throw invalid_arg(std::string("-") + std::string(1,_shortname),i->args[j]); + { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->args[j]); + } } break; } if (i == storage.end()) - throw unknown_option(std::string("-") + std::string(1,_shortname)); + { + std::stringstream ss1; + ss1 << field; + throw unknown_option(ss1.str()); + } } -template <class BackInsertIterator> -void Opts::getemall( const std::string& _longname , BackInsertIterator bi) +template <class V , class BackInsertIterator> +void Opts::get_pos( V field , BackInsertIterator bi) { options_container_type::const_iterator i; for (i = storage.begin();i != storage.end();++i) - if (i->longname == _longname) + if (*i == field) { - if (!i->has_arg) - throw bad_usage("using Opts::getemall for option without arguments"); - - if (!i->args.empty()) - for (int j = 0;j < i->args.size();j++) + if (i->is_set) + for (int j = 0;j < i->pos.size();j++) { - - std::stringstream ss(i->args[j]); - try - { - ss >> *bi++; - } - catch(...) - { - throw invalid_arg(std::string("--") + _longname,i->args[j]); - } - - if (ss.fail()) - throw invalid_arg(std::string("-") + _longname,i->args[j]); + *bi++ = i->pos[j]; } break; } if (i == storage.end()) - throw unknown_option(std::string("-") + _longname); + { + std::stringstream ss1; + ss1 << field; + throw unknown_option(ss1.str()); + } } + + #endif Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-05-23 10:41:10 UTC (rev 1880) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-05-24 10:09:48 UTC (rev 1881) @@ -9,9 +9,6 @@ using namespace std; string Opts::get_pname() const { return pname; } -string Opts::get_brief() const { return brief; } -string Opts::get_author() const { return author; } -string Opts::get_copyright() const { return copyright; } bool Opts::isterm(const string& s) { @@ -95,13 +92,15 @@ out << "usage: " << endl; out << pname << " [option ...] [optiongoup ...] [end operands ...]" << endl; - out << "available options:" << endl; + out << "available options:" << endl << "shortname:" << '\t' << "longname:" << '\t' << "default value" << '\t' << "description" << endl; options_container_type::const_iterator i; for (i = storage.begin();i != storage.end();++i) - out << "-" << i->shortname << "\t[--" << i->longname << "] [" << i->default_v << "]\t-\t" << i->desc << endl; + { + out << i->shortname << "\t[--" << i->longname << "] [" << i->default_v << "]\t-\t" << i->desc << endl; + } } -void Opts::addflag(char _shortname,const string& _longname,const string& _desc) +int Opts::addflag(char _shortname,const string& _longname,const string& _desc) { Opt opt; opt.shortname = _shortname; @@ -109,52 +108,30 @@ opt.desc = _desc; opt.has_arg = false; opt.is_set = false; + opt.token = ++free_token; storage.push_back(opt); + return opt.token; } - -bool Opts::is_set(char _shortname) +int Opts::addflag(const string& _longname,const string& _desc) { - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (i->shortname == _shortname) - return i->is_set; - return false; + Opt opt; + opt.longname = _longname; + opt.desc = _desc; + opt.has_arg = false; + opt.is_set = false; + opt.token = ++free_token; + storage.push_back(opt); + return opt.token; } -bool Opts::is_set(const string& _longname) -{ - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (i->longname == _longname) - return i->is_set; - return false; -} - -int Opts::get_cnt(char _shortname) const -{ - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (i->shortname == _shortname) - return i->cnt; - return 0; -} - -int Opts::get_cnt(const string& _longname) const -{ - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (i->longname == _longname) - return i->cnt; - return 0; -} - void Opts::parse(int& ac,const char** av) { pname = av[0]; int i = 1; int j = 1; + int q = 0; while (i < ac && !isterm(av[i])) { if (is_opt_name(av[i])) @@ -171,11 +148,12 @@ } options_container_type::iterator p = get_opt_index(opt); - + if (p == storage.end()) throw unknown_option(opt); else { + p->pos.push_back(++q); p->is_set = true; p->cnt++; if (p->has_arg) @@ -189,8 +167,8 @@ throw missing_arg(opt); } else - if (!arg.empty()) //unexpected arg - throw invalid_arg(opt,arg); + if (!arg.empty()) //unexpected arg (not exactly mismatch) + throw arg_typemismatch(opt,arg); } } else @@ -201,11 +179,14 @@ { options_container_type::iterator p = get_opt_index(string("-") + optgroup[j]); if (p == storage.end()) + { throw unknown_option( "-" + string(1,optgroup[j]) ); + } else { p->is_set = true; p->cnt++; + p->pos.push_back(++q); if (p->has_arg) throw missing_arg( "-" + string(1,optgroup[j]) ); } Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-23 10:41:10 UTC (rev 1880) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-24 10:09:48 UTC (rev 1881) @@ -65,14 +65,17 @@ opts_test opts; - t.add( &opts_test::bool_option_long, opts, "simple boolean option, long", + t.add( &opts_test::bool_option_long, opts, "simple boolean option, long" , t.add( &opts_test::bool_option, opts, "simple boolean option" ) ); - + t.add( &opts_test::int_option_long, opts, "option with int parameter, long", t.add( &opts_test::int_option, opts, "option with int parameter" ) ); + t.add( &opts_test::add_check_flag , opts , "add_check_flag"); + t.add( &opts_test::add_get_opt , opts , "add_get_opts"); + t.add( &opts_test::option_position,opts,"option position"); + t.add( &opts_test::defaults, opts, "defaults" ); - t.add( &opts_test::bad_option, opts, "bad option" ); t.add( &opts_test::bad_argument, opts, "bad argument" ); @@ -98,5 +101,7 @@ t.add( &opts_test::multiple_args, opts,"multiple_args"); + t.add( &opts_test::help, opts, "help"); + return t.girdle(); } Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-23 10:41:10 UTC (rev 1880) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-24 10:09:48 UTC (rev 1881) @@ -13,11 +13,14 @@ #include <misc/opts.h> #include <set> #include <vector> +#include <list> +#include <fstream> // #include <iostream> using namespace std; + int EXAM_IMPL(opts_test::bool_option) { const char* argv[] = { "name", "-h" }; @@ -34,7 +37,7 @@ } catch ( const Opts::unknown_option& e ) { } - catch ( const Opts::invalid_arg& e ) { + catch ( const Opts::arg_typemismatch& e ) { } return EXAM_RESULT; @@ -56,7 +59,7 @@ } catch ( const Opts::unknown_option& e ) { } - catch ( const Opts::invalid_arg& e ) { + catch ( const Opts::arg_typemismatch& e ) { } return EXAM_RESULT; @@ -80,7 +83,7 @@ } catch ( const Opts::unknown_option& e ) { } - catch ( const Opts::invalid_arg& e ) { + catch ( const Opts::arg_typemismatch& e ) { } return EXAM_RESULT; @@ -104,12 +107,183 @@ } catch ( const Opts::unknown_option& e ) { } - catch ( const Opts::invalid_arg& e ) { + catch ( const Opts::arg_typemismatch& e ) { } return EXAM_RESULT; } +int EXAM_IMPL(opts_test::add_check_flag) +{ + const char* argv[] = { "name", "-ht" , "--temp"}; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + int f_token = opts.addflag('f'); + opts.addflag('t',"tag"); + int foo_token = opts.addflag("foo"); + opts.addflag("temp","temp desc"); + int h_token = opts.addflag( 'h', "help", "print this help message" ); + bool exception_happens = false; + + try { + opts.parse( argc, argv ); + + EXAM_CHECK( opts.is_set( 'h' ) ); + } + catch ( const Opts::unknown_option& e ) { + } + catch ( const Opts::arg_typemismatch& e ) { + } + + EXAM_CHECK( !opts.is_set("foo") ); + EXAM_CHECK( !opts.is_set(foo_token) ); + EXAM_CHECK( opts.is_set('h') ); + EXAM_CHECK( opts.is_set(h_token) ); + EXAM_CHECK( opts.is_set("help")); + EXAM_CHECK( opts.is_set('t')); + EXAM_CHECK( opts.is_set("temp") ); + EXAM_CHECK( !opts.is_set("unknow option") ); + EXAM_CHECK( !opts.is_set(42) ); + + try + { + opts.get<int>('f'); + } + catch(const logic_error& e) + { + exception_happens = true; + } + + EXAM_CHECK( exception_happens ); + + exception_happens = false; + try + { + opts.get_default<int>("tag"); + } + catch(const logic_error& e) + { + exception_happens = true; + } + + EXAM_CHECK( exception_happens ); + + exception_happens = false; + + try + { + vector< string > vs; + opts.getemall(h_token,vs.begin()); + } + catch( const logic_error& e) + { + exception_happens = true; + } + + EXAM_CHECK( exception_happens ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::add_get_opt) +{ + const char* argv[] = { "name", "-t" , "20" , "--name=torwalds" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + int t_token = opts.add('t',10); + int name_token = opts.add("name","linus"); + int port_token = opts.add('p',80,"port"); + int num_token = opts.add("num",100,"number of elements"); + + + try { + opts.parse( argc, argv ); + } + catch ( const Opts::unknown_option& e ) { + } + catch ( const Opts::arg_typemismatch& e ) { + } + + EXAM_CHECK( opts.is_set('t') ); + EXAM_CHECK( opts.get_cnt(t_token) == 1 ); + EXAM_CHECK( opts.get<int>('t') == 20); + EXAM_CHECK( opts.get_default<int>(t_token) == 10 ); + EXAM_CHECK( opts.is_set(name_token) ); + EXAM_CHECK( opts.get_cnt("name") == 1 ); + EXAM_CHECK( opts.get<string>(name_token) == "torwalds"); + EXAM_CHECK( opts.get_default<string>("name") == "linus"); + EXAM_CHECK( !opts.is_set('p') ); + EXAM_CHECK( !opts.is_set("num") && opts.get<int>(num_token) == opts.get_default<int>("num") ) ; + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::option_position) +{ + const char* argv[] = { "name" , "--begin" , "--f1","--f2","--end","--f1","--port=10"}; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'p', 0, "port", "listen tcp port"); + opts.addflag("begin"); + int f1_token = opts.addflag("f1"); + int f2_token = opts.addflag("f2"); + opts.addflag("end"); + + try { + opts.parse( argc, argv ); + + EXAM_CHECK(opts.get_cnt('p') == 1); + EXAM_CHECK(opts.get_cnt("begin") == 1); + EXAM_CHECK(opts.get_cnt(f1_token) == 2); + EXAM_CHECK(opts.get_cnt(f2_token) == 1); + EXAM_CHECK(opts.get_cnt("end") == 1); + EXAM_CHECK(opts.get_cnt("unknown") == 0); + EXAM_CHECK(opts.get_cnt('u') == 0); + EXAM_CHECK(opts.get_cnt(42) == 0); + + list<int> p_l(opts.get_cnt('p')); + vector<int> b_v(opts.get_cnt("begin")); + vector<int> f1_v(opts.get_cnt(f1_token)); + vector<int> f2_v(opts.get_cnt(f2_token)); + vector<int> e_v(opts.get_cnt("end")); + list<int> u_l(opts.get_cnt("unknown")); + bool exception_happens = false; + + opts.get_pos('p',p_l.begin()); + opts.get_pos("begin",b_v.begin()); + opts.get_pos("f1",f1_v.begin()); + opts.get_pos(f2_token,f2_v.begin()); + opts.get_pos("end",e_v.begin()); + + try + { + opts.get_pos("unknown",u_l.begin()); + } + catch(const Opts::unknown_option& e) + { + exception_happens = true; + } + + EXAM_CHECK( exception_happens ); + EXAM_CHECK( !b_v.empty() && !e_v.empty() && e_v[0] > b_v[0]); + EXAM_CHECK( f1_v.size() == 2 && f1_v[0] == 2 && f1_v[1] == 5); + EXAM_CHECK( !p_l.empty() && *p_l.begin() == 6); + EXAM_CHECK( u_l.empty() ); + } + catch ( const Opts::unknown_option& e ) { + } + catch ( const Opts::arg_typemismatch& e ) { + } + + return EXAM_RESULT; +} + int EXAM_IMPL(opts_test::defaults) { const char* argv[] = { "name" }; @@ -128,7 +302,7 @@ } catch ( const Opts::unknown_option& e ) { } - catch ( const Opts::invalid_arg& e ) { + catch ( const Opts::arg_typemismatch& e ) { } return EXAM_RESULT; @@ -153,7 +327,7 @@ catch ( const Opts::unknown_option& e ) { exception_happens = true; } - catch ( const Opts::invalid_arg& e ) { + catch ( const Opts::arg_typemismatch& e ) { } EXAM_CHECK( exception_happens ); @@ -178,7 +352,7 @@ { int t = opts.get<int>('p'); } - catch(const Opts::invalid_arg& e) + catch(const Opts::arg_typemismatch& e) { exception_happens = true; } @@ -204,7 +378,7 @@ { opts.parse( argc, argv ); } - catch(const Opts::invalid_arg& e) + catch(const Opts::arg_typemismatch& e) { exception_happens = true; } @@ -485,7 +659,7 @@ opts.add('t',string("standart"),"proc_type","process type"); bool exception_happens = false; - + try { opts.parse( argc, argv ); @@ -526,3 +700,33 @@ return EXAM_RESULT; } + +int EXAM_IMPL(opts_test::help) +{ + { + const char* argv[] = { "name" , "--help" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts("what utility do","author","copyright"); + + + opts.addflag('h',"help","print this help message"); + opts.addflag('v',"verbose"); + opts.addflag("flag","some program flag"); + opts.add('I',"/usr/include","include","include paths" ); + opts.add('p',80,"port","listen to tcp port"); + opts.add('t',"standart");; + + opts.parse(argc,argv); + + EXAM_CHECK(opts.is_set('h')); + EXAM_CHECK( opts.get_pname() == "name" ); + + ofstream out("help.out"); + opts.help(out); + cout << "check file help.out" << endl; + out.close(); + } + + return EXAM_RESULT; +} Modified: trunk/complement/explore/lib/misc/ut/opts_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-23 10:41:10 UTC (rev 1880) +++ trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-24 10:09:48 UTC (rev 1881) @@ -23,6 +23,9 @@ int EXAM_DECL(bool_option_long); int EXAM_DECL(int_option); int EXAM_DECL(int_option_long); + int EXAM_DECL(add_check_flag); + int EXAM_DECL(add_get_opt); + int EXAM_DECL(option_position); int EXAM_DECL(defaults); int EXAM_DECL(bad_option); int EXAM_DECL(bad_argument); @@ -37,6 +40,7 @@ int EXAM_DECL(autocomplement); int EXAM_DECL(autocomplement_failure); int EXAM_DECL(multiple_args); + int EXAM_DECL(help); }; #endif // __MISC_TEST_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |