Author: wyoung
Date: Tue Mar 3 13:34:54 2009
New Revision: 2472
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2472&view=rev
Log:
Moved "successful" flag and truth operator stuff up into
CommandLineBase, and renamed collect_unparsed_arguments() method to
finish_parse(), as it now sets this flag after doing what its previous
name implied. Now simply "finishing the parse" in the subclass ctor
implictly marks the object as successful, as they're really part of the
same thing.
Modified:
trunk/lib/cmdline.cpp
trunk/lib/cmdline.h
Modified: trunk/lib/cmdline.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/cmdline.cpp?rev=2472&r1=2471&r2=2472&view=diff
==============================================================================
--- trunk/lib/cmdline.cpp (original)
+++ trunk/lib/cmdline.cpp Tue Mar 3 13:34:54 2009
@@ -122,10 +122,10 @@
namespace mysqlpp {
-//// CommandLineBase::collect_unparsed_arguments ///////////////////////
+//// CommandLineBase::finish_parse /////////////////////////////////////
void
-CommandLineBase::collect_unparsed_arguments()
+CommandLineBase::finish_parse()
{
const int nextras = argc_ - option_index();
if (nextras > 0) {
@@ -134,6 +134,8 @@
extra_args_[i] = argv_[option_index() + i];
}
}
+
+ successful_ = true;
}
@@ -183,7 +185,6 @@
CommandLine::CommandLine(int argc, char* const argv[],
const char* user, const char* pass, const char* usage_extra) :
CommandLineBase(argc, argv, "m:p:s:u:D"),
-successful_(false),
dtest_mode_(false),
run_mode_(0),
server_(0),
@@ -204,9 +205,7 @@
}
}
- collect_unparsed_arguments();
-
- successful_ = true;
+ finish_parse();
}
Modified: trunk/lib/cmdline.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/cmdline.h?rev=2472&r1=2471&r2=2472&view=diff
==============================================================================
--- trunk/lib/cmdline.h (original)
+++ trunk/lib/cmdline.h Tue Mar 3 13:34:54 2009
@@ -53,21 +53,29 @@
const ArgumentList& extra_args() const
{ return extra_args_; }
+ // Return truthy value if command line was parsed successfully
+ operator void*() const
+ {
+ return successful_ ? const_cast<bool*>(&successful_) :
0;
+ }
+
protected:
//// Subclass interface
// Hidden ctor and dtor to prevent instantiation
CommandLineBase(int argc, char* const argv[], const char* opts)
:
argc_(argc),
argv_(argv),
- opts_(opts)
+ opts_(opts),
+ successful_(false)
{
assert(argc > 0 && argv && opts);
}
virtual ~CommandLineBase() { }
- // Save non-option arguments to extra_args_ list. Subclass
- // ctor should call this after parse_next() loop gets EOF.
- void collect_unparsed_arguments();
+ // Save non-option arguments to extra_args_ list, and mark the
+ // object as "successful". Subclass ctor should call this after
+ // parse_next() loop gets EOF.
+ void finish_parse();
// Wrapper for getopt()
int parse_next() const;
@@ -85,6 +93,7 @@
int argc_;
char* const* argv_;
const char* opts_;
+ bool successful_;
ArgumentList extra_args_;
};
@@ -103,12 +112,6 @@
const char* user = 0, const char* pass
= 0,
const char* usage_extra = 0);
- // Return truthy value if command line was parsed
successfully
- operator void*() const
- {
- return successful_ ?
const_cast<bool*>(&successful_) : 0;
- }
-
// Show a mesage explaining the program's proper usage
void print_usage(const char* extra) const;
@@ -121,7 +124,6 @@
private:
//// Internal data
- bool successful_;
bool dtest_mode_;
int run_mode_;
const char* server_;
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits