# cmdline.h

    00001 /***********************************************************************
    00002  cmdline.h - Declares the interface to the MySQL++'s command line
    00003         parsing logic, used by the examples and the utility programs.
    00004         Not intended for use by third parties!  If it breaks, you
    00005         get to keep all the pieces.
    00006
    00007  Copyright (c) 2007-2009 by Educational Technology Resources, Inc.
    00008  Others may also hold copyrights on code in this file.  See the
    00009  CREDITS.txt file in the top directory of the distribution for details.
    00010
    00011  This file is part of MySQL++.
    00012
    00013  MySQL++ is free software; you can redistribute it and/or modify it
    00014  under the terms of the GNU Lesser General Public License as published
    00015  by the Free Software Foundation; either version 2.1 of the License, or
    00016  (at your option) any later version.
    00017
    00018  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00019  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00020  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00021  License for more details.
    00022
    00023  You should have received a copy of the GNU Lesser General Public
    00024  License along with MySQL++; if not, write to the Free Software
    00025  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00026  USA
    00027 ***********************************************************************/
    00028
    00029 #if !defined(MYSQLPP_CMDLINE_H)
    00030 #define MYSQLPP_CMDLINE_H
    00031
    00032 #include "common.h"
    00033
    00034 #include <string>
    00035 #include <vector>
    00036
    00037 #include <assert.h>
    00038
    00039 namespace mysqlpp {
    00044         class MYSQLPP_EXPORT CommandLineBase
    00045         {
    00046         public:
    00049                 typedef std::vector<std::string> ArgumentList;
    00051                 typedef ArgumentList::const_iterator ArgumentListIt;
    00052
    00056                 const ArgumentList& extra_args() const
    00057                                 { return extra_args_; }
    00058
    00061                 operator void*() const
    00062                 {
    00063                         return successful_ ? const_cast<bool*>(&successful_) : 0;
    00064                 }
    00065
    00066         protected:
    00069                 CommandLineBase(int argc, char* const argv[], const char* opts) :
    00070                 argc_(argc),
    00071                 argv_(argv),
    00072                 opts_(opts),
    00073                 successful_(argc > 0 && argv && opts)
    00074                 {
    00075                         assert(successful_);
    00076                 }
    00078                 virtual ~CommandLineBase() { }
    00079
    00083                 void finish_parse();
    00084
    00086                 const char* option_argument() const;
    00088                 int option_index() const;
    00089
    00095                 void parse_error(const char* message = 0);
    00096
    00098                 int parse_next() const;
    00099
    00101                 virtual void print_usage() const = 0;
    00102
    00104                 const char* program_name() const { return argv_[0]; }
    00105
    00108                 bool successful() const { return successful_; }
    00109
    00110         private:
    00112                 int argc_;
    00113                 char* const* argv_;
    00114                 const char* opts_;
    00115                 bool successful_;
    00116                 ArgumentList extra_args_;
    00117         };
    00118
    00119
    00121         namespace examples {
    00123                 extern MYSQLPP_EXPORT const char* db_name;
    00124
    00126                 class MYSQLPP_EXPORT CommandLine : public CommandLineBase
    00127                 {
    00128                 public:
    00131                         CommandLine(int argc, char* const argv[],
    00132                                         const char* user = 0, const char* pass = 0,
    00133                                         const char* usage_extra = 0);
    00134
    00139                         void print_usage() const { print_usage(usage_extra_); }
    00140
    00144                         void print_usage(const char* extra) const;
    00145
    00150                         bool dtest_mode() const { return dtest_mode_; }
    00151
    00153                         const char* pass() const { return pass_; }
    00154
    00160                         int run_mode() const { return run_mode_; }
    00161
    00163                         const char* server() const { return server_; }
    00164
    00166                         const char* user() const { return user_; }
    00167
    00168                 private:
    00170                         // Examples-specific command line parse results
    00171                         bool dtest_mode_;
    00172                         int run_mode_;
    00173                         const char* server_;
    00174                         const char* user_;
    00175                         const char* pass_;
    00176                         const char* usage_extra_;
    00177                 };
    00178         } // end namespace mysqlpp::examples
    00179
    00180
    00182         namespace ssqlsxlat {
    00184                 class MYSQLPP_EXPORT CommandLine : public CommandLineBase
    00185                 {
    00186                 public:
    00189                         enum SourceSink {
    00190                                 ss_unknown,
    00191                                 ss_ssqls1,
    00192                                 ss_ssqls2,
    00193                                 ss_table
    00194                         };
    00195
    00198                         CommandLine(int argc, char* const argv[]);
    00199
    00201                         void print_usage() const;
    00202
    00207                         const char* input() const { return input_; }
    00208
    00210                         SourceSink input_source() const { return input_source_; }
    00211
    00213                         SourceSink output_sink() const { return output_sink_; }
    00214
    00216                         const char* output() const { return output_; }
    00217
    00219                         const char* pass() const { return pass_; }
    00220
    00222                         const char* server() const { return server_; }
    00223
    00225                         const char* user() const { return user_; }
    00226
    00227                 private:
    00229                         const char* input_;
    00230                         const char* output_;
    00231                         const char* pass_;
    00232                         const char* server_;
    00233                         const char* user_;
    00234                         SourceSink input_source_;
    00235                         SourceSink output_sink_;
    00236                 };
    00237         } // end namespace mysqlpp::ssqlsxlat
    00238 } // end namespace mysqlpp
    00239
    00240 #endif // !defined(MYSQLPP_CMDLINE_H)
    00241