Collaboration diagram for mpqc::KeyVal:

Documentation

KeyVal specifies C++ primitive data (booleans, integers, reals, string) and user-defined objects obtained from JSON/XML/INFO input or by programmatic construction.

KeyVal is a (sub)tree of Key=Value pairs implemented with Boost.PropertyTree. KeyVal extends the standard JSON/XML/INFO syntax to allow references as well as specification of registered C++ objects. See The KeyVal Library for the rationale, examples, and other details.

KeyVal has reference semantics, i.e., copying KeyVal produces a KeyVal that refers to the same PropertyTree object and shares the class registry object with the original KeyVal object.

Since KeyVal is default-constructible and directly mutable, this obsoletes sc::AssignedKeyVal from MPQC v3 and older. Its behavior resembles sc::PrefixKeyVal by combining prefix with a const tree. Hence this version of KeyVal roughly can be viewed as an assignable PrefixKeyVal of MPQC v3 and older, but supporting input from more modern formats like XML and JSON.

Classes

struct  bad_input
 KeyVal exception. More...
 
struct  dummy_validator_t
 
struct  is_nonnegative_t
 
struct  is_positive_t
 

Public Types

enum  InputFormat {
  InputFormat::invalid = -1, InputFormat::json = 0, InputFormat::xml = 1, InputFormat::info = 2,
  InputFormat::first = json, InputFormat::last = info
}
 
using ptree = boost::property_tree::iptree
 data type for representing a property tree More...
 
using key_type = ptree::key_type
 
using value_type = ptree::data_type
 

Public Member Functions

 KeyVal ()
 creates empty KeyVal More...
 
 KeyVal (const KeyVal &other)=default
 copy ctor More...
 
 KeyVal (KeyVal &&other)=default
 move ctor More...
 
virtual ~KeyVal ()=default
 
KeyValoperator= (const KeyVal &other)=default
 copy assignment More...
 
KeyValoperator= (KeyVal &&other)=default
 move assignment More...
 
KeyVal clone () const
 creates a deep copy of this object More...
 
virtual KeyVal keyval (const key_type &path) const
 construct a KeyVal representing a subtree located at the given path More...
 
std::shared_ptr< ptreetop_tree () const
 returns a shared_ptr to the (top) tree More...
 
std::shared_ptr< ptreetree () const
 returns a shared_ptr to this (sub)tree More...
 
template<typename T , typename = std::enable_if_t<Describable<T>::value>>
KeyValset_default_class_key (const std::string &key)
 obtains default class key for class T More...
 
template<typename T >
std::string default_class_key () const
 obtains default class key for class T More...
 
bool exists (const key_type &path) const
 
template<typename Target = const DescribedClass>
bool exists_object (const key_type &path) const noexcept
 
bool exists_class (const key_type &path) const
 
std::optional< size_t > count (const key_type &path) const
 
template<typename T >
std::enable_if_t< not KeyVal::is_sequence_v< T >, KeyVal & > assign (const key_type &path, const T &value) &
 assign simple value at the given path (overwrite, if necessary) More...
 
template<typename T >
std::enable_if_t< not KeyVal::is_sequence_v< T >, KeyValassign (const key_type &path, const T &value) &&
 
template<typename SequenceContainer >
std::enable_if_t< KeyVal::is_sequence_v< SequenceContainer >, KeyVal & > assign (const key_type &path, const SequenceContainer &value, bool json_style=true) &
 Assign a sequence container at the given path (overwrite, if necessary). More...
 
template<typename SequenceContainer >
std::enable_if_t< KeyVal::is_sequence_v< SequenceContainer >, KeyValassign (const key_type &path, const SequenceContainer &value, bool json_style=true) &&
 
template<typename T >
KeyValassign (const key_type &path, std::initializer_list< T > value, bool json_style=true) &
 Assign a sequence container at the given path (overwrite, if necessary). More...
 
template<typename T >
KeyVal assign (const key_type &path, std::initializer_list< T > value, bool json_style=true) &&
 
template<typename T = DescribedClass>
std::enable_if_t< Describable< T >::value, KeyVal & > assign (const key_type &path, const std::shared_ptr< T > &value) &
 
template<typename T = DescribedClass>
std::enable_if_t< Describable< T >::value, KeyValassign (const key_type &path, const std::shared_ptr< T > &value) &&
 
template<typename T = DescribedClass>
std::enable_if_t< Describable< T >::value, const KeyVal & > assign (const key_type &path, const std::shared_ptr< T > &value) const
 
KeyValerase (const key_type &path)
 
const KeyValerase_object (const key_type &path) const
 
const KeyValerase_class (const key_type &path) const
 
template<typename T , typename Validator = dummy_validator_t>
std::enable_if_t< not KeyVal::is_sequence_v< T > &&not utility::meta::can_construct< T, const KeyVal & >::value, T > value (const key_type &path, Validator &&validator=Validator{}, std::enable_if_t< KeyVal::is_valid_validator_v< Validator, T >> *=nullptr) const
 
template<typename T , typename Validator = dummy_validator_t>
std::enable_if_t< not KeyVal::is_sequence_v< T > &&utility::meta::can_construct< T, const KeyVal & >::value, T > value (const key_type &path, Validator &&validator=Validator{}, std::enable_if_t< is_valid_validator_v< Validator, T >> *=nullptr) const
 
template<typename SequenceContainer , typename Validator = dummy_validator_t>
std::enable_if_t< KeyVal::is_mutable_sequence_v< SequenceContainer >, SequenceContainer > value (const key_type &path, Validator &&validator=Validator{}, std::enable_if_t< KeyVal::is_valid_validator_v< Validator, std::decay_t< typename SequenceContainer::value_type >>> *=nullptr) const
 
template<typename SequenceContainer , typename Validator = dummy_validator_t>
std::enable_if_t< KeyVal::is_mutable_sequence_v< SequenceContainer >, SequenceContainer > value (const key_type &path, const key_type &deprecated_path, Validator &&validator=Validator{}, std::enable_if_t< KeyVal::is_valid_validator_v< Validator, std::decay_t< typename SequenceContainer::value_type >>> *=nullptr) const
 
template<typename T , typename Validator = dummy_validator_t>
std::enable_if_t< not KeyVal::is_sequence_v< T >, T > value (const key_type &path, const T &default_value, const key_type &deprecated_path, Validator &&validator=Validator{}, std::enable_if_t< KeyVal::is_valid_validator_v< Validator, T >> *=nullptr) const
 
template<typename T , typename Validator = dummy_validator_t>
std::enable_if_t< not KeyVal::is_sequence_v< T >, T > value (const key_type &path, const T &default_value, Validator &&validator=Validator{}, std::enable_if_t< KeyVal::is_valid_validator_v< Validator, T >> *=nullptr) const
 
template<typename T = DescribedClass, typename Enabler = std::enable_if_t<Describable<T>::value>>
std::shared_ptr< T > object (const key_type &path=key_type(), bool bypass_registry=false, bool disable_bad_input=false) const
 return a pointer to an object at the given path More...
 
template<typename T = DescribedClass, typename = std::enable_if_t<Describable<T>::value>>
std::shared_ptr< T > class_ptr (const key_type &path=key_type(), bool bypass_registry=false, bool disable_bad_input=false) const
 
std::vector< key_typedc_registry_paths () const
 dumps paths of all objects in the DescribedClass object registry More...
 
std::string path () const
 
key_type to_absolute_path (const key_type &path) const
 
bool operator== (const KeyVal &other) const
 
void write_xml (std::basic_ostream< typename key_type::value_type > &os) const
 write to stream in XML form More...
 
void read_xml (std::basic_istream< typename key_type::value_type > &is)
 
void write_json (std::basic_ostream< key_type::value_type > &os) const
 write to stream in JSON form More...
 
void read_json (std::basic_istream< key_type::value_type > &is)
 
void write_info (std::basic_ostream< typename key_type::value_type > &os) const
 write to stream in INFO form More...
 
void read_info (std::basic_istream< typename key_type::value_type > &is)
 

Static Public Member Functions

static bool throw_if_deprecated_path ()
 
static void set_throw_if_deprecated_path (bool f)
 
static key_type concat_path (const key_type &prefix, const key_type &postfix)
 

Static Public Attributes

constexpr static char separator = ':'
 
static constexpr dummy_validator_t dummy_validator {}
 
static const is_nonnegative_t is_nonnegative {}
 
static const is_positive_t is_positive {}
 

Protected Member Functions

virtual boost::optional< const ptree & > get_subtree (const key_type &path) const
 

Member Typedef Documentation

◆ key_type

using mpqc::KeyVal::key_type = ptree::key_type

◆ ptree

using mpqc::KeyVal::ptree = boost::property_tree::iptree

data type for representing a property tree

◆ value_type

using mpqc::KeyVal::value_type = ptree::data_type

Member Enumeration Documentation

◆ InputFormat

the format of the input file, described in Boost.PropertyTree docs.

Enumerator
invalid 
json 
xml 
info 
first 
last 

Constructor & Destructor Documentation

◆ KeyVal() [1/3]

mpqc::KeyVal::KeyVal ( )

creates empty KeyVal

◆ KeyVal() [2/3]

mpqc::KeyVal::KeyVal ( const KeyVal other)
default

copy ctor

Since this class has reference semantics, the underlying data structures (ptree and class registry) are not copied.

Note
to clone top-level tree use KeyVal::clone()

◆ KeyVal() [3/3]

mpqc::KeyVal::KeyVal ( KeyVal &&  other)
default

move ctor

◆ ~KeyVal()

virtual mpqc::KeyVal::~KeyVal ( )
virtualdefault

Member Function Documentation

◆ assign() [1/9]

template<typename SequenceContainer >
std::enable_if_t<KeyVal::is_sequence_v<SequenceContainer>, KeyVal&> mpqc::KeyVal::assign ( const key_type path,
const SequenceContainer &  value,
bool  json_style = true 
) &
inline

Assign a sequence container at the given path (overwrite, if necessary).

Template Parameters
SequenceContainerany container for which KeyVal::is_sequence_v<SequenceContainer> is true, currently any of the following is allowed: std::array, std::vector, std::list , and std::initializer_list. Can be a recursive sequence (unless initializer_list), i.e. sequence of sequence.
Parameters
paththe target path
valuethe sequence to put at the path
json_styleif true, use empty keys so that JSON arrays are produced by KeyVal::write_json, else use 0-based integer keys, e.g. the first element will have key path:0, the second – path:1, etc. (this is similar to how array elements were addressed in MPQC3)

◆ assign() [2/9]

template<typename SequenceContainer >
std::enable_if_t<KeyVal::is_sequence_v<SequenceContainer>, KeyVal> mpqc::KeyVal::assign ( const key_type path,
const SequenceContainer &  value,
bool  json_style = true 
) &&
inline

◆ assign() [3/9]

template<typename T = DescribedClass>
std::enable_if_t<Describable<T>::value, KeyVal&> mpqc::KeyVal::assign ( const key_type path,
const std::shared_ptr< T > &  value 
) &
inline

assign the given pointer to a DescribedClass object at the given path (overwrite, if necessary). This Keyval will keep track of the given object via a weak_ptr (i.e. KeyVal will not own it).

Template Parameters
Ta class directly derived from DescribedClass
Parameters
paththe path to value
valuethe object pointer to assign to path path
Note
redirects to the const version of this function; this (non-const version) is needed to be able to chain with other variants
Warning
these key/value pairs are not part of ptree, hence cannot be written to JSON/XML

◆ assign() [4/9]

template<typename T = DescribedClass>
std::enable_if_t<Describable<T>::value, KeyVal> mpqc::KeyVal::assign ( const key_type path,
const std::shared_ptr< T > &  value 
) &&
inline

◆ assign() [5/9]

template<typename T = DescribedClass>
std::enable_if_t<Describable<T>::value, const KeyVal&> mpqc::KeyVal::assign ( const key_type path,
const std::shared_ptr< T > &  value 
) const
inline

assign the given pointer to a DescribedClass object at the given path (overwrite, if necessary). This Keyval will keep track of the given object via a weak_ptr (i.e. KeyVal will not own it).

Template Parameters
Ta class directly derived from DescribedClass
Parameters
paththe path to value
valuethe object pointer to assign to path path (it is asserted to be nonnull)
Note
this is legitimately const since the registry contents are mutable (see KeyVal::object ).
Warning
these key/value pairs are not part of ptree, hence cannot be written to JSON/XML

◆ assign() [6/9]

template<typename T >
std::enable_if_t<not KeyVal::is_sequence_v<T>, KeyVal&> mpqc::KeyVal::assign ( const key_type path,
const T &  value 
) &
inline

assign simple value at the given path (overwrite, if necessary)

Parameters
valuea "simple" value, i.e. it can be converted to a KeyVal::key_type using a std::basic_ostream<KeyVal::key_type::value_type>

◆ assign() [7/9]

template<typename T >
std::enable_if_t<not KeyVal::is_sequence_v<T>, KeyVal> mpqc::KeyVal::assign ( const key_type path,
const T &  value 
) &&
inline

◆ assign() [8/9]

template<typename T >
KeyVal& mpqc::KeyVal::assign ( const key_type path,
std::initializer_list< T >  value,
bool  json_style = true 
) &
inline

Assign a sequence container at the given path (overwrite, if necessary).

Template Parameters
Tany type
Parameters
paththe target path
valuea sequence to put at the path
json_styleif true, use empty keys so that JSON arrays are produced by KeyVal::write_json, else use 0-based integer keys, e.g. the first element will have key path:0, the second – path:1, etc. (this is similar to how array elements were addressed in MPQC3)

◆ assign() [9/9]

template<typename T >
KeyVal mpqc::KeyVal::assign ( const key_type path,
std::initializer_list< T >  value,
bool  json_style = true 
) &&
inline

◆ class_ptr()

template<typename T = DescribedClass, typename = std::enable_if_t<Describable<T>::value>>
std::shared_ptr<T> mpqc::KeyVal::class_ptr ( const key_type path = key_type(),
bool  bypass_registry = false,
bool  disable_bad_input = false 
) const
inline

◆ clone()

KeyVal mpqc::KeyVal::clone ( ) const

creates a deep copy of this object

Note
the DescribedClass object registry is not copied

◆ concat_path()

static key_type mpqc::KeyVal::concat_path ( const key_type prefix,
const key_type postfix 
)
inlinestatic

Concatenates two paths

Returns
a path obtained by concatenating prefix and postfix ;

◆ count()

std::optional<size_t> mpqc::KeyVal::count ( const key_type path) const
inline

counts the number of children of the node at this path

Parameters
paththe path
Returns
an optional that does not contain a value if path does not exist or it points to a simple keyword, otherwise containing the number of elements (>=0) if path points to an array or a keyword group

◆ dc_registry_paths()

std::vector<key_type> mpqc::KeyVal::dc_registry_paths ( ) const
inline

dumps paths of all objects in the DescribedClass object registry

Returns
vector of absolute paths for the objects in the DescribedClass registry

◆ default_class_key()

template<typename T >
std::string mpqc::KeyVal::default_class_key ( ) const
inline

obtains default class key for class T

Template Parameters
Ta class
Returns
the default class key to assume in KeyVal::object<T>() ; if the default class key has not been specified previously, returns an empty string
See also
set_default_class_key

◆ erase()

KeyVal& mpqc::KeyVal::erase ( const key_type path)
inline

erases entries located under path . This does not touch the DescribedClass object registry (

See also
KeyVal::erase_object ).
Parameters
paththe target path

◆ erase_class()

const KeyVal& mpqc::KeyVal::erase_class ( const key_type path) const
inline

◆ erase_object()

const KeyVal& mpqc::KeyVal::erase_object ( const key_type path) const
inline

erases the entry in the DescribedClass object registry at path . This does not touch the keyword tree (

See also
KeyVal::erase ).
Note
this is const since the registry contents are mutable (see KeyVal::object ).

◆ exists()

bool mpqc::KeyVal::exists ( const key_type path) const
inline

checks whether the given path exists

Parameters
paththe path
Returns
true if path exists

◆ exists_class()

bool mpqc::KeyVal::exists_class ( const key_type path) const
inline

◆ exists_object()

template<typename Target = const DescribedClass>
bool mpqc::KeyVal::exists_object ( const key_type path) const
inlinenoexcept

check whether the given DescribedClass object exists in the registry already.

Template Parameters
Targetif it is not DescribedClass will only return true if the found object can be converted to this type Target
Parameters
paththe path
Returns
true if an object of type Target at path class exists

◆ get_subtree()

virtual boost::optional<const ptree&> mpqc::KeyVal::get_subtree ( const key_type path) const
inlineprotectedvirtual

returns a reference to a subtree located at (absolute or relative) path.

Parameters
paththe path to the subtree

◆ keyval()

virtual KeyVal mpqc::KeyVal::keyval ( const key_type path) const
inlinevirtual

construct a KeyVal representing a subtree located at the given path

Since this class has reference semantics, the result refers to the same underlying data structures (ptree and class registry).

corresponds to the old MPQC's PrefixKeyVal

Parameters
paththe path to the subtree; absolute (within the top_tree) and relative (with respect to this KeyVal's subtree) paths are allowed.
Returns
the KeyVal object corresponding to path ; if path does not exist, return an empty KeyVal

Reimplemented in mpqc::detail::SubTreeKeyVal.

◆ object()

template<typename T = DescribedClass, typename Enabler = std::enable_if_t<Describable<T>::value>>
std::shared_ptr<T> mpqc::KeyVal::object ( const key_type path = key_type(),
bool  bypass_registry = false,
bool  disable_bad_input = false 
) const
inline

return a pointer to an object at the given path

Constructs a smart pointer to object of type T . If user provided keyword "type" in this KeyVal object its value will be used for the object type. Otherwise, if T is a concrete type, this will construct object of type T. In either case, the type of constructed object must have DescribedClass as its public base and registered.

Template Parameters
Ta class derived from DescribedClass
Enablera dummy enabler class; defaults to std::enable_if_t<Describable<T>::value> ; override to force object construction (this is useful to construct objects of classes that do not derive from DescribedClass programmatically), but must set bypass_registry to true
Parameters
paththe path; if not provided, use the empty path
bypass_registryif true will not query the registry for the existence of the object and will not place the newly-constructed object in the registry
disable_bad_inputif true will return a null pointer instead of throwing KeyVal::bad_input
Returns
a std::shared_ptr to T ; null pointer will be returned if path does not exist.
Exceptions
KeyVal::bad_inputUnless disable_bad_input is true, will throw this if any of the following is true:
  • the value of keyword "type" is not a registered class key;
  • the user did not specify keyword "type" and class T is abstract or is not registered.
  • an object has been previosuly constructed, but cannot be cast to T
Note
object<T>("path") is equivalent to keyval("path").object<T>()
the contents of the registry are by definition mutable so that this can be const

◆ operator=() [1/2]

KeyVal& mpqc::KeyVal::operator= ( const KeyVal other)
default

copy assignment

Since this class has reference semantics, the underlying data structures (ptree and class registry) are not copied.

◆ operator=() [2/2]

KeyVal& mpqc::KeyVal::operator= ( KeyVal &&  other)
default

move assignment

◆ operator==()

bool mpqc::KeyVal::operator== ( const KeyVal other) const
inline

comparison operator

Returns
true if this and other point to the same location in the same ptree (+ other impl details are the same)

◆ path()

std::string mpqc::KeyVal::path ( ) const
inline
Returns
the path from the root of top tree to this subtree

◆ read_info()

void mpqc::KeyVal::read_info ( std::basic_istream< typename key_type::value_type > &  is)
inline

read from a std::istream in INFO form

Parameters
[in,out]isa std::istream
Exceptions
KeyVal::bad_inputif failed to parse the contents of is as INFO

◆ read_json()

void mpqc::KeyVal::read_json ( std::basic_istream< key_type::value_type > &  is)
inline

read from a std::istream in JSON form

Parameters
[in,out]isa std::istream
Exceptions
KeyVal::bad_inputif failed to parse the contents of is as JSON

◆ read_xml()

void mpqc::KeyVal::read_xml ( std::basic_istream< typename key_type::value_type > &  is)
inline

read from a std::istream in XML form

Parameters
[in,out]isa std::istream
Exceptions
KeyVal::bad_inputif failed to parse the contents of is as XML

◆ set_default_class_key()

template<typename T , typename = std::enable_if_t<Describable<T>::value>>
KeyVal& mpqc::KeyVal::set_default_class_key ( const std::string &  key)
inline

obtains default class key for class T

Template Parameters
Ta class derived from DescribedClass
Returns
the default class key to assume in KeyVal::object<T>() ; if the default class key has not been specified previously, returns an empty string
See also
set_default_class_key

◆ set_throw_if_deprecated_path()

static void mpqc::KeyVal::set_throw_if_deprecated_path ( bool  f)
inlinestatic

sets the flag controlling whether reading a deprecated path results in an exception

Parameters
fthe new value of the flag

◆ throw_if_deprecated_path()

static bool mpqc::KeyVal::throw_if_deprecated_path ( )
inlinestatic

reads the flag controlling whether reading a deprecated path results in an exception

Returns
a boolean

◆ to_absolute_path()

key_type mpqc::KeyVal::to_absolute_path ( const key_type path) const
inline

computes an absolute path from a given (absolute or relative) path

Parameters
pathan absolute path (starts with "$:") or a relative path (the leading "$" is dropped)
Returns
the absolute path
Note
this does not resolve references
Exceptions
KeyVal::bad_inputif path is invalid; an example is ".." .

◆ top_tree()

std::shared_ptr<ptree> mpqc::KeyVal::top_tree ( ) const
inline

returns a shared_ptr to the (top) tree

◆ tree()

std::shared_ptr< KeyVal::ptree > mpqc::KeyVal::tree ( ) const

returns a shared_ptr to this (sub)tree

Note
the result is aliased against the top tree

◆ value() [1/6]

template<typename SequenceContainer , typename Validator >
std::enable_if_t< KeyVal::is_mutable_sequence_v< SequenceContainer >, SequenceContainer > mpqc::KeyVal::value ( const key_type path,
const key_type deprecated_path,
Validator &&  validator = Validator{},
std::enable_if_t< KeyVal::is_valid_validator_v< Validator, std::decay_t< typename SequenceContainer::value_type >>> *  = nullptr 
) const

find value corresponding to a path and returns it as a SequenceContainer

Template Parameters
SequenceContainerthe desired sequence conatiner type
Validatorthe type of validator
Parameters
paththe path
deprecated_patha deprecated path will only be queried if it's not
validatora callable for which validator(T) returns a boolean. Before returning a value, it will be validated by validator . The default is a dummy validator that always returns true.
Exceptions
KeyVal::bad_inputif path is bad, if validation failed, or if KeyVal::throw_if_deprecated_path returns true and deprecated_path was read.
Returns
value of type SequenceContainer

◆ value() [2/6]

template<typename T , typename Validator = dummy_validator_t>
std::enable_if_t<not KeyVal::is_sequence_v<T>, T> mpqc::KeyVal::value ( const key_type path,
const T &  default_value,
const key_type deprecated_path,
Validator &&  validator = Validator{},
std::enable_if_t< KeyVal::is_valid_validator_v< Validator, T >> *  = nullptr 
) const
inline

return value corresponding to a path and convert to the desired type.

Template Parameters
Tthe desired value type
Validatorthe type of validator
Parameters
paththe path to the value; ignored if empty
default_valuethe default value will be returned if path is not found.
deprecated_patha deprecated path will only be queried if it's not empty and path is empty or not found; if its value is used a message will be added to ExEnv::err0() . The default is an empty string.
validatora callable for which validator(T) returns a boolean. Before returning a value, it will be validated by validator . The default is a dummy validator that always returns true.
Returns
value of type T
Exceptions
KeyVal::bad_inputif validation failed, or if KeyVal::throw_if_deprecated_path returns true and deprecated_path was read.

◆ value() [3/6]

template<typename T , typename Validator = dummy_validator_t>
std::enable_if_t<not KeyVal::is_sequence_v<T>, T> mpqc::KeyVal::value ( const key_type path,
const T &  default_value,
Validator &&  validator = Validator{},
std::enable_if_t< KeyVal::is_valid_validator_v< Validator, T >> *  = nullptr 
) const
inline

return value corresponding to a path and convert to the desired type.

Template Parameters
Tthe desired value type
Validatorthe type of validator
Parameters
paththe path to the value
default_valuethe default value will be returned if path is not found.
validatora callable for which validator(T) returns a boolean. Before returning a value, it will be validated by validator . The default is a dummy validator that always returns true.
Returns
value of type T
Exceptions
KeyVal::bad_inputif validation failed.

◆ value() [4/6]

template<typename T , typename Validator >
std::enable_if_t< not KeyVal::is_sequence_v< T > &&utility::meta::can_construct< T, const KeyVal & >::value, T > mpqc::KeyVal::value ( const key_type path,
Validator &&  validator = Validator{},
std::enable_if_t< is_valid_validator_v< Validator, T >> *  = nullptr 
) const

return the result of converting the value at the given path to the desired type.

Template Parameters
Tthe desired value type, must be a "simple" type that can be accepted by KeyVal::assign()
Validatorthe type of validator
Parameters
paththe path to the value
validatora callable for which validator(T) returns a boolean. Before returning a value, it will be validated by validator . The default is a dummy validator that always returns true.
Returns
value stored at path converted to type T
Exceptions
KeyVal::bad_inputif path not found or cannot convert value
KeyVal::bad_inputif validation failed. representation to the desired type

◆ value() [5/6]

template<typename SequenceContainer , typename Validator >
std::enable_if_t< KeyVal::is_mutable_sequence_v< SequenceContainer >, SequenceContainer > mpqc::KeyVal::value ( const key_type path,
Validator &&  validator = Validator{},
std::enable_if_t< KeyVal::is_valid_validator_v< Validator, std::decay_t< typename SequenceContainer::value_type >>> *  = nullptr 
) const

find value corresponding to a path and returns it as a SequenceContainer

Template Parameters
SequenceContainerthe desired sequence conatiner type
Validatorthe type of validator
Parameters
paththe path
validatora callable for which validator(T) returns a boolean. Before returning a value, it will be validated by validator . The default is a dummy validator that always returns true.
Exceptions
KeyVal::bad_inputif path is bad, or if validation failed.
Returns
value of type T

◆ value() [6/6]

template<typename T , typename Validator = dummy_validator_t>
std::enable_if_t< not KeyVal::is_sequence_v<T> && not utility::meta::can_construct<T, const KeyVal&>::value, T> mpqc::KeyVal::value ( const key_type path,
Validator &&  validator = Validator{},
std::enable_if_t< KeyVal::is_valid_validator_v< Validator, T >> *  = nullptr 
) const
inline

return the result of converting the value at the given path to the desired type.

Template Parameters
Tthe desired value type, must be a "simple" type that can be accepted by KeyVal::assign()
Validatorthe type of validator
Parameters
paththe path to the value
validatora callable for which validator(T) returns a boolean. Before returning a value, it will be validated by validator . The default is a dummy validator that always returns true.
Returns
value stored at path converted to type T
Exceptions
KeyVal::bad_inputif path not found or cannot convert value representation to the desired type
KeyVal::bad_inputif validation failed.

◆ write_info()

void mpqc::KeyVal::write_info ( std::basic_ostream< typename key_type::value_type > &  os) const
inline

write to stream in INFO form

◆ write_json()

void mpqc::KeyVal::write_json ( std::basic_ostream< key_type::value_type > &  os) const
inline

write to stream in JSON form

◆ write_xml()

void mpqc::KeyVal::write_xml ( std::basic_ostream< typename key_type::value_type > &  os) const
inline

write to stream in XML form

read/write KeyVal specified in one of accepted Boost.PropertyTree formats (see Boost.PropertyTree docs)

Member Data Documentation

◆ dummy_validator

constexpr dummy_validator_t mpqc::KeyVal::dummy_validator {}
staticconstexpr

◆ is_nonnegative

const KeyVal::is_nonnegative_t mpqc::KeyVal::is_nonnegative {}
static

◆ is_positive

const KeyVal::is_positive_t mpqc::KeyVal::is_positive {}
static

◆ separator

constexpr static char mpqc::KeyVal::separator = ':'
staticconstexpr

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