hpx/program_options/value_semantic.hpp

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace program_options

Functions

template<class T>
typed_value<T> *value()

Creates a typed_value<T> instance. This function is the primary method to create value_semantic instance for a specific type, which can later be passed to ‘option_description’ constructor. The second overload is used when it’s additionally desired to store the value of option into program variable.

template<class T>
typed_value<T> *value(T *v)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
typed_value<T, wchar_t> *wvalue()

Creates a typed_value<T> instance. This function is the primary method to create value_semantic instance for a specific type, which can later be passed to ‘option_description’ constructor.

template<class T>
typed_value<T, wchar_t> *wvalue(T *v)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

typed_value<bool> *bool_switch()

Works the same way as the ‘value<bool>’ function, but the created value_semantic won’t accept any explicit value. So, if the option is present on the command line, the value will be ‘true’.

typed_value<bool> *bool_switch(bool *v)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T, class Char = char>
class typed_value : public hpx::program_options::value_semantic_codecvt_helper<char>, public hpx::program_options::typed_value_base
#include <value_semantic.hpp>

Class which handles value of a specific type.

Public Functions

typed_value(T *store_to)

Ctor. The ‘store_to’ parameter tells where to store the value when it’s known. The parameter can be NULL.

typed_value *default_value(const T &v)

Specifies default value, which will be used if none is explicitly specified. The type ‘T’ should provide operator<< for ostream.

typed_value *default_value(const T &v, const std::string &textual)

Specifies default value, which will be used if none is explicitly specified. Unlike the above overload, the type ‘T’ need not provide operator<< for ostream, but textual representation of default value must be provided by the user.

typed_value *implicit_value(const T &v)

Specifies an implicit value, which will be used if the option is given, but without an adjacent value. Using this implies that an explicit value is optional,

typed_value *value_name(const std::string &name)

Specifies the name used to to the value in help message.

typed_value *implicit_value(const T &v, const std::string &textual)

Specifies an implicit value, which will be used if the option is given, but without an adjacent value. Using this implies that an explicit value is optional, but if given, must be strictly adjacent to the option, i.e.: ‘-ovalue’ or ‘option=value’. Giving ‘-o’ or ‘option’ will cause the implicit value to be applied. Unlike the above overload, the type ‘T’ need not provide operator<< for ostream, but textual representation of default value must be provided by the user.

typed_value *notifier(std::function<void(const T&)> f)

Specifies a function to be called when the final value is determined.

typed_value *composing()

Specifies that the value is composing. See the ‘is_composing’ method for explanation.

typed_value *multitoken()

Specifies that the value can span multiple tokens.

typed_value *zero_tokens()

Specifies that no tokens may be provided as the value of this option, which means that only presence of the option is significant. For such option to be useful, either the ‘validate’ function should be specialized, or the ‘implicit_value’ method should be also used. In most cases, you can use the ‘bool_switch’ function instead of using this method.

typed_value *required()

Specifies that the value must occur.

std::string name() const

Returns the name of the option. The name is only meaningful for automatic help message.

bool is_composing() const

Returns true if values from different sources should be composed. Otherwise, value from the first source is used and values from other sources are discarded.

unsigned min_tokens() const

The minimum number of tokens for this option that should be present on the command line.

unsigned max_tokens() const

The maximum number of tokens for this option that should be present on the command line.

bool is_required() const

Returns true if value must be given. Non-optional value

void xparse(hpx::any_nonser &value_store, const std::vector<std::basic_string<Char>> &new_tokens) const

Creates an instance of the ‘validator’ class and calls its operator() to perform the actual conversion.

virtual bool apply_default(hpx::any_nonser &value_store) const

If default value was specified via previous call to ‘default_value’, stores that value into ‘value_store’. Returns true if default value was stored.

void notify(const hpx::any_nonser &value_store) const

If an address of variable to store value was specified when creating *this, stores the value there. Otherwise, does nothing.

const std::type_info &value_type() const

Private Members

T *m_store_to
std::string m_value_name
hpx::any_nonser m_default_value
std::string m_default_value_as_text
hpx::any_nonser m_implicit_value
std::string m_implicit_value_as_text
bool m_composing
bool m_implicit
bool m_multitoken
bool m_zero_tokens
bool m_required
std::function<void(const T&)> m_notifier
class typed_value_base
#include <value_semantic.hpp>

Base class for all option that have a fixed type, and are willing to announce this type to the outside world. Any ‘value_semantics’ for which you want to find out the type can be dynamic_cast-ed to typed_value_base. If conversion succeeds, the ‘type’ method can be called.

Subclassed by hpx::program_options::typed_value< T, Char >

Public Functions

virtual const std::type_info &value_type() const = 0
virtual ~typed_value_base()
class untyped_value : public hpx::program_options::value_semantic_codecvt_helper<char>
#include <value_semantic.hpp>

Class which specifies a simple handling of a value: the value will have string type and only one token is allowed.

Public Functions

untyped_value(bool zero_tokens = false)
std::string name() const

Returns the name of the option. The name is only meaningful for automatic help message.

unsigned min_tokens() const

The minimum number of tokens for this option that should be present on the command line.

unsigned max_tokens() const

The maximum number of tokens for this option that should be present on the command line.

bool is_composing() const

Returns true if values from different sources should be composed. Otherwise, value from the first source is used and values from other sources are discarded.

bool is_required() const

Returns true if value must be given. Non-optional value

void xparse(hpx::any_nonser &value_store, const std::vector<std::string> &new_tokens) const

If ‘value_store’ is already initialized, or new_tokens has more than one elements, throws. Otherwise, assigns the first string from ‘new_tokens’ to ‘value_store’, without any modifications.

bool apply_default(hpx::any_nonser&) const

Does nothing.

void notify(const hpx::any_nonser&) const

Does nothing.

Private Members

bool m_zero_tokens
class value_semantic
#include <value_semantic.hpp>

Class which specifies how the option’s value is to be parsed and converted into C++ types.

Subclassed by hpx::program_options::value_semantic_codecvt_helper< char >, hpx::program_options::value_semantic_codecvt_helper< wchar_t >

Public Functions

virtual std::string name() const = 0

Returns the name of the option. The name is only meaningful for automatic help message.

virtual unsigned min_tokens() const = 0

The minimum number of tokens for this option that should be present on the command line.

virtual unsigned max_tokens() const = 0

The maximum number of tokens for this option that should be present on the command line.

virtual bool is_composing() const = 0

Returns true if values from different sources should be composed. Otherwise, value from the first source is used and values from other sources are discarded.

virtual bool is_required() const = 0

Returns true if value must be given. Non-optional value

virtual void parse(hpx::any_nonser &value_store, const std::vector<std::string> &new_tokens, bool utf8) const = 0

Parses a group of tokens that specify a value of option. Stores the result in ‘value_store’, using whatever representation is desired. May be be called several times if value of the same option is specified more than once.

virtual bool apply_default(hpx::any_nonser &value_store) const = 0

Called to assign default value to ‘value_store’. Returns true if default value is assigned, and false if no default value exists.

virtual void notify(const hpx::any_nonser &value_store) const = 0

Called when final value of an option is determined.

virtual ~value_semantic()
template<class Char>
class value_semantic_codecvt_helper
#include <value_semantic.hpp>

Helper class which perform necessary character conversions in the ‘parse’ method and forwards the data further.

template<>
class value_semantic_codecvt_helper<char> : public hpx::program_options::value_semantic
#include <value_semantic.hpp>

Helper conversion class for values that accept ascii strings as input. Overrides the ‘parse’ method and defines new ‘xparse’ method taking std::string. Depending on whether input to parse is ascii or UTF8, will pass it to xparse unmodified, or with UTF8->ascii conversion.

Subclassed by hpx::program_options::typed_value< T, Char >, hpx::program_options::untyped_value

Protected Functions

virtual void xparse(hpx::any_nonser &value_store, const std::vector<std::string> &new_tokens) const = 0

Private Functions

void parse(hpx::any_nonser &value_store, const std::vector<std::string> &new_tokens, bool utf8) const

Parses a group of tokens that specify a value of option. Stores the result in ‘value_store’, using whatever representation is desired. May be be called several times if value of the same option is specified more than once.

template<>
class value_semantic_codecvt_helper<wchar_t> : public hpx::program_options::value_semantic
#include <value_semantic.hpp>

Helper conversion class for values that accept ascii strings as input. Overrides the ‘parse’ method and defines new ‘xparse’ method taking std::wstring. Depending on whether input to parse is ascii or UTF8, will recode input to Unicode, or pass it unmodified.

Protected Functions

virtual void xparse(hpx::any_nonser &value_store, const std::vector<std::wstring> &new_tokens) const = 0

Private Functions

void parse(hpx::any_nonser &value_store, const std::vector<std::string> &new_tokens, bool utf8) const

Parses a group of tokens that specify a value of option. Stores the result in ‘value_store’, using whatever representation is desired. May be be called several times if value of the same option is specified more than once.