Author: wyoung
Date: Tue Mar 3 13:28:25 2009
New Revision: 2471
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2471&view=rev
Log:
Have now completely hidden getopt() interface behind CommandLineBase
interface. This makes it possible to derive from it from anothe module,
not even necessarily inside the library, without having to care about
where we get command line parsing services.
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=2471&r1=2470&r2=2471&view=diff
==============================================================================
--- trunk/lib/cmdline.cpp (original)
+++ trunk/lib/cmdline.cpp Tue Mar 3 13:28:25 2009
@@ -127,13 +127,35 @@
void
CommandLineBase::collect_unparsed_arguments()
{
- const int nextras = argc_ - optind;
+ const int nextras = argc_ - option_index();
if (nextras > 0) {
extra_args_.resize(nextras);
for (int i = 0; i < nextras; ++i) {
- extra_args_[i] = argv_[optind + i];
+ extra_args_[i] = argv_[option_index() + i];
}
}
+}
+
+
+//// CommandLineBase::option_argument //////////////////////////////////
+// Accessor for optarg, so caller doesn't have to know about this
+// getopt() style interface. Particualy helpful on non-POSIX systems.
+
+const char*
+CommandLineBase::option_argument() const
+{
+ return optarg;
+}
+
+
+//// CommandLineBase::option_index /////////////////////////////////////
+// Accessor for optind, so caller doesn't have to know about this
+// getopt() style interface. Particualy helpful on non-POSIX systems.
+
+int
+CommandLineBase::option_index() const
+{
+ return optind;
}
@@ -171,11 +193,11 @@
int ch;
while ((ch = parse_next()) != EOF) {
switch (ch) {
- case 'm': run_mode_ = atoi(optarg); break;
- case 'p': pass_ = optarg; break;
- case 's': server_ = optarg; break;
- case 'u': user_ = optarg; break;
- case 'D': dtest_mode_ = true; break;
+ case 'm': run_mode_ = atoi(option_argument()); break;
+ case 'p': pass_ = option_argument(); break;
+ case 's': server_ = option_argument(); break;
+ case 'u': user_ = option_argument(); break;
+ case 'D': dtest_mode_ = true; break;
default:
print_usage(usage_extra);
return;
Modified: trunk/lib/cmdline.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/cmdline.h?rev=2471&r1=2470&r2=2471&view=diff
==============================================================================
--- trunk/lib/cmdline.h (original)
+++ trunk/lib/cmdline.h Tue Mar 3 13:28:25 2009
@@ -72,6 +72,11 @@
// Wrapper for getopt()
int parse_next() const;
+ // Accessors for getopt() globals, so subclasses can ignore
+ // getopt()'s interface entirely.
+ const char* option_argument() const;
+ int option_index() const;
+
// Get the program's executable name
const char* program_name() const { return argv_[0]; }
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits