From 7e11b20594ae05177fe36701422a0faf6120c0b0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 2 May 2013 12:58:36 +0300 Subject: [PATCH] Use a typedef for the option descriptor list --- source/core/getopt.cpp | 16 ++++++++-------- source/core/getopt.h | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index ad72644..2bbfebc 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -13,13 +13,13 @@ GetOpt::GetOpt(): GetOpt::~GetOpt() { - for(list::iterator i=opts.begin(); i!=opts.end(); ++i) + for(OptionList::iterator i=opts.begin(); i!=opts.end(); ++i) delete *i; } GetOpt::OptBase &GetOpt::add_option(OptBase *opt) { - for(list::iterator i=opts.begin(); i!=opts.end(); ) + for(OptionList::iterator i=opts.begin(); i!=opts.end(); ) { if((opt->get_short()!=0 && (*i)->get_short()==opt->get_short()) || (*i)->get_long()==opt->get_long()) { @@ -36,7 +36,7 @@ GetOpt::OptBase &GetOpt::add_option(OptBase *opt) GetOpt::OptBase &GetOpt::get_option(char s) { - for(list::iterator i=opts.begin(); i!=opts.end(); ++i) + for(OptionList::iterator i=opts.begin(); i!=opts.end(); ++i) if((*i)->get_short()==s) return **i; throw usage_error(string("Unknown option -")+s); @@ -44,7 +44,7 @@ GetOpt::OptBase &GetOpt::get_option(char s) GetOpt::OptBase &GetOpt::get_option(const string &l) { - for(list::iterator i=opts.begin(); i!=opts.end(); ++i) + for(OptionList::iterator i=opts.begin(); i!=opts.end(); ++i) if((*i)->get_long()==l) return **i; throw usage_error(string("Unknown option --")+l); @@ -149,7 +149,7 @@ unsigned GetOpt::process_short(const char *const *argp) string GetOpt::generate_usage(const string &argv0) const { string result = argv0; - for(list::const_iterator i=opts.begin(); i!=opts.end(); ++i) + for(OptionList::const_iterator i=opts.begin(); i!=opts.end(); ++i) { result += " ["; if((*i)->get_short()) @@ -180,12 +180,12 @@ string GetOpt::generate_usage(const string &argv0) const string GetOpt::generate_help() const { bool any_short = false; - for(list::const_iterator i=opts.begin(); (!any_short && i!=opts.end()); ++i) + for(OptionList::const_iterator i=opts.begin(); (!any_short && i!=opts.end()); ++i) any_short = (*i)->get_short(); string::size_type maxw = 0; list switches; - for(list::const_iterator i=opts.begin(); i!=opts.end(); ++i) + for(OptionList::const_iterator i=opts.begin(); i!=opts.end(); ++i) { string swtch; if((*i)->get_short()) @@ -215,7 +215,7 @@ string GetOpt::generate_help() const string result; list::const_iterator j = switches.begin(); - for(list::const_iterator i=opts.begin(); i!=opts.end(); ++i, ++j) + for(OptionList::const_iterator i=opts.begin(); i!=opts.end(); ++i, ++j) result += format(" %s%s%s\n", *j, string(maxw+2-j->size(), ' '), (*i)->get_help()); return result; diff --git a/source/core/getopt.h b/source/core/getopt.h index 53c9ddf..4f53cc2 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -141,8 +141,10 @@ private: { data.push_back(lexical_cast(a)); } }; + typedef std::list OptionList; + bool help; - std::list opts; + OptionList opts; std::vector args; public: -- 2.45.2