clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | List of all members
ProgramOptions::Value Class Referenceabstract

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
Collaboration diagram for ProgramOptions::Value:
Collaboration graph

Public Types

enum  State { value_unassigned = 0, value_defaulted = 1, value_fixed = 2 }
 Possible (tentative) states of an option value. More...
 
enum  DescType { desc_name = 1, desc_default = 2, desc_implicit = 4 }
 Possible value descriptions. More...
 

Public Member Functions

virtual ~Value ()
 
State state () const
 Returns the current state of this value. More...
 
Valuestate (Value::State s)
 
const char * arg () const
 Returns the name of this value. More...
 
Valuearg (const char *n)
 
Valuealias (char c)
 Sets an alias name for the corresponding option. More...
 
char alias () const
 
Valuelevel (DescriptionLevel lev)
 Sets a description level for the corresponding option. More...
 
DescriptionLevel level () const
 Returns the description level of the corresponding option. More...
 
bool isNegatable () const
 Returns true if this is the value of an negatable option. More...
 
Valuenegatable ()
 
bool isImplicit () const
 Returns true if value can be implicitly created from an empty string. More...
 
bool isFlag () const
 Returns true if this is the value of an option flag. More...
 
Valueflag ()
 
bool isComposing () const
 Returns true if the value of this option can be composed from multiple source. More...
 
Valuecomposing ()
 
ValuedefaultsTo (const char *v)
 
const char * defaultsTo () const
 Returns the default value of this or 0 none exists. More...
 
Valueimplicit (const char *str)
 
const char * implicit () const
 Returns the implicit value of this or 0 if isImplicit() == false. More...
 
bool parse (const std::string &name, const std::string &value, State st=value_fixed)
 Parses the given string and updates the value's state. More...
 

Protected Types

enum  Property {
  property_implicit = 1, property_flag = 3, property_composing = 4, property_negatable = 8,
  property_location =16, not_a_property =32
}
 
typedef unsigned char byte_t
 

Protected Member Functions

 Value (byte_t flagSet, State initial=value_unassigned)
 
void setProperty (Property f)
 
void clearProperty (Property f)
 
bool hasProperty (Property f) const
 
bool state (bool b, State s)
 
virtual bool doParse (const std::string &name, const std::string &value)=0
 
const char * desc (DescType t) const
 
Valuedesc (DescType t, const char *d)
 

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.

Member Typedef Documentation

typedef unsigned char ProgramOptions::Value::byte_t
protected

Member Enumeration Documentation

Possible value descriptions.

Enumerator
desc_name 
desc_default 
desc_implicit 
Enumerator
property_implicit 
property_flag 
property_composing 
property_negatable 
property_location 
not_a_property 

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

Constructor & Destructor Documentation

ProgramOptions::Value::~Value ( )
virtual
ProgramOptions::Value::Value ( byte_t  flagSet,
State  initial = value_unassigned 
)
protected

Member Function Documentation

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

Sets an alias name for the corresponding option.

char ProgramOptions::Value::alias ( ) const
inline
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 "".

Here is the call graph for this function:

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

Here is the call graph for this function:

void ProgramOptions::Value::clearProperty ( Property  f)
inlineprotected
Value* ProgramOptions::Value::composing ( )
inline

Marks the value as composing.

See also
Value::isComposing()

Here is the call graph for this function:

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

Sets a default value for this value.

Here is the call graph for this function:

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

Returns the default value of this or 0 none exists.

Here is the call graph for this function:

const char * ProgramOptions::Value::desc ( DescType  t) const
protected
Value * ProgramOptions::Value::desc ( DescType  t,
const char *  d 
)
protected

Here is the call graph for this function:

virtual bool ProgramOptions::Value::doParse ( const std::string &  name,
const std::string &  value 
)
protectedpure virtual
Value* ProgramOptions::Value::flag ( )
inline

Marks the value as flag.

See also
bool Value::isFlag() const

Here is the call graph for this function:

bool ProgramOptions::Value::hasProperty ( Property  f) const
inlineprotected
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

Here is the call graph for this function:

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

Returns the implicit value of this or 0 if isImplicit() == false.

Here is the call graph for this function:

bool ProgramOptions::Value::isComposing ( ) const
inline

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

Here is the call graph for this function:

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'.

Here is the call graph for this function:

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'.

Here is the call graph for this function:

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'.

Here is the call graph for this function:

Value* ProgramOptions::Value::level ( DescriptionLevel  lev)
inline

Sets a description level for the corresponding option.

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

DescriptionLevel ProgramOptions::Value::level ( ) const
inline

Returns the description level of the corresponding option.

Value* ProgramOptions::Value::negatable ( )
inline

Here is the call graph for this function:

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

Here is the call graph for this function:

void ProgramOptions::Value::setProperty ( Property  f)
inlineprotected
State ProgramOptions::Value::state ( ) const
inline

Returns the current state of this value.

Value* ProgramOptions::Value::state ( Value::State  s)
inline

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

Here is the call graph for this function:

bool ProgramOptions::Value::state ( bool  b,
State  s 
)
inlineprotected

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