Github   Telegram
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
yaml_config::YamlConfig Class Reference

Datatype that represents YAML with substituted variables. More...

#include <userver/yaml_config/yaml_config.hpp>

+ Inheritance diagram for yaml_config::YamlConfig:

Classes

struct  DefaultConstructed
 
struct  IterTraits
 

Public Types

using const_iterator = Iterator< IterTraits >
 
using Exception = yaml_config::Exception
 
using ParseException = yaml_config::ParseException
 

Public Member Functions

 YamlConfig (formats::yaml::Value yaml, formats::yaml::Value config_vars)
 YamlConfig = config + config_vars.
 
const formats::yaml::ValueYaml () const
 Get the plain Yaml without substitutions. It may contain raw references.
 
YamlConfig operator[] (std::string_view key) const
 Access member by key for read. More...
 
YamlConfig operator[] (size_t index) const
 Access member by index for read. More...
 
std::size_t GetSize () const
 Returns array size or object members count. More...
 
bool IsMissing () const
 Returns true if *this holds nothing. When IsMissing() returns true any attempt to get the actual value or iterate over *this will throw MemberMissingException.
 
bool IsNull () const
 Returns true if *this holds 'null'.
 
bool IsInt64 () const
 Returns true if *this is convertible to int64_t. More...
 
bool IsUInt64 () const
 Returns true if *this is convertible to uint64_t. More...
 
void CheckArrayOrNull () const
 
void CheckObjectOrNull () const
 
template<typename T >
As () const
 Returns value of *this converted to T. More...
 
template<typename T , typename First , typename... Rest>
As (First &&default_arg, Rest &&... more_default_args) const
 Returns value of *this converted to T or T(args) if this->IsMissing(). More...
 
template<typename T >
As (DefaultConstructed) const
 Returns value of *this converted to T or T() if this->IsMissing(). More...
 
bool HasMember (std::string_view key) const
 Returns true if *this holds a key. More...
 
std::string GetPath () const
 Returns full path to this value.
 
const_iterator begin () const
 Returns an iterator to the beginning of the held array or map. More...
 
const_iterator end () const
 Returns an iterator to the end of the held array or map. More...
 
template<>
bool As () const
 
template<>
int64_t As () const
 
template<>
uint64_t As () const
 
template<>
double As () const
 

Detailed Description

Datatype that represents YAML with substituted variables.

Definition at line 29 of file yaml_config.hpp.

Member Typedef Documentation

◆ const_iterator

Definition at line 38 of file yaml_config.hpp.

◆ Exception

Definition at line 39 of file yaml_config.hpp.

◆ ParseException

Definition at line 40 of file yaml_config.hpp.

Member Function Documentation

◆ As() [1/3]

template<typename T >
T yaml_config::YamlConfig::As

Returns value of *this converted to T.

Exceptions
Anythingderived from std::exception.
Examples
components/component_sample_test.cpp, and samples/grpc_service/grpc_service.cpp.

Definition at line 124 of file yaml_config.hpp.

◆ As() [2/3]

template<typename T >
T yaml_config::YamlConfig::As ( YamlConfig::DefaultConstructed  ) const

Returns value of *this converted to T or T() if this->IsMissing().

Exceptions
Anythingderived from std::exception.
Note
Use as value.As<T>({})

Definition at line 162 of file yaml_config.hpp.

◆ As() [3/3]

template<typename T , typename First , typename... Rest>
T yaml_config::YamlConfig::As ( First &&  default_arg,
Rest &&...  more_default_args 
) const

Returns value of *this converted to T or T(args) if this->IsMissing().

Exceptions
Anythingderived from std::exception.

Definition at line 151 of file yaml_config.hpp.

◆ begin()

const_iterator yaml_config::YamlConfig::begin ( ) const

Returns an iterator to the beginning of the held array or map.

Exceptions
TypeMismatchExceptionis the value of *this is not a map, array or Null.

◆ CheckArrayOrNull()

void yaml_config::YamlConfig::CheckArrayOrNull ( ) const
Exceptions
MemberMissingExceptionif *this is not an array or Null.

◆ CheckObjectOrNull()

void yaml_config::YamlConfig::CheckObjectOrNull ( ) const
Exceptions
TypeMismatchExceptionif *this is not a map or Null.

◆ end()

const_iterator yaml_config::YamlConfig::end ( ) const

Returns an iterator to the end of the held array or map.

Exceptions
TypeMismatchExceptionis the value of *this is not a map, array or Null.

◆ GetSize()

std::size_t yaml_config::YamlConfig::GetSize ( ) const

Returns array size or object members count.

Exceptions
TypeMismatchExceptionif not array or object value.

◆ HasMember()

bool yaml_config::YamlConfig::HasMember ( std::string_view  key) const

Returns true if *this holds a key.

Exceptions
Nothing.

◆ IsInt64()

bool yaml_config::YamlConfig::IsInt64 ( ) const

Returns true if *this is convertible to int64_t.

Exceptions
Nothing.

◆ IsUInt64()

bool yaml_config::YamlConfig::IsUInt64 ( ) const

Returns true if *this is convertible to uint64_t.

Exceptions
Nothing.

◆ operator[]() [1/2]

YamlConfig yaml_config::YamlConfig::operator[] ( size_t  index) const

Access member by index for read.

Exceptions
TypeMismatchExceptionif value is not missing and is not array.

◆ operator[]() [2/2]

YamlConfig yaml_config::YamlConfig::operator[] ( std::string_view  key) const

Access member by key for read.

Exceptions
TypeMismatchExceptionif value is not missing and is not object.

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