GCpp general purpose C++ library  version 1.0
GOptionString Class Reference

#include <GOptionString.hh>

Inheritance diagram for GOptionString:
GString

Public Member Functions

template<class Q >
bool IsInstanceOf () const
 
template<class Q >
bool IsInstanceOf ()
 
virtual GOptionStringClone () const
 
virtual const char * ClassName () const
 
 GOptionString (bool case_sens=false)
 
 GOptionString (const string &s, bool case_sens=false)
 
 GOptionString (const char *s, bool case_sens=false)
 
 GOptionString (const GOptionString &s)
 
GOptionStringoperator= (const GOptionString &s)
 
GOptionStringoperator= (const string &s)
 
GOptionStringoperator= (const char *s)
 
virtual ~GOptionString ()
 
virtual void SetArgumentDelimiter (char c)
 
virtual void SetArgumentSeparator (char c)
 
virtual void SetArgumentSeparator (const string &str)
 
virtual void SetCaseSensitive (bool case_sens=true)
 
virtual bool CheckOption (const char opt) const
 
virtual bool CheckOption (const string &opt) const
 
virtual bool CheckOption (const char opt, string &arg) const
 
virtual bool CheckOption (const string &opt, string &arg) const
 
virtual bool CheckOption (const char opt, int &arg, const int default_val=0) const
 
virtual bool CheckOption (const string &opt, int &arg, const int default_val=0) const
 
virtual bool CheckOption (const char opt, double &arg, const double default_val=0.) const
 
virtual bool CheckOption (const string &opt, double &arg, const double default_val=0.) const
 
virtual bool ExtractOption (const char opt)
 
virtual bool ExtractOption (const string &opt)
 
virtual bool ExtractOption (const char opt, string &arg)
 
virtual bool ExtractOption (const string &opt, string &arg)
 
virtual bool ExtractOption (const char opt, int &arg, const int default_val=0)
 
virtual bool ExtractOption (const string &opt, int &arg, const int default_val=0)
 
virtual bool ExtractOption (const char opt, double &arg, const double default_val=0.)
 
virtual bool ExtractOption (const string &opt, double &arg, const double default_val=0.)
 
- Public Member Functions inherited from GString
template<class Q >
bool IsInstanceOf () const
 
template<class Q >
bool IsInstanceOf ()
 
 GString ()
 
 GString (const string &s)
 
 GString (const char *s)
 
 GString (const GString &s)
 
GStringoperator= (const GString &s)
 
GStringoperator= (const string &s)
 
GStringoperator= (const char *s)
 
virtual ~GString ()
 
virtual GString ToLower () const
 
virtual GString ToUpper () const
 
virtual GString NoAccent () const
 
virtual GString NoPunct (const string &punct=",;:.!?", const char rep= ' ') const
 
virtual GString NoSpace (const string &spc=" \n\t\r") const
 
virtual GString NoEndSpace (const string &spc=" \n\t\r") const
 
virtual GString Fill (size_t len, const char c= ' ', bool trunc=false) const
 
size_t FindFirstOf (const string &s, size_t index=0)
 
GStringReplaceChar (char c, char r, u_int n=0)
 
GStringReplaceAll (const GString &s, const GString &r)
 
virtual int Compare (const GString &str) const
 
virtual int CompareDict (const GString &str) const
 
virtual int ReadInt (int default_val=0) const
 
virtual float ReadFloat (float default_val=0.) const
 
virtual double ReadDouble (double default_val=0.) const
 
virtual int ReadSubInt (size_t &ifirst, size_t &ilast, size_t index=0, int default_val=0, const string &separ=" \n\t\r") const
 
virtual float ReadSubFloat (size_t &ifirst, size_t &ilast, const size_t index=0, const float default_val=0., const string &separ=" \n\t\r") const
 
virtual double ReadSubDouble (size_t &ifirst, size_t &ilast, const size_t index=0, const double default_val=0., const string &separ=" \n\t\r") const
 
virtual GString GetSubstring (char first, char last, size_t &ifirst, size_t &ilast, size_t index=0, bool keep=true) const
 
virtual GString GetSubstring (char first, char last, size_t index=0, bool keep=true) const
 
virtual GString GetWord (size_t &ifirst, size_t &ilast, size_t index=0, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual GString GetWord (size_t index=0, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual u_int CountWords (const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual u_int GetWords (string *table, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual string * CreateWordsTable (u_int &nw, const string &separ=" ,;:.!?'[]{}()=+-*&%$#\n\t\r") const
 
virtual size_t FindFormat (const char fmtc, size_t &fmtlen, size_t &len)
 
virtual size_t FindFormat (const char fmtc, size_t &fmtlen)
 
virtual GString ReplaceFormat (const char fmtc, const int val, const char spc= '0')
 

Static Public Member Functions

static const char * StaticClassName ()
 
- Static Public Member Functions inherited from GString
static const char * StaticClassName ()
 

Protected Member Functions

virtual size_t OptPosition (const GString &opt) const
 
virtual size_t OptPosition (const GString &opt, size_t &end_pos) const
 
virtual string OptArgument (const size_t pos, size_t &end) const
 

Protected Attributes

bool case_flag
 Indicates if options are case sensitive.
 

Static Protected Attributes

static char arg_begin = '('
 Character for beginning of argument.
 
static char arg_end = ')'
 Character for end of argument.
 
static string arg_separ = ";, "
 Characters to separate options.
 

Detailed Description

Class for options defined by text strings. Options may be searched for with or without additional numerical or text parameters.

The CheckOption() functions search for an option and return true if it is found in the string, that is let unchanged. The ExtractOption() functions do the same, but the corresponding text is removed from the string.

The search for options ignores spaces between options.

La recherche d'option ignore les espaces entre les options.

The option arguments can be defined with 2 froms:

  • "... opt = valeur; ..."
  • "... opt = (valeur) ..."

Constructor & Destructor Documentation

GOptionString::GOptionString ( bool  case_sens = false)
inline

Default constructor: empty option string.

Parameters
case_sensdefines if case sensitive

References case_flag.

Referenced by operator=().

GOptionString::GOptionString ( const string &  s,
bool  case_sens = false 
)
inline

Constructor from a C++ string..

Parameters
soriginal string
case_sensdefines if case sensitive

References case_flag.

GOptionString::GOptionString ( const char *  s,
bool  case_sens = false 
)
inline

Constructor from a C characters array.

Parameters
soriginal string
case_sensdefines if case sensitive

References case_flag.

GOptionString::GOptionString ( const GOptionString s)
inline

Copy constructor.

Parameters
soriginal string

References case_flag.

GOptionString::~GOptionString ( )
inlinevirtual

Destructor.

Member Function Documentation

bool GOptionString::CheckOption ( const char  opt) const
inlinevirtual

Check if option is included (1 character).

Parameters
optoption character searched

Referenced by CheckOption().

bool GOptionString::CheckOption ( const string &  opt) const
virtual

Check if an option string is present.

Parameters
optoption string to search for

References OptPosition().

bool GOptionString::CheckOption ( const char  opt,
string &  arg 
) const
inlinevirtual

Check if option is included (1 character), with text argument.

Parameters
optoption character searched
argargument value

References CheckOption().

bool GOptionString::CheckOption ( const string &  opt,
string &  arg 
) const
virtual

Check if an option string is present, with string argument.

Parameters
optoption string to search for
argreturned argument value

References OptArgument(), and OptPosition().

bool GOptionString::CheckOption ( const char  opt,
int &  arg,
const int  default_val = 0 
) const
inlinevirtual

Check if option is included (1 character), with integer value argument.

Parameters
optoption character searched
argargument value
default_valdefault argument value if option is not defined

References CheckOption().

bool GOptionString::CheckOption ( const string &  opt,
int &  arg,
const int  default_val = 0 
) const
virtual

Check if an option string is present, with interger value argument.

Parameters
optoption string to search for
argreturned argument value
default_valdefault argument value if option is not defined

References OptArgument(), OptPosition(), and GString::ReadInt().

bool GOptionString::CheckOption ( const char  opt,
double &  arg,
const double  default_val = 0. 
) const
inlinevirtual

Check if option is included (1 character), with double value argument.

Parameters
optoption character searched
argargument value
default_valdefault argument value if option is not defined

References CheckOption().

bool GOptionString::CheckOption ( const string &  opt,
double &  arg,
const double  default_val = 0. 
) const
virtual

Check if an option string is present, with double value argument.

Parameters
optoption string to search for
argreturned argument value
default_valdefault argument value if option is not defined

References OptArgument(), OptPosition(), and GString::ReadDouble().

bool GOptionString::ExtractOption ( const char  opt)
inlinevirtual

Check if option is included (1 character). If found, the option is removed from the original string.

Parameters
optoption character searched

Referenced by ExtractOption().

bool GOptionString::ExtractOption ( const string &  opt)
virtual

Check if option is included (1 character). If found, the option is removed from the original string.

Parameters
optoption character searched

References OptPosition().

bool GOptionString::ExtractOption ( const char  opt,
string &  arg 
)
inlinevirtual

Check if option is included (1 character), with text argument. If found, the option is removed from the original string.

Parameters
optoption character searched
argargument value

References ExtractOption().

bool GOptionString::ExtractOption ( const string &  opt,
string &  arg 
)
virtual

Check if option is included (1 character), with text argument. If found, the option is removed from the original string.

Parameters
optoption character searched
argargument value

References OptArgument(), and OptPosition().

bool GOptionString::ExtractOption ( const char  opt,
int &  arg,
const int  default_val = 0 
)
inlinevirtual

Check if option is included (1 character), with integer value argument. If found, the option is removed from the original string.

Parameters
optoption character searched
argargument value
default_valdefault argument value if option is not defined

References ExtractOption().

bool GOptionString::ExtractOption ( const string &  opt,
int &  arg,
const int  default_val = 0 
)
virtual

Check if option is included (1 character), with integer value argument. If found, the option is removed from the original string.

Parameters
optoption character searched
argargument value
default_valdefault argument value if option is not defined

References OptArgument(), OptPosition(), and GString::ReadInt().

bool GOptionString::ExtractOption ( const char  opt,
double &  arg,
const double  default_val = 0. 
)
inlinevirtual

Check if option is included (1 character), with double value argument. If found, the option is removed from the original string.

Parameters
optoption character searched
argargument value
default_valdefault argument value if option is not defined

References ExtractOption().

bool GOptionString::ExtractOption ( const string &  opt,
double &  arg,
const double  default_val = 0. 
)
virtual

Check if option is included (1 character), with double value argument. If found, the option is removed from the original string.

Parameters
optoption character searched
argargument value
default_valdefault argument value if option is not defined

References OptArgument(), OptPosition(), and GString::ReadDouble().

template<class Q >
bool GOptionString::IsInstanceOf ( ) const
inline

Macro from GCpp library that defines the following functions:

  • ClassName(): return the real class name of the object
  • StaticClassName(): return the used class name of the object (that may be a base class of the real object).
  • IsInstanceOf<T>(): return true if the current object is an instance of the template class name argument
  • Clone(): return an allocated copy of the object.
GOptionString & GOptionString::operator= ( const GOptionString s)
inline

Affectation operator.

Parameters
soption string
GOptionString & GOptionString::operator= ( const string &  s)
inline

Affectation operator.

Parameters
soption string
GOptionString & GOptionString::operator= ( const char *  s)
inline

Affectation operator.

Parameters
soption string

References GOptionString().

string GOptionString::OptArgument ( const size_t  pos,
size_t &  end 
) const
protectedvirtual

Extract an argument from a string: it is searched for with 2 possible forms (if delimiters are parenthesis):

  • "=(argument)" then other options can be placed after
  • "=argument" that take all the remaining of the string In order to use the end delimiter in the argument itself, it must be preceded by '\'. This function is protected since it is called by public functions.
    Parameters
    posstart position to search for argument
    endreturned position of the end of the argument

References arg_begin, arg_end, and arg_separ.

Referenced by CheckOption(), and ExtractOption().

size_t GOptionString::OptPosition ( const GString opt) const
protectedvirtual

Return the position of an option in the string: if option is not found; string::npos is returned.

Parameters
optoption to check

References case_flag, and GString::ToUpper().

Referenced by CheckOption(), ExtractOption(), and OptPosition().

size_t GOptionString::OptPosition ( const GString opt,
size_t &  end_pos 
) const
protectedvirtual

Return the position of an option in the string: if option is not found; string::npos is returned. The end_pos argument variable returns the end position of the option.

Parameters
optoption to check
end_posreturned end of option position in the string

References OptPosition().

void GOptionString::SetArgumentDelimiter ( char  c)
virtual

Set the arguments delimiter. Accepted delimiters are (...) {...} [...] "..." and ... The delimiter is set by specifying either beginning or end character.

Parameters
copen or close delimiter

References arg_begin, and arg_end.

void GOptionString::SetArgumentSeparator ( char  c)
inlinevirtual

Set the unique character defining argument separator.

Parameters
cselected character

References arg_separ.

void GOptionString::SetArgumentSeparator ( const string &  str)
inlinevirtual

Set a list of character defining accepted argument separators.

Parameters
strstring of selected characters

References arg_separ.

void GOptionString::SetCaseSensitive ( bool  case_sens = true)
inlinevirtual

Set the case sentitivity of options search.

Parameters
case_senslogical value

References case_flag.


The documentation for this class was generated from the following files: