C++ Actor Framework  0.18
Public Types | Public Member Functions | Static Public Member Functions | Related Functions | List of all members
caf::config_value Class Reference

A type for config parameters with similar interface to a variant. More...

#include <config_value.hpp>

Collaboration diagram for caf::config_value:
Collaboration graph

Public Types

using integer = int64_t
 
using boolean = bool
 
using real = double
 
using string = std::string
 
using list = std::vector< config_value >
 
using dictionary = caf::dictionary< config_value >
 
using types = detail::type_list< none_t, integer, boolean, real, timespan, uri, string, list, dictionary >
 
using variant_type = detail::tl_apply_t< types, variant >
 

Public Member Functions

 config_value (config_value &&other)=default
 
 config_value (const config_value &other)=default
 
template<class T , class E = detail::enable_if_t< !std::is_same<detail::decay_t<T>, config_value>::value>>
 config_value (T &&x)
 
config_valueoperator= (config_value &&other)=default
 
config_valueoperator= (const config_value &other)=default
 
template<class T , class E = detail::enable_if_t< !std::is_same<detail::decay_t<T>, config_value>::value>>
config_valueoperator= (T &&x)
 
void convert_to_list ()
 Converts the value to a list with one element (unless the config value holds nullptr). More...
 
list & as_list ()
 Returns the value as a list, converting it to one if needed.
 
dictionaryas_dictionary ()
 Returns the value as a dictionary, converting it to one if needed. More...
 
void append (config_value x)
 Appends x to a list. More...
 
const char * type_name () const noexcept
 Returns a human-readable type name of the current value.
 
variant_type & get_data ()
 Returns the underlying variant.
 
const variant_type & get_data () const
 Returns the underlying variant.
 
variant_type * get_data_ptr ()
 Returns a pointer to the underlying variant.
 
const variant_type * get_data_ptr () const
 Returns a pointer to the underlying variant.
 
 operator bool () const noexcept
 Checks whether this config value is not null.
 
bool operator! () const noexcept
 Checks whether this config value is null.
 
template<class T >
error assign (const T &x)
 

Static Public Member Functions

static expected< config_valueparse (string_view::iterator first, string_view::iterator last)
 Tries to parse a value from given characters.
 
static expected< config_valueparse (string_view str)
 Tries to parse a value from str.
 
template<class Handle >
static optional< messageparse_msg (string_view str, const Handle &)
 Tries to parse a config value (list) from str and to convert it to an allowed input message type for Handle. More...
 
template<class T >
static constexpr string_view mapped_type_name ()
 

Related Functions

(Note that these are not member functions.)

using settings = dictionary< config_value >
 Software options stored as key-value pairs.
 
CAF_CORE_EXPORT std::string to_string (const config_value &x)
 
template<class T >
expected< T > get_as (const config_value &value)
 Converts a config_value to builtin types or user-defined types that opted into the type inspection API.
 
template<class To = get_or_auto_deduce, class Fallback >
auto get_or (const config_value &x, Fallback &&fallback)
 Converts a config_value to To or returns fallback if the conversion fails.
 
CAF_CORE_EXPORT bool operator< (const config_value &x, const config_value &y)
 
CAF_CORE_EXPORT bool operator<= (const config_value &x, const config_value &y)
 
CAF_CORE_EXPORT bool operator== (const config_value &x, const config_value &y)
 
CAF_CORE_EXPORT bool operator> (const config_value &x, const config_value &y)
 
CAF_CORE_EXPORT bool operator>= (const config_value &x, const config_value &y)
 
bool operator!= (const config_value &x, const config_value &y)
 
CAF_CORE_EXPORT std::ostream & operator<< (std::ostream &out, const config_value &x)
 
CAF_CORE_EXPORT std::string to_string (const settings &xs)
 
CAF_CORE_EXPORT const config_valueget_if (const settings *xs, string_view name)
 Tries to retrieve the value associated to name from xs.
 
template<class T >
auto get_if (const settings *xs, string_view name)
 Tries to retrieve the value associated to name from xs.
 
template<class T >
bool holds_alternative (const settings &xs, string_view name)
 Returns whether xs associates a value of type T to name.
 

Detailed Description

A type for config parameters with similar interface to a variant.

This type is not implemented as a simple variant alias because variants cannot contain lists of themselves.

Member Function Documentation

◆ append()

void caf::config_value::append ( config_value  x)

Appends x to a list.

Converts this config value to a list first by calling convert_to_list if needed.

◆ as_dictionary()

dictionary& caf::config_value::as_dictionary ( )

Returns the value as a dictionary, converting it to one if needed.

The only data structure that CAF can convert to a dictionary is a list of lists, where each nested list contains exactly two elements (key and value). In all other cases, the conversion results in an empty dictionary.

◆ convert_to_list()

void caf::config_value::convert_to_list ( )

Converts the value to a list with one element (unless the config value holds nullptr).

Does nothing if the value already is a list.

◆ parse_msg()

template<class Handle >
static optional<message> caf::config_value::parse_msg ( string_view  str,
const Handle &   
)
static

Tries to parse a config value (list) from str and to convert it to an allowed input message type for Handle.

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const config_value x,
const config_value y 
)
related

◆ operator<()

CAF_CORE_EXPORT bool operator< ( const config_value x,
const config_value y 
)
related

◆ operator<<()

CAF_CORE_EXPORT std::ostream & operator<< ( std::ostream &  out,
const config_value x 
)
related

◆ operator<=()

CAF_CORE_EXPORT bool operator<= ( const config_value x,
const config_value y 
)
related

◆ operator==()

CAF_CORE_EXPORT bool operator== ( const config_value x,
const config_value y 
)
related

◆ operator>()

CAF_CORE_EXPORT bool operator> ( const config_value x,
const config_value y 
)
related

◆ operator>=()

CAF_CORE_EXPORT bool operator>= ( const config_value x,
const config_value y 
)
related

◆ to_string() [1/2]

CAF_CORE_EXPORT std::string to_string ( const settings xs)
related

◆ to_string() [2/2]

CAF_CORE_EXPORT std::string to_string ( const config_value x)
related

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