LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 ()
 
std::string stringified_value () const
 
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
 
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 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.

References fhicl::detail::ParameterBase::name().

85  : OptionalAtom{std::move(name), Comment("")}
86  {}
std::string const & name() const
template<typename T >
fhicl::OptionalAtom< T >::OptionalAtom ( Name &&  name,
Comment &&  comment 
)
explicit

Definition at line 89 of file OptionalAtom.h.

References fhicl::detail::AlwaysUse(), fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), fhicl::OPTIONAL, and fhicl::detail::RegisterIfTableMember::RegisterIfTableMember().

90  : AtomBase{std::move(name),
91  std::move(comment),
94  , RegisterIfTableMember{this}
95  {
97  }
AtomBase(Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
Definition: AtomBase.h:10
std::function< bool()> AlwaysUse()
std::string const & name() const
std::string const & comment() const
template<typename T >
fhicl::OptionalAtom< T >::OptionalAtom ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 100 of file OptionalAtom.h.

References fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), fhicl::OPTIONAL_CONDITIONAL, and fhicl::detail::RegisterIfTableMember::RegisterIfTableMember().

103  : AtomBase{std::move(name),
104  std::move(comment),
106  maybeUse}
107  , RegisterIfTableMember{this}
108  {
110  }
AtomBase(Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
Definition: AtomBase.h:10
std::string const & name() const
std::string const & comment() const
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.

References fhicl::ParameterSet::get_if_present(), fhicl::detail::ParameterBase::key(), fhicl::detail::strip_first_containing_name(), value, and fhicl::OptionalAtom< T >::value_.

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.cc:6
double value
Definition: spectrum.C:18
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.

References fhicl::OptionalAtom< T >::value_.

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.

Referenced by fhicl::OptionalAtom< RunNumber_t >::operator()().

61  {
62  return value_.has_value();
63  }
std::optional< T > value_
Definition: OptionalAtom.h:71
bool fhicl::detail::ParameterBase::is_conditional ( ) const
inherited
std::string const & fhicl::detail::ParameterBase::key ( ) const
inherited

Definition at line 6 of file ParameterBase.cc.

References fhicl::detail::ParameterMetadata::key(), and fhicl::detail::ParameterBase::mdata_.

Referenced by fhicl::detail::PrintAllowedConfiguration::after_action(), fhicl::detail::ValidateThenSet::before_action(), fhicl::detail::PrintAllowedConfiguration::before_action(), fhicl::detail::SearchAllowedConfiguration::before_action(), fhicl::detail::PrintAllowedConfiguration::cacheTopLevelParameter(), detinfo::LArPropertiesStandard::Configure(), fhicl::OptionalTuple< ARGS... >::do_prepare_elements_for_validation(), fhicl::OptionalSequence< art::InputTag >::do_prepare_elements_for_validation(), fhicl::OptionalSequence< T,-1ull >::do_prepare_elements_for_validation(), fhicl::OptionalSequence< T, N >::do_preset_value(), fhicl::OptionalSequence< T,-1ull >::do_preset_value(), fhicl::Atom< T >::do_set_value(), fhicl::OptionalAtom< T >::do_set_value(), fhicl::detail::ValidateThenSet::enter_sequence(), fhicl::detail::PrintAllowedConfiguration::enter_sequence(), fhicl::detail::SearchAllowedConfiguration::form_absolute(), fhicl::DelegatedParameter::get(), fhicl::OptionalDelegatedParameter::get_if_present(), fhicl::OptionalDelegatedParameter::hasValue(), fhicl::detail::MaybeDisplayParent::is_sequence_element(), fhicl::detail::TableBase::maybe_select_pset(), fhicl::detail::PrintAllowedConfiguration::maybeReleaseTopLevelParameter(), fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::detail::TableBase::select_pset(), and fhicl::detail::PrintAllowedConfiguration::suppressFormat().

7  {
8  return mdata_.key();
9  }
ParameterMetadata mdata_
Definition: ParameterBase.h:63
std::string const & key() const
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  }
double value
Definition: spectrum.C:18
bool hasValue() const
Definition: OptionalAtom.h:60
std::optional< T > value_
Definition: OptionalAtom.h:71
bool fhicl::detail::ParameterBase::preset_value ( fhicl::ParameterSet const &  ps)
inherited

Definition at line 63 of file ParameterBase.cc.

References fhicl::detail::ParameterBase::do_preset_value().

Referenced by fhicl::detail::ValidateThenSet::before_action().

64  {
65  return do_preset_value(ps);
66  }
virtual bool do_preset_value(fhicl::ParameterSet const &)
void fhicl::detail::ParameterBase::set_par_style ( par_style const  vt)
inherited
void fhicl::detail::ParameterBase::set_value ( fhicl::ParameterSet const &  ps)
inherited

Definition at line 58 of file ParameterBase.cc.

References fhicl::detail::ParameterBase::do_set_value().

Referenced by fhicl::detail::ValidateThenSet::after_action().

59  {
60  do_set_value(ps);
61  }
virtual void do_set_value(fhicl::ParameterSet const &)=0
bool fhicl::detail::ParameterBase::should_use ( ) const
inherited

Definition at line 41 of file ParameterBase.cc.

References fhicl::detail::ParameterBase::maybeUse_.

Referenced by fhicl::detail::ValidateThenSet::before_action().

42  {
43  return maybeUse_();
44  }
std::function< bool()> maybeUse_
Definition: ParameterBase.h:64
std::string fhicl::detail::AtomBase::stringified_value ( ) const
inlineinherited

Definition at line 18 of file AtomBase.h.

References fhicl::detail::AtomBase::get_stringified_value().

Referenced by fhicl::detail::PrintAllowedConfiguration::atom().

19  {
20  return get_stringified_value();
21  }
virtual std::string get_stringified_value() const =0

Member Data Documentation


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