// -*- c++ -*- //------------------------------------------------------------------------------ // $Id: CmdLineOpts.h,v 1.7 2005/10/12 02:28:58 vlg Exp $ //------------------------------------------------------------------------------ // CmdLineOpts.h //------------------------------------------------------------------------------ // Copyright (C) 2000,2005 Vladislav Grinchenko // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. //------------------------------------------------------------------------------ #ifndef CMD_LINE_OPTS_H #define CMD_LINE_OPTS_H #include "assa/Assure.h" #include #include using std::string; using std::vector; namespace ASSA { class CmdLineOpts; /** @file CmdLineOpts.h Class to handle processing command-line options. */ /** * Option class. This class is a helper class of CmdLineOpts class. * It is not used by any other class and cannot be instantiated. */ class Option { public: friend class CmdLineOpts; /** @enum type_t Option type. Each option, except for flags has a value following it on the command line. Following types are supported: */ enum type_t { string_t=0, /**< Convert argument to STL string */ int_t, /**< Convert argument to int */ uint_t, /**< Convert argument to unsigned int */ long_t, /**< Convert argument to long */ ulong_t, /**< Convert argument to unsinged long */ double_t, /**< Convert argument to double */ float_t, /**< Convert argument to float */ flag_t, /**< No argument; bool value is flipped. */ func_t, /**< Convert argument to function */ func_one_t, /**< Convert argument to function with one argument */ none_t }; private: /// Private default constructor Option (); /// Private constructor Option (char shopt_, const string& lopt_, type_t type_, void* val_); /// Write object state to the log file void dump () const; /// Return the type of the Option object const char* type_c_str (); private: /// One-letter option name char m_short_name; /// Long option name string m_long_name; /// Option type type_t m_type; /// Pointer to the option value void* m_val; }; inline Option::Option () : m_short_name (' '), m_long_name (""), m_type (none_t), m_val (NULL) { /* empty */ } inline Option::Option (char shopt_, const string& lopt_, type_t type_, void* val_) : m_short_name (shopt_), m_long_name (lopt_), m_type (type_), m_val (val_) { trace_with_mask("Option::Option", CMDLINEOPTS); } /*----------------------------------------------------------------------------*/ class IniFile; /** Class CmdLineOpts. CmdLineOpts class parsers the command line arguments. It is a base class, and to use it, it has to be inherited from. See "ASSA Library User's Guide" for further details. */ class CmdLineOpts { public: typedef void (* OPTS_FUNC) (void); typedef void (* OPTS_FUNC_ONE) (const string&); typedef vector