Loading [MathJax]/extensions/tex2jax.js
 Version: SMASH-3.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
smash::Key< default_type >::Default< T > Class Template Reference

template<typename default_type>
template<typename T>
class smash::Key< default_type >::Default< T >

Wrapper class around a type with the capability to both store the type of default and its value, if any exists.

This class has 3 valid states:

State type_ value_
Required key DefaultType::Null std::nullopt
Default value DefaultType::Value std::nullopt
Key with dependent default DefaultType::Dependent std::nullopt

There is a constructor for each of the cases above.

Template Parameters
TThe default value type.
Note
This is an implementation detail of the Key class and it is meant to be rigid in its usage. E.g., the constructor specifying a DefaultType is meant to only accept DefaultType::Dependent because this is the only way we want it to be used.

Definition at line 321 of file key.h.

Public Member Functions

 Default ()
 Construct a new Default object which denotes a mandatory value without a default. More...
 
 Default (T in)
 Construct a new Default object storing its default value. More...
 
 Default (DefaultType type)
 Construct a new Default object which has a value dependent on external information. More...
 
value () const
 Retrieve the default value stored in the object. More...
 
bool is_dependent () const noexcept
 Ask whether the default value depends on other external information. More...
 

Private Attributes

DefaultType type_ = DefaultType::Value
 The type of default value. More...
 
std::optional< T > value_ = std::nullopt
 The default value, if any. More...
 

Friends

class Key< T >
 

Constructor & Destructor Documentation

◆ Default() [1/3]

template<typename default_type >
template<typename T >
smash::Key< default_type >::Default< T >::Default ( )
inline

Construct a new Default object which denotes a mandatory value without a default.

This is meant to be used for required keys.

Definition at line 327 of file key.h.

DefaultType type_
The type of default value.
Definition: key.h:372
@ Null
Default "type" for mandatory keys

◆ Default() [2/3]

template<typename default_type >
template<typename T >
smash::Key< default_type >::Default< T >::Default ( in)
inlineexplicit

Construct a new Default object storing its default value.

Parameters
inThe default value to be stored

Definition at line 333 of file key.h.

333 : value_{std::move(in)} {}
std::optional< T > value_
The default value, if any.
Definition: key.h:374

◆ Default() [3/3]

template<typename default_type >
template<typename T >
smash::Key< default_type >::Default< T >::Default ( DefaultType  type)
inlineexplicit

Construct a new Default object which has a value dependent on external information.

Parameters
typeThe type of default (it should be DefaultType::Dependent ).
Exceptions
std::logic_errorif called with a type different from DefaultType::Dependent .

Definition at line 344 of file key.h.

344  : type_{type} {
345  if (type != DefaultType::Dependent) {
346  throw std::logic_error("Default constructor used with invalid type!");
347  }
348  }
default_type type
Let the clients of this class have access to the key type.
Definition: key.h:168
@ Dependent
Default value which depends on other keys

Member Function Documentation

◆ value()

template<typename default_type >
template<typename T >
T smash::Key< default_type >::Default< T >::value ( ) const
inline

Retrieve the default value stored in the object.

Returns
The default value stored
Exceptions
std::bad_optional_accessIf the object stores no default value.

Definition at line 357 of file key.h.

357 { return value_.value(); }

◆ is_dependent()

template<typename default_type >
template<typename T >
bool smash::Key< default_type >::Default< T >::is_dependent ( ) const
inlinenoexcept

Ask whether the default value depends on other external information.

Returns
true if this is the case,
false if the default value is known or none exists.

Definition at line 366 of file key.h.

366  {
367  return type_ == DefaultType::Dependent;
368  }

Friends And Related Function Documentation

◆ Key< T >

template<typename default_type >
template<typename T >
friend class Key< T >
friend

Definition at line 374 of file key.h.

Member Data Documentation

◆ type_

template<typename default_type >
template<typename T >
DefaultType smash::Key< default_type >::Default< T >::type_ = DefaultType::Value
private

The type of default value.

Definition at line 372 of file key.h.

◆ value_

template<typename default_type >
template<typename T >
std::optional<T> smash::Key< default_type >::Default< T >::value_ = std::nullopt
private

The default value, if any.

Definition at line 374 of file key.h.


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