- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

cmdline.h
1 /***********************************************************************
2 cmdline.h - Declares the interface to the MySQL++'s command line
3 parsing logic, used by the examples and the utility programs.
4 Not intended for use by third parties! If it breaks, you
5 get to keep all the pieces.
6
7 Copyright (c) 2007-2009 by Educational Technology Resources, Inc.
8 Others may also hold copyrights on code in this file. See the
9 CREDITS.txt file in the top directory of the distribution for details.
10
11 This file is part of MySQL++.
12
13 MySQL++ is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Lesser General Public License as published
15 by the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
17
18 MySQL++ is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21 License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with MySQL++; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
26 USA
27 ***********************************************************************/
28
29 #if !defined(MYSQLPP_CMDLINE_H)
30 #define MYSQLPP_CMDLINE_H
31
32 #include "common.h"
33
34 #include <string>
35 #include <vector>
36
37 #include <assert.h>
38
39 namespace mysqlpp {
44 class MYSQLPP_EXPORT CommandLineBase
45 {
46 public:
49 typedef std::vector<std::string> ArgumentList;
51 typedef ArgumentList::const_iterator ArgumentListIt;
52
56 const ArgumentList& extra_args() const
57 { return extra_args_; }
58
61 operator void*() const
62 {
63 return successful_ ? const_cast<bool*>(&successful_) : 0;
64 }
65
66 protected:
69 CommandLineBase(int argc, char* const argv[], const char* opts) :
70 argc_(argc),
71 argv_(argv),
72 opts_(opts),
73 successful_(argc > 0 && argv && opts)
74 {
75 assert(successful_);
76 }
78 virtual ~CommandLineBase() { }
79
83 void finish_parse();
84
86 const char* option_argument() const;
88 int option_index() const;
89
95 void parse_error(const char* message = 0);
96
98 int parse_next() const;
99
101 virtual void print_usage() const = 0;
102
104 const char* program_name() const { return argv_[0]; }
105
108 bool successful() const { return successful_; }
109
110 private:
112 int argc_;
113 char* const* argv_;
114 const char* opts_;
115 bool successful_;
116 ArgumentList extra_args_;
117 };
118
119
121 namespace examples {
123 extern MYSQLPP_EXPORT const char* db_name;
124
126 class MYSQLPP_EXPORT CommandLine : public CommandLineBase
127 {
128 public:
131 CommandLine(int argc, char* const argv[],
132 const char* user = 0, const char* pass = 0,
133 const char* usage_extra = 0);
134
139 void print_usage() const { print_usage(usage_extra_); }
140
144 void print_usage(const char* extra) const;
145
150 bool dtest_mode() const { return dtest_mode_; }
151
153 const char* pass() const { return pass_; }
154
160 int run_mode() const { return run_mode_; }
161
163 const char* server() const { return server_; }
164
166 const char* user() const { return user_; }
167
168 private:
170 // Examples-specific command line parse results
171 bool dtest_mode_;
172 int run_mode_;
173 const char* server_;
174 const char* user_;
175 const char* pass_;
176 const char* usage_extra_;
177 };
178 } // end namespace mysqlpp::examples
179
180
182 namespace ssqlsxlat {
184 class MYSQLPP_EXPORT CommandLine : public CommandLineBase
185 {
186 public:
189 enum SourceSink {
190 ss_unknown,
191 ss_ssqls1,
192 ss_ssqls2,
193 ss_table
194 };
195
198 CommandLine(int argc, char* const argv[]);
199
201 void print_usage() const;
202
207 const char* input() const { return input_; }
208
210 SourceSink input_source() const { return input_source_; }
211
213 SourceSink output_sink() const { return output_sink_; }
214
216 const char* output() const { return output_; }
217
219 const char* pass() const { return pass_; }
220
222 const char* server() const { return server_; }
223
225 const char* user() const { return user_; }
226
227 private:
229 const char* input_;
230 const char* output_;
231 const char* pass_;
232 const char* server_;
233 const char* user_;
234 SourceSink input_source_;
235 SourceSink output_sink_;
236 };
237 } // end namespace mysqlpp::ssqlsxlat
238 } // end namespace mysqlpp
239
240 #endif // !defined(MYSQLPP_CMDLINE_H)
241
mysqlpp::ssqlsxlat::CommandLine::user
const char * user() const
DB user name, when input type is is_table.
Definition: cmdline.h:225
mysqlpp::ssqlsxlat::CommandLine::ss_unknown
no known input type given yet
Definition: cmdline.h:190
mysqlpp::examples::CommandLine::run_mode
int run_mode() const
Return the -m flag value.
Definition: cmdline.h:160
mysqlpp::CommandLineBase::ArgumentListIt
ArgumentList::const_iterator ArgumentListIt
Iterator into ArgumentList.
Definition: cmdline.h:51
mysqlpp::CommandLineBase::program_name
const char * program_name() const
Get the file name of the program&#39;s executable.
Definition: cmdline.h:104
mysqlpp::ssqlsxlat::CommandLine::SourceSink
SourceSink
Types of inputs that ssqlsxlat will accept.
Definition: cmdline.h:189
mysqlpp::CommandLineBase
Parses command line arguments and holds the results.
Definition: cmdline.h:44
mysqlpp::examples::CommandLine::dtest_mode
bool dtest_mode() const
Return true if we&#39;re in &quot;dtest&quot; mode This happens when an example gets the -D flag, always passed by the dtest script to ask the programs it runs to suppress any nondeterministic output.
Definition: cmdline.h:150
mysqlpp::examples::CommandLine::user
const char * user() const
Return the DB user name (-u argument)
Definition: cmdline.h:166
mysqlpp::CommandLineBase::extra_args
const ArgumentList & extra_args() const
Get reference to list of command line arguments past the last flag and its possible argument...
Definition: cmdline.h:56
mysqlpp::ssqlsxlat::CommandLine::ss_ssqls2
an SSQLS v2 file
Definition: cmdline.h:192
mysqlpp::examples::CommandLine
Command line parsing mechanism for ../examples/*.cpp.
Definition: cmdline.h:126
mysqlpp::CommandLineBase::successful
bool successful() const
Returns true if nothing has gone wrong since calling the ctor.
Definition: cmdline.h:108
mysqlpp::examples::db_name
const char * db_name
Name of examples&#39; DB.
Definition: cmdline.cpp:199
mysqlpp::ssqlsxlat::CommandLine::pass
const char * pass() const
DB password, when input type is is_table.
Definition: cmdline.h:219
mysqlpp::ssqlsxlat::CommandLine
Command line parser for MySQL++&#39;s ssqlsxlat tool.
Definition: cmdline.h:184
mysqlpp::ssqlsxlat::CommandLine::output_sink
SourceSink output_sink() const
The output sink (destination) type.
Definition: cmdline.h:213
mysqlpp::CommandLineBase::ArgumentList
std::vector< std::string > ArgumentList
Type for a list of arguments.
Definition: cmdline.h:49
mysqlpp::CommandLineBase::~CommandLineBase
virtual ~CommandLineBase()
Hidden dtor to prevent instantiation.
Definition: cmdline.h:78
mysqlpp::ssqlsxlat::CommandLine::server
const char * server() const
DB server name, when input type is is_table.
Definition: cmdline.h:222
mysqlpp::ssqlsxlat::CommandLine::input
const char * input() const
Return the name of the input source.
Definition: cmdline.h:207
mysqlpp::CommandLineBase::CommandLineBase
CommandLineBase(int argc, char *const argv[], const char *opts)
Hidden ctor to prevent instantiation.
Definition: cmdline.h:69
mysqlpp::ssqlsxlat::CommandLine::input_source
SourceSink input_source() const
The input source type.
Definition: cmdline.h:210
mysqlpp::examples::CommandLine::server
const char * server() const
Return the DB server name (-s argument)
Definition: cmdline.h:163
mysqlpp::examples::CommandLine::pass
const char * pass() const
Return the DB password (-p argument)
Definition: cmdline.h:153
common.h
This file includes top-level definitions for use both internal to the library, and outside it...
mysqlpp::ssqlsxlat::CommandLine::ss_ssqls1
a C++ file containing an SSQLS v1 declaration
Definition: cmdline.h:191
mysqlpp::ssqlsxlat::CommandLine::output
const char * output() const
The base name of the output file.
Definition: cmdline.h:216
mysqlpp::examples::CommandLine::print_usage
void print_usage() const
Show a message explaining the program&#39;s proper usage.
Definition: cmdline.h:139