userver: components::ComponentConfig Class Reference
Loading...
Searching...
No Matches
components::ComponentConfig Class Referencefinal

Detailed Description

+ Inheritance diagram for components::ComponentConfig:

Public Types

enum class  Mode {
  kSecure ,
  kEnvAllowed ,
  kEnvAndFileAllowed
}
 
using const_iterator = Iterator<IterTraits>
 
using Exception = yaml_config::Exception
 
using ParseException = yaml_config::ParseException
 

Public Member Functions

 ComponentConfig (std::string name)
 Creates an empty config.
 
 ComponentConfig (yaml_config::YamlConfig value)
 
const std::string & Name () const
 
void SetName (std::string name)
 
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.
 
YamlConfig operator[] (size_t index) const
 Access member by index for read.
 
std::size_t GetSize () const
 Returns array size or object members count.
 
bool IsMissing () const noexcept
 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 noexcept
 Returns true if *this holds 'null'.
 
bool IsBool () const noexcept
 Returns true if *this is convertible to bool.
 
bool IsInt () const noexcept
 Returns true if *this is convertible to int.
 
bool IsInt64 () const noexcept
 Returns true if *this is convertible to int64_t.
 
bool IsUInt64 () const noexcept
 Returns true if *this is convertible to uint64_t.
 
bool IsDouble () const noexcept
 Returns true if *this is convertible to double.
 
bool IsString () const noexcept
 Returns true if *this is convertible to std::string.
 
bool IsArray () const noexcept
 Returns true if *this is an array (Type::kArray).
 
bool IsObject () const noexcept
 Returns true if *this is a map (Type::kObject).
 
void CheckNotMissing () const
 
void CheckArray () const
 
void CheckArrayOrNull () const
 
void CheckObjectOrNull () const
 
void CheckObject () const
 
void CheckString () const
 
void CheckObjectOrArrayOrNull () const
 
template<typename T >
auto As () const
 Returns value of *this converted to T.
 
template<typename T , typename First , typename... Rest>
auto As (First &&default_arg, Rest &&... more_default_args) const
 Returns value of *this converted to T or T(args) if this->IsMissing().
 
template<typename T >
auto As (DefaultConstructed) const
 Returns value of *this converted to T or T() if this->IsMissing().
 
bool HasMember (std::string_view key) const
 Returns true if *this holds a key.
 
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.
 
const_iterator end () const
 Returns an iterator to the end of the held array or map.
 

Member Typedef Documentation

◆ const_iterator

Definition at line 88 of file yaml_config.hpp.

◆ Exception

Definition at line 89 of file yaml_config.hpp.

◆ ParseException

Member Enumeration Documentation

◆ Mode

enum class yaml_config::YamlConfig::Mode
stronginherited
Enumerator
kEnvAllowed 

< secure mode, without reading environment variables or files

kEnvAndFileAllowed 

< allows reading of environment variables

Definition at line 81 of file yaml_config.hpp.

Member Function Documentation

◆ As() [1/3]

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

Returns value of *this converted to T.

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

Definition at line 216 of file yaml_config.hpp.

◆ As() [2/3]

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

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 250 of file yaml_config.hpp.

◆ As() [3/3]

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

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

Exceptions
Anythingderived from std::exception.

Definition at line 239 of file yaml_config.hpp.

◆ begin()

const_iterator yaml_config::YamlConfig::begin ( ) const
inherited

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.

◆ CheckArray()

void yaml_config::YamlConfig::CheckArray ( ) const
inherited
Exceptions
MemberMissingExceptionif *this is not an array.

◆ CheckArrayOrNull()

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

◆ CheckNotMissing()

void yaml_config::YamlConfig::CheckNotMissing ( ) const
inherited
Exceptions
MemberMissingExceptionif this->IsMissing().

◆ CheckObject()

void yaml_config::YamlConfig::CheckObject ( ) const
inherited
Exceptions
TypeMismatchExceptionif *this is not a map.

◆ CheckObjectOrArrayOrNull()

void yaml_config::YamlConfig::CheckObjectOrArrayOrNull ( ) const
inherited
Exceptions
TypeMismatchExceptionif *this is not a map, array or Null.

◆ CheckObjectOrNull()

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

◆ CheckString()

void yaml_config::YamlConfig::CheckString ( ) const
inherited
Exceptions
TypeMismatchExceptionif *this is not convertible to std::string.

◆ end()

const_iterator yaml_config::YamlConfig::end ( ) const
inherited

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
inherited

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
inherited

Returns true if *this holds a key.

Exceptions
Nothing.

◆ operator[]() [1/2]

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

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
inherited

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: