Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Types | Private Attributes
ProgramOptions::Value Class Reference

Manages the value of an option and defines how it is parsed from a string. More...

#include <value.h>

Inheritance diagram for ProgramOptions::Value:
Inheritance graph
[legend]

List of all members.

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

Valuealias (char c)
 Sets an alias name for the corresponding option.
char alias () const
const char * arg () const
 Returns the name of this value.
Valuearg (const char *n)
Valuecomposing ()
ValuedefaultsTo (const char *v)
const char * defaultsTo () const
 Returns the default value of this or 0 none exists.
Valueflag ()
Valueimplicit (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.
Valuelevel (DescriptionLevel lev)
 Sets a description level for the corresponding option.
DescriptionLevel level () const
 Returns the description level of the corresponding option.
Valuenegatable ()
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.
Valuestate (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
Valuedesc (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_

Detailed Description

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.

Definition at line 53 of file value.h.


Member Typedef Documentation

typedef unsigned char ProgramOptions::Value::byte_t [protected]

Definition at line 179 of file value.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
desc_pack 
level_shift 
levels 

Definition at line 197 of file value.h.

Possible value descriptions.

Enumerator:
desc_name 
desc_default 
desc_implicit 

Definition at line 62 of file value.h.

Enumerator:
property_implicit 
property_flag 
property_composing 
property_negatable 
property_location 
not_a_property 

Definition at line 180 of file value.h.

Possible (tentative) states of an option value.

Enumerator:
value_unassigned 

no value assigned

value_defaulted 

a default value is assigned

value_fixed 

a parsed value is assigned

Definition at line 56 of file value.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

Value* ProgramOptions::Value::alias ( char  c) [inline]

Sets an alias name for the corresponding option.

Definition at line 89 of file value.h.

char ProgramOptions::Value::alias ( ) const [inline]

Definition at line 90 of file value.h.

const char * ProgramOptions::Value::arg ( ) const

Returns the name of this value.

Note:
The default name is "<arg>" unless isFlag() is true in which case the default is "".

Definition at line 134 of file program_options.cpp.

Value* ProgramOptions::Value::arg ( const char *  n) [inline]

Definition at line 86 of file value.h.

void ProgramOptions::Value::clearProperty ( Property  f) [inline, protected]

Definition at line 190 of file value.h.

Marks the value as composing.

See also:
Value::isComposing()

Definition at line 147 of file value.h.

Value* ProgramOptions::Value::defaultsTo ( const char *  v) [inline]

Sets a default value for this value.

Definition at line 152 of file value.h.

const char* ProgramOptions::Value::defaultsTo ( ) const [inline]

Returns the default value of this or 0 none exists.

Definition at line 154 of file value.h.

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]

Marks the value as flag.

See also:
bool Value::isFlag() const

Definition at line 138 of file value.h.

bool ProgramOptions::Value::hasProperty ( Property  f) const [inline, protected]

Definition at line 191 of file value.h.

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'

See also:
bool Value::isImplicit() const

Definition at line 161 of file value.h.

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]

Returns true if the value of this option can be composed from multiple source.

Definition at line 142 of file value.h.

bool ProgramOptions::Value::isFlag ( ) const [inline]

Returns true if this is the value of an option flag.

Similar to isImplicit but with the difference that no value is accepted on the command-line.

Used for options like '--help' or '--version'.

Definition at line 132 of file value.h.

bool ProgramOptions::Value::isImplicit ( ) const [inline]

Returns true if value can be implicitly created from an empty string.

Note:
the implicit value comes into play if the corresponding option is present but without an adjacent value.
an explicit value for an implicit value is only used if it is unambiguously given. E.g. on the command-line one has to use '--option=value' or '-ovalue' but *not* '--option value' or '-o value'.

Definition at line 123 of file value.h.

bool ProgramOptions::Value::isNegatable ( ) const [inline]

Returns true if this is the value of an negatable option.

If an option '--option' is negatable, passing '--no-option' on the command-line will set the value of '--option' to 'no'.

Definition at line 109 of file value.h.

Sets a description level for the corresponding option.

Description levels can be used to suppress certain options when generating option descriptions.

Definition at line 96 of file value.h.

Returns the description level of the corresponding option.

Definition at line 102 of file value.h.

Definition at line 110 of file value.h.

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.

Parameters:
nameThe name of the option associated with this value.
valueThe value to parse.
stThe state to which the value should transition if parsing is succesful.
Returns:
  • true if the given string contains a valid value
  • false otherwise
Postcondition:
if true is returned, state() is st

Definition at line 177 of file program_options.cpp.

void ProgramOptions::Value::setProperty ( Property  f) [inline, protected]

Definition at line 189 of file value.h.

State ProgramOptions::Value::state ( ) const [inline]

Returns the current state of this value.

Definition at line 70 of file value.h.

Sets the (initial) state of this value to s.

Definition at line 75 of file value.h.

bool ProgramOptions::Value::state ( bool  b,
State  s 
) [inline, protected]

Definition at line 192 of file value.h.


Member Data Documentation

Definition at line 200 of file value.h.

Definition at line 199 of file value.h.

Definition at line 201 of file value.h.

Definition at line 198 of file value.h.


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


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:41