11 #ifndef _LIMBO_PROGRAMOPTIONS_PROGRAMOPTIONS_H
12 #define _LIMBO_PROGRAMOPTIONS_PROGRAMOPTIONS_H
28 namespace programoptions
58 virtual const char*
what()
const throw () {
return m_msg.c_str();}
75 ValueBase(std::string
const& cat, std::string
const& m)
109 virtual bool parse(
const char*) = 0;
114 virtual void print(std::ostream& os)
const = 0;
152 virtual bool help_on()
const = 0;
216 template <
typename T>
231 Value(std::string
const& cat, value_type* target, std::string
const& m)
292 virtual void print(std::ostream& os)
const
359 std::ostringstream oss;
361 return oss.str().size();
483 template <
typename ValueType>
490 bool parse(
int argc,
char** argv);
495 bool count(std::string
const& cat)
const;
505 void print(std::ostream& os)
const;
523 assert_msg(num < 1000,
"num out of bounds: " << num);
524 os << std::string (num,
' ');
536 template <
typename ValueType>
539 std::pair<cat2index_map_type::iterator, bool> insertRet =
m_mCat2Index.insert(std::make_pair(data.category(),
m_vData.size()));
540 if (insertRet.second)
541 m_vData.push_back(
new ValueType (data));
std::map< std::string, unsigned > m_mCat2Index
saving mapping for flag to option
Value(Value const &rhs)
copy constructor
std::string m_msg
message of the exception
std::vector< ValueBase * > m_vData
saving options
Value(std::string const &cat, value_type *target, std::string const &m)
constructor
unsigned char m_toggle
true if this option is a toggle value
ProgramOptionsException(std::string const &msg)
constructor
metafunction for parsing a char-based string to a target data type
std::map< std::string, unsigned > cat2index_map_type
mapping from category to index
virtual ~ValueBase()
destructor
ValueBase base_type
base type
ValueBase(ValueBase const &rhs)
copy constructor
std::string m_default_display
display default value
virtual bool parse(const char *v)
parse data from string
void copy(ValueBase const &rhs)
copy another object
abstract type of data value which defines various virtual functions
virtual bool valid_target() const
check whether target value is valid
virtual bool valid_default() const
check whether default value is valid
~ProgramOptions()
destructor
unsigned char m_valid
true if target is set, not default
virtual bool valid_target() const =0
check whether target value is valid
friend std::ostream & operator<<(std::ostream &os, ProgramOptions const &rhs)
print help message by override operator<<
virtual const char * what() const
access message
helper function objects for various data types
metafunction for printing a target data type
virtual bool valid_toggle() const =0
check whether toggle value is valid
virtual void print(std::ostream &os) const
print target value
std::string const & msg() const
std::string const & category() const
std::string m_category
category
ProgramOptions(std::string const &title="Available options")
constructor
ValueBase & operator=(ValueBase const &rhs)
assignment
ProgramOptions & add_option(ValueType const &data)
generic API to add options of various data types
virtual bool help_on() const =0
check whether help message is turned on
std::string m_title
title of options
virtual void apply_toggle()=0
apply toggle value
virtual ~Value()
destructor
a generic class for various data values
virtual bool valid_default() const =0
check whether default value is valid
ValueBase(std::string const &cat, std::string const &m)
constructor
Value & operator=(Value const &rhs)
assignment
virtual Value & toggle_value(value_type const &v)
set toggle value
unsigned char m_required
whether the value is a required option
ProgramOptionsException(ProgramOptionsException const &rhs)
copy constructor
bool count(std::string const &cat) const
virtual Value & toggle(bool t)
set toggle flag
std::exception base_type
base type
virtual ~ProgramOptionsException()
destructor
virtual bool parse(const char *)=0
parse command
virtual void print_default(std::ostream &os) const
print default value
value_type * m_default_value
default value
virtual unsigned count_default_chars() const =0
count the length of default value string
void copy(Value const &rhs)
copy another object
std::string m_msg
helper message
virtual bool help_on() const
check whether help message is turned on
virtual Value & required(bool r)
set required flag
void print_space(std::ostream &os, unsigned num) const
print a specific number of spaces
virtual Value & help(bool h)
set help flag
top API to parse program options
unsigned char m_help
whether is help option
Check string is integer, floating point, number... Convert string to upper/lower cases.
void print_category(std::ostream &os) const
print category
metafunction for assign a source data type to a target data type
virtual void apply_toggle()
apply toggle value
void print() const
print help message
virtual void print_default(std::ostream &os) const =0
print default value
void print_msg(std::ostream &os) const
print message
value_type * m_toggle_value
only valid when this option is a toggle value
bool parse(int argc, char **argv)
read command line options
an exception class for limbo::programoptions::ProgramOptions
virtual void print(std::ostream &os) const =0
print target value
virtual bool valid_toggle() const
check whether toggle value is valid
metafunction for boolean operation
#define assert_msg(condition, message)
assertion with message
virtual Value & default_value(value_type const &v, std::string const &d="")
set default value
virtual void apply_default()=0
apply default value
virtual unsigned count_default_chars() const
count the length of default value string
virtual void apply_default()
apply default value
value_type * m_target
NULL for help.