Manages the value of an option and defines how it is parsed from a string. More...
#include <value.h>
Classes | |
union | ValueDesc |
Public Types | |
enum | DescType { desc_name = 1, desc_default = 2, desc_implicit = 4 } |
Possible value descriptions. More... | |
enum | State { value_unassigned = 0, value_defaulted = 1, value_fixed = 2 } |
Possible (tentative) states of an option value. More... | |
Public Member Functions | |
Value * | alias (char c) |
Sets an alias name for the corresponding option. | |
char | alias () const |
const char * | arg () const |
Returns the name of this value. | |
Value * | arg (const char *n) |
Value * | composing () |
Value * | defaultsTo (const char *v) |
const char * | defaultsTo () const |
Returns the default value of this or 0 none exists. | |
Value * | flag () |
Value * | implicit (const char *str) |
const char * | implicit () const |
Returns the implicit value of this or 0 if isImplicit() == false. | |
bool | isComposing () const |
Returns true if the value of this option can be composed from multiple source. | |
bool | isFlag () const |
Returns true if this is the value of an option flag. | |
bool | isImplicit () const |
Returns true if value can be implicitly created from an empty string. | |
bool | isNegatable () const |
Returns true if this is the value of an negatable option. | |
Value * | level (DescriptionLevel lev) |
Sets a description level for the corresponding option. | |
DescriptionLevel | level () const |
Returns the description level of the corresponding option. | |
Value * | negatable () |
bool | parse (const std::string &name, const std::string &value, State st=value_fixed) |
Parses the given string and updates the value's state. | |
State | state () const |
Returns the current state of this value. | |
Value * | state (Value::State s) |
virtual | ~Value () |
Protected Types | |
typedef unsigned char | byte_t |
enum | Property { property_implicit = 1, property_flag = 3, property_composing = 4, property_negatable = 8, property_location = 16, not_a_property = 32 } |
Protected Member Functions | |
void | clearProperty (Property f) |
const char * | desc (DescType t) const |
Value * | desc (DescType t, const char *d) |
virtual bool | doParse (const std::string &name, const std::string &value)=0 |
bool | hasProperty (Property f) const |
void | setProperty (Property f) |
bool | state (bool b, State s) |
Value (byte_t flagSet, State initial=value_unassigned) | |
Private Types | |
enum | { desc_pack = 8, level_shift = not_a_property, levels = 255/level_shift } |
Private Attributes | |
union ProgramOptions::Value::ValueDesc | desc_ |
byte_t | descFlag_ |
byte_t | flags_ |
byte_t | optAlias_ |
byte_t | state_ |
Manages the value of an option and defines how it is parsed from a string.
The library maintains a 1:1-relationship between options and their values. That is, an option has exactly one value and a value has exactly one state w.r.t its option.
typedef unsigned char ProgramOptions::Value::byte_t [protected] |
anonymous enum [private] |
enum ProgramOptions::Value::Property [protected] |
ProgramOptions::Value::~Value | ( | ) | [virtual] |
Definition at line 128 of file program_options.cpp.
ProgramOptions::Value::Value | ( | byte_t | flagSet, |
State | initial = value_unassigned |
||
) | [protected] |
Definition at line 120 of file program_options.cpp.
Value* ProgramOptions::Value::alias | ( | char | c | ) | [inline] |
char ProgramOptions::Value::alias | ( | ) | const [inline] |
const char * ProgramOptions::Value::arg | ( | ) | const |
Returns the name of this value.
Definition at line 134 of file program_options.cpp.
Value* ProgramOptions::Value::arg | ( | const char * | n | ) | [inline] |
void ProgramOptions::Value::clearProperty | ( | Property | f | ) | [inline, protected] |
Value* ProgramOptions::Value::composing | ( | ) | [inline] |
Value* ProgramOptions::Value::defaultsTo | ( | const char * | v | ) | [inline] |
const char* ProgramOptions::Value::defaultsTo | ( | ) | const [inline] |
const char * ProgramOptions::Value::desc | ( | DescType | t | ) | const [protected] |
Definition at line 162 of file program_options.cpp.
Value * ProgramOptions::Value::desc | ( | DescType | t, |
const char * | d | ||
) | [protected] |
Definition at line 140 of file program_options.cpp.
virtual bool ProgramOptions::Value::doParse | ( | const std::string & | name, |
const std::string & | value | ||
) | [protected, pure virtual] |
Value* ProgramOptions::Value::flag | ( | ) | [inline] |
Marks the value as flag.
bool ProgramOptions::Value::hasProperty | ( | Property | f | ) | const [inline, protected] |
Value* ProgramOptions::Value::implicit | ( | const char * | str | ) | [inline] |
Sets an implicit value, which will be used if option is given without an adjacent value, e.g. '--option' instead of '--option value'
const char * ProgramOptions::Value::implicit | ( | ) | const |
Returns the implicit value of this or 0 if isImplicit() == false.
Definition at line 171 of file program_options.cpp.
bool ProgramOptions::Value::isComposing | ( | ) | const [inline] |
bool ProgramOptions::Value::isFlag | ( | ) | const [inline] |
bool ProgramOptions::Value::isImplicit | ( | ) | const [inline] |
Returns true if value can be implicitly created from an empty string.
bool ProgramOptions::Value::isNegatable | ( | ) | const [inline] |
Value* ProgramOptions::Value::level | ( | DescriptionLevel | lev | ) | [inline] |
DescriptionLevel ProgramOptions::Value::level | ( | ) | const [inline] |
Value* ProgramOptions::Value::negatable | ( | ) | [inline] |
bool ProgramOptions::Value::parse | ( | const std::string & | name, |
const std::string & | value, | ||
State | st = value_fixed |
||
) |
Parses the given string and updates the value's state.
name | The name of the option associated with this value. |
value | The value to parse. |
st | The state to which the value should transition if parsing is succesful. |
Definition at line 177 of file program_options.cpp.
void ProgramOptions::Value::setProperty | ( | Property | f | ) | [inline, protected] |
State ProgramOptions::Value::state | ( | ) | const [inline] |
Value* ProgramOptions::Value::state | ( | Value::State | s | ) | [inline] |
bool ProgramOptions::Value::state | ( | bool | b, |
State | s | ||
) | [inline, protected] |
union ProgramOptions::Value::ValueDesc ProgramOptions::Value::desc_ [private] |
byte_t ProgramOptions::Value::descFlag_ [private] |
byte_t ProgramOptions::Value::flags_ [private] |
byte_t ProgramOptions::Value::optAlias_ [private] |
byte_t ProgramOptions::Value::state_ [private] |