11#ifndef _LIMBO_PROGRAMOPTIONS_PROGRAMOPTIONS_H
12#define _LIMBO_PROGRAMOPTIONS_PROGRAMOPTIONS_H
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;
292 virtual void print(std::ostream& os)
const
359 std::ostringstream oss;
361 return oss.str().size();
483 template <
typename ValueType>
495 bool count(std::string
const& cat)
const;
524 os << std::string (num,
' ');
536template <
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));
#define limboAssertMsg(condition, args...)
custom assertion with message
helper function objects for various data types
Check string is integer, floating point, number... Convert string to upper/lower cases.
std::exception base_type
base type
virtual ~ProgramOptionsException()
destructor
virtual const char * what() const
access message
std::string m_msg
message of the exception
ProgramOptionsException(std::string const &msg)
constructor
ProgramOptionsException(ProgramOptionsException const &rhs)
copy constructor
ProgramOptions(ProgramOptions const &rhs)
copy constructor
void print_space(std::ostream &os, unsigned num) const
print a specific number of spaces
bool parse(int argc, char **argv)
read command line options
void print(std::ostream &os) const
print help message
bool count(std::string const &cat) const
void print() const
print help message
~ProgramOptions()
destructor
std::map< std::string, unsigned > cat2index_map_type
mapping from category to index
std::map< std::string, unsigned > m_mCat2Index
saving mapping for flag to option
ProgramOptions(std::string const &title="Available options")
constructor
std::string m_title
title of options
std::vector< ValueBase * > m_vData
saving options
friend std::ostream & operator<<(std::ostream &os, ProgramOptions const &rhs)
print help message by override operator<<
ProgramOptions & add_option(ValueType const &data)
generic API to add options of various data types
unsigned char m_required
whether the value is a required option
virtual bool valid_toggle() const =0
check whether toggle value is valid
virtual bool help_on() const =0
check whether help message is turned on
virtual void apply_default()=0
apply default value
std::string const & msg() const
ValueBase(std::string const &cat, std::string const &m)
constructor
virtual void print_default(std::ostream &os) const =0
print default value
unsigned char m_help
whether is help option
std::string m_category
category
ValueBase(ValueBase const &rhs)
copy constructor
ValueBase & operator=(ValueBase const &rhs)
assignment
std::string m_msg
helper message
std::string const & category() const
void copy(ValueBase const &rhs)
copy another object
void print_category(std::ostream &os) const
print category
virtual void print(std::ostream &os) const =0
print target value
virtual bool valid_target() const =0
check whether target value is valid
unsigned char m_toggle
true if this option is a toggle value
void print_msg(std::ostream &os) const
print message
virtual bool valid_default() const =0
check whether default value is valid
virtual bool parse(const char *)=0
parse command
virtual unsigned count_default_chars() const =0
count the length of default value string
unsigned char m_valid
true if target is set, not default
virtual void apply_toggle()=0
apply toggle value
virtual ~ValueBase()
destructor
virtual ~Value()
destructor
virtual Value & default_value(value_type const &v, std::string const &d="")
set default value
virtual void apply_toggle()
apply toggle value
virtual Value & toggle_value(value_type const &v)
set toggle value
value_type * m_default_value
default value
Value(std::string const &cat, value_type *target, std::string const &m)
constructor
ValueBase base_type
base type
virtual Value & required(bool r)
set required flag
virtual Value & toggle(bool t)
set toggle flag
Value(Value const &rhs)
copy constructor
virtual bool valid_target() const
check whether target value is valid
virtual bool help_on() const
check whether help message is turned on
Value & operator=(Value const &rhs)
assignment
virtual bool valid_toggle() const
check whether toggle value is valid
virtual unsigned count_default_chars() const
count the length of default value string
virtual void print_default(std::ostream &os) const
print default value
virtual void apply_default()
apply default value
value_type * m_target
NULL for help.
virtual bool valid_default() const
check whether default value is valid
void copy(Value const &rhs)
copy another object
virtual bool parse(const char *v)
parse data from string
virtual Value & help(bool h)
set help flag
virtual void print(std::ostream &os) const
print target value
std::string m_default_display
display default value
value_type * m_toggle_value
only valid when this option is a toggle value
namespace for Limbo.ProgramOptions
metafunction for assign a source data type to a target data type
metafunction for boolean operation
metafunction for parsing a char-based string to a target data type
metafunction for printing a target data type