Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
fhicl::OptionalAtom< T > Class Template Reference

#include <type_traits.h>

Inheritance diagram for fhicl::OptionalAtom< T >:
fhicl::detail::AtomBase fhicl::detail::RegisterIfTableMember fhicl::detail::ParameterBase

Public Types

using value_type = T
 

Public Member Functions

 OptionalAtom (Name &&name)
 
 OptionalAtom (Name &&name, Comment &&comment)
 
 OptionalAtom (Name &&name, Comment &&comment, std::function< bool()> maybeUse)
 
std::optional< T > operator() () const
 
bool operator() (T &value) const
 
bool hasValue () const
 
 OptionalAtom ()
 
- Public Member Functions inherited from fhicl::detail::AtomBase
 AtomBase (Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
 
std::string stringified_value () const
 
- Public Member Functions inherited from fhicl::detail::ParameterBase
std::string const & key () const
 
std::string const & name () const
 
std::string const & comment () const
 
bool has_default () const
 
bool is_optional () const
 
bool is_conditional () const
 
par_type parameter_type () const
 
bool should_use () const
 
 ParameterBase (Name const &name, Comment const &comment, par_style const vt, par_type const type, std::function< bool()> maybeUse=AlwaysUse())
 
virtual ~ParameterBase ()=default
 
void set_value (fhicl::ParameterSet const &ps)
 
bool preset_value (fhicl::ParameterSet const &ps)
 
void set_par_style (par_style const vt)
 

Private Member Functions

std::string get_stringified_value () const override
 
void do_set_value (fhicl::ParameterSet const &) override
 
- Private Member Functions inherited from fhicl::detail::RegisterIfTableMember
 RegisterIfTableMember (ParameterBase *pb)
 

Private Attributes

std::optional< T > value_ {}
 

Detailed Description

template<typename T>
class fhicl::OptionalAtom< T >

Definition at line 27 of file type_traits.h.

Member Typedef Documentation

template<typename T>
using fhicl::OptionalAtom< T >::value_type = T

Definition at line 66 of file OptionalAtom.h.

Constructor & Destructor Documentation

template<typename T >
fhicl::OptionalAtom< T >::OptionalAtom ( Name &&  name)
explicit

Definition at line 84 of file OptionalAtom.h.

86  {}
std::string const & name() const
Definition: ParameterBase.h:43
def move(depos, offset)
Definition: depos.py:107
#define Comment
template<typename T >
fhicl::OptionalAtom< T >::OptionalAtom ( Name &&  name,
Comment &&  comment 
)
explicit

Definition at line 89 of file OptionalAtom.h.

94  , RegisterIfTableMember{this}
95  {
97  }
std::string const & name() const
Definition: ParameterBase.h:43
AtomBase(Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
Definition: AtomBase.h:10
std::function< bool()> AlwaysUse()
def move(depos, offset)
Definition: depos.py:107
std::string const & comment() const
Definition: ParameterBase.h:48
template<typename T >
fhicl::OptionalAtom< T >::OptionalAtom ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 100 of file OptionalAtom.h.

106  maybeUse}
107  , RegisterIfTableMember{this}
108  {
110  }
std::string const & name() const
Definition: ParameterBase.h:43
AtomBase(Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
Definition: AtomBase.h:10
def move(depos, offset)
Definition: depos.py:107
std::string const & comment() const
Definition: ParameterBase.h:48
template<typename T>
fhicl::OptionalAtom< T >::OptionalAtom ( )

Member Function Documentation

template<typename T >
void fhicl::OptionalAtom< T >::do_set_value ( fhicl::ParameterSet const &  pset)
overrideprivatevirtual

Implements fhicl::detail::ParameterBase.

Definition at line 129 of file OptionalAtom.h.

130  {
131  auto const trimmed_key = detail::strip_first_containing_name(key());
132  if (auto value = pset.get_if_present<T>(trimmed_key)) {
133  value_ = *value;
134  }
135  }
std::string strip_first_containing_name(std::string const &key)
std::string const & key() const
Definition: ParameterBase.h:38
std::optional< T > value_
Definition: OptionalAtom.h:71
template<typename T >
std::string fhicl::OptionalAtom< T >::get_stringified_value ( ) const
overrideprivatevirtual

Implements fhicl::detail::AtomBase.

Definition at line 114 of file OptionalAtom.h.

115  {
116  std::stringstream oss;
117  if (value_) {
118  using namespace detail::yes_defaults;
119  oss << maybe_quotes<T>(*value_);
120  } else {
121  using namespace detail::no_defaults;
122  oss << expected_types<T>();
123  }
124  return oss.str();
125  }
std::optional< T > value_
Definition: OptionalAtom.h:71
template<typename T>
bool fhicl::OptionalAtom< T >::hasValue ( ) const
inline

Definition at line 60 of file OptionalAtom.h.

61  {
62  return value_.has_value();
63  }
std::optional< T > value_
Definition: OptionalAtom.h:71
template<typename T>
std::optional<T> fhicl::OptionalAtom< T >::operator() ( ) const
inline

Definition at line 43 of file OptionalAtom.h.

44  {
45  return value_;
46  }
std::optional< T > value_
Definition: OptionalAtom.h:71
template<typename T>
bool fhicl::OptionalAtom< T >::operator() ( T &  value) const
inline

Definition at line 50 of file OptionalAtom.h.

51  {
52  if (hasValue()) {
53  value = *value_;
54  return true;
55  }
56  return false;
57  }
bool hasValue() const
Definition: OptionalAtom.h:60
std::optional< T > value_
Definition: OptionalAtom.h:71

Member Data Documentation

template<typename T>
std::optional<T> fhicl::OptionalAtom< T >::value_ {}
private

Definition at line 71 of file OptionalAtom.h.


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