GCpp general purpose C++ library  version 1.0
GOptionString.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file GOptionString.hh
3  *
4  * Include file for class GOptionString.
5  */
6 //======================================================================
7 
8 #ifndef G_OPTION_STRING_HH
9 #define G_OPTION_STRING_HH
10 
11 #include "GString.hh"
12 
13 //======================================================================
14 /*! \class GOptionString
15  *
16  * Class for options defined by text strings.
17  * Options may be searched for with or without additional numerical
18  * or text parameters.
19  *
20  * The CheckOption() functions search for an option and return true
21  * if it is found in the string, that is let unchanged.
22  * The ExtractOption() functions do the same, but the corresponding
23  * text is removed from the string.
24  *
25  * The search for options ignores spaces between options.
26  *
27  * La recherche d'option ignore les espaces entre les options.
28  *
29  * The option arguments can be defined with 2 froms:
30  * - "... opt = valeur; ..."
31  * - "... opt = (valeur) ..."
32  */
33 
34 class GOptionString : public GString
35 {
36  //------------------------------------------------------------
37  /*! \object_doc */
39  //------------------------------------------------------------
40 
41  protected:
42 
43  static char arg_begin; ///< Character for beginning of argument
44  static char arg_end; ///< Character for end of argument
45  static string arg_separ; ///< Characters to separate options
46  bool case_flag; ///< Indicates if options are case sensitive
47 
48  //------------------------------------------------------------
49  // Constructor / Destructor / Affectation
50  public:
51  GOptionString ( bool case_sens = false );
52  GOptionString ( const string & s, bool case_sens = false );
53  GOptionString ( const char * s, bool case_sens = false );
54  GOptionString ( const GOptionString & s );
55 
56  GOptionString & operator = ( const GOptionString & s );
57  GOptionString & operator = ( const string & s );
58  GOptionString & operator = ( const char * s );
59 
60  virtual ~GOptionString (); // inline
61 
62  //------------------------------------------------------------
63  protected:
64  virtual size_t OptPosition ( const GString &opt ) const;
65  virtual size_t OptPosition ( const GString &opt, size_t &end_pos ) const;
66 
67  virtual string OptArgument ( const size_t pos, size_t &end ) const;
68 
69  //------------------------------------------------------------
70  public:
71 
72  virtual void SetArgumentDelimiter ( char c );
73  virtual void SetArgumentSeparator ( char c );
74  virtual void SetArgumentSeparator ( const string &str );
75  virtual void SetCaseSensitive ( bool case_sens = true );
76 
77  // options check without change of the original option string
78  virtual bool CheckOption ( const char opt ) const;
79  virtual bool CheckOption ( const string &opt ) const;
80 
81  virtual bool CheckOption ( const char opt, string &arg ) const;
82  virtual bool CheckOption ( const string &opt, string &arg ) const;
83 
84  virtual bool CheckOption ( const char opt, int &arg, const int default_val = 0 ) const;
85  virtual bool CheckOption ( const string &opt, int &arg, const int default_val = 0 ) const;
86 
87  virtual bool CheckOption ( const char opt, double &arg, const double default_val = 0. ) const;
88  virtual bool CheckOption ( const string &opt, double &arg, const double default_val = 0. ) const;
89 
90  // options check, removed from original option string
91  virtual bool ExtractOption ( const char opt );
92  virtual bool ExtractOption ( const string &opt );
93 
94  virtual bool ExtractOption ( const char opt, string &arg );
95  virtual bool ExtractOption ( const string &opt, string &arg );
96 
97  virtual bool ExtractOption ( const char opt, int &arg, const int default_val = 0 );
98  virtual bool ExtractOption ( const string &opt, int &arg, const int default_val = 0 );
99 
100  virtual bool ExtractOption ( const char opt, double &arg, const double default_val = 0. );
101  virtual bool ExtractOption ( const string &opt, double &arg, const double default_val = 0. );
102 
103 };
104 
105 //----------------------------------------------------------------------
106 // Inline functions
107 #include "icc/GOptionString.icc"
108 
109 //======================================================================
110 #endif
virtual size_t OptPosition(const GString &opt) const
Definition: GOptionString.cpp:154
virtual bool ExtractOption(const char opt)
Definition: GOptionString.icc:123
virtual void SetCaseSensitive(bool case_sens=true)
Definition: GOptionString.icc:83
static char arg_begin
Character for beginning of argument.
Definition: GOptionString.hh:43
static char arg_end
Character for end of argument.
Definition: GOptionString.hh:44
#define GObject(T)
Definition: GClassDefine.hh:65
Definition: GOptionString.hh:34
static string arg_separ
Characters to separate options.
Definition: GOptionString.hh:45
Definition: GString.hh:44
virtual string OptArgument(const size_t pos, size_t &end) const
Definition: GOptionString.cpp:65
virtual bool CheckOption(const char opt) const
Definition: GOptionString.icc:91
virtual void SetArgumentDelimiter(char c)
Definition: GOptionString.cpp:25
bool case_flag
Indicates if options are case sensitive.
Definition: GOptionString.hh:46
virtual void SetArgumentSeparator(char c)
Definition: GOptionString.icc:70