cmdline.h
/***********************************************************************
cmdline.h - Declares the interface to the MySQL++'s command line
parsing logic, used by the examples and the utility programs.
Not intended for use by third parties! If it breaks, you
get to keep all the pieces.
Copyright (c) 2007-2009 by Educational Technology Resources, Inc.
Others may also hold copyrights on code in this file. See the
CREDITS.txt file in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_CMDLINE_H)
#define MYSQLPP_CMDLINE_H
#include "common.h"
#include <string>
#include <vector>
#include <assert.h>
namespace mysqlpp {
class MYSQLPP_EXPORT CommandLineBase
{
public:
typedef std::vector<std::string> ArgumentList;
typedef ArgumentList::const_iterator ArgumentListIt;
const ArgumentList& extra_args() const
{ return extra_args_; }
operator void*() const
{
return successful_ ? const_cast<bool*>(&successful_) : 0;
}
protected:
CommandLineBase(int argc, char* const argv[], const char* opts) :
argc_(argc),
argv_(argv),
opts_(opts),
successful_(argc > 0 && argv && opts)
{
assert(successful_);
}
virtual ~CommandLineBase() { }
void finish_parse();
const char* option_argument() const;
int option_index() const;
void parse_error(const char* message = 0);
int parse_next() const;
virtual void print_usage() const = 0;
const char* program_name() const { return argv_[0]; }
bool successful() const { return successful_; }
private:
int argc_;
char* const* argv_;
const char* opts_;
bool successful_;
ArgumentList extra_args_;
};
namespace examples {
extern MYSQLPP_EXPORT const char* db_name;
class MYSQLPP_EXPORT CommandLine : public CommandLineBase
{
public:
CommandLine(int argc, char* const argv[],
const char* user = 0, const char* pass = 0,
const char* usage_extra = 0);
void print_usage() const { print_usage(usage_extra_); }
void print_usage(const char* extra) const;
bool dtest_mode() const { return dtest_mode_; }
const char* pass() const { return pass_; }
int run_mode() const { return run_mode_; }
const char* server() const { return server_; }
const char* user() const { return user_; }
private:
// Examples-specific command line parse results
bool dtest_mode_;
int run_mode_;
const char* server_;
const char* user_;
const char* pass_;
const char* usage_extra_;
};
} // end namespace mysqlpp::examples
namespace ssqlsxlat {
class MYSQLPP_EXPORT CommandLine : public CommandLineBase
{
public:
enum SourceSink {
ss_unknown,
ss_ssqls1,
ss_ssqls2,
ss_table
};
CommandLine(int argc, char* const argv[]);
void print_usage() const;
const char* input() const { return input_; }
SourceSink input_source() const { return input_source_; }
SourceSink output_sink() const { return output_sink_; }
const char* output() const { return output_; }
const char* pass() const { return pass_; }
const char* server() const { return server_; }
const char* user() const { return user_; }
private:
const char* input_;
const char* output_;
const char* pass_;
const char* server_;
const char* user_;
SourceSink input_source_;
SourceSink output_sink_;
};
} // end namespace mysqlpp::ssqlsxlat
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_CMDLINE_H)
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