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

#include <type_traits.h>

Inheritance diagram for fhicl::OptionalTable< T >:
fhicl::detail::TableBase fhicl::detail::RegisterIfTableMember fhicl::detail::ParameterBase

Public Types

using value_type = T
 

Public Member Functions

 OptionalTable (Name &&name)
 
 OptionalTable (Name &&name, Comment &&comment)
 
 OptionalTable (Name &&name, Comment &&comment, std::function< bool()> maybeUse)
 
 OptionalTable (ParameterSet const &pset, std::set< std::string > const &keysToIgnore)
 
std::optional< T > operator() () const
 
bool operator() (T &value) const
 
bool hasValue () const
 
ParameterSet const & get_PSet () const
 
void print_allowed_configuration (std::ostream &os, std::string const &tab=std::string(3, ' ')) const
 
 OptionalTable ()
 
void validate (ParameterSet const &pset, std::set< std::string > const &keysToIgnore={})
 
- Public Member Functions inherited from fhicl::detail::TableBase
 TableBase (Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
 
std::vector< cet::exempt_ptr< ParameterBase > > const & members () 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 Types

using members_t = std::vector< cet::exempt_ptr< ParameterBase >>
 

Private Member Functions

members_t const & get_members () const override
 
void do_set_value (fhicl::ParameterSet const &pset) override
 
- Private Member Functions inherited from fhicl::detail::RegisterIfTableMember
 RegisterIfTableMember (ParameterBase *pb)
 

Private Attributes

std::shared_ptr< T > value_ {std::make_shared<T>()}
 
bool has_value_ {false}
 
ParameterSet pset_ {}
 
members_t members_ {detail::TableMemberRegistry::release_members()}
 

Detailed Description

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

Definition at line 32 of file type_traits.h.

Member Typedef Documentation

template<typename T>
using fhicl::OptionalTable< T >::members_t = std::vector<cet::exempt_ptr<ParameterBase>>
private

Definition at line 87 of file OptionalTable.h.

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

Definition at line 79 of file OptionalTable.h.

Constructor & Destructor Documentation

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

Definition at line 122 of file OptionalTable.h.

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

Definition at line 127 of file OptionalTable.h.

132  , RegisterIfTableMember{this}
133  {
135  }
std::string const & name() const
Definition: ParameterBase.h:43
std::function< bool()> AlwaysUse()
def move(depos, offset)
Definition: depos.py:107
std::string const & comment() const
Definition: ParameterBase.h:48
TableBase(Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
Definition: TableBase.h:11
template<typename T >
fhicl::OptionalTable< T >::OptionalTable ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 138 of file OptionalTable.h.

144  maybeUse}
145  , RegisterIfTableMember{this}
146  {
148  }
std::string const & name() const
Definition: ParameterBase.h:43
def move(depos, offset)
Definition: depos.py:107
std::string const & comment() const
Definition: ParameterBase.h:48
TableBase(Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
Definition: TableBase.h:11
template<typename T >
fhicl::OptionalTable< T >::OptionalTable ( ParameterSet const &  pset,
std::set< std::string > const &  keysToIgnore 
)

Definition at line 151 of file OptionalTable.h.

153  : TableBase{Name("<top_level>"),
154  Comment(""),
157  , RegisterIfTableMember{this}
158  {
160  validate(pset, keysToIgnore);
161  }
void validate(ParameterSet const &pset, std::set< std::string > const &keysToIgnore={})
ChannelGroupService::Name Name
std::function< bool()> AlwaysUse()
#define Comment
TableBase(Name const &name, Comment const &comment, par_style const vt, std::function< bool()> maybeUse)
Definition: TableBase.h:11
template<typename T>
fhicl::OptionalTable< T >::OptionalTable ( )

Member Function Documentation

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

Implements fhicl::detail::ParameterBase.

Definition at line 186 of file OptionalTable.h.

187  {
188  // Kind of tricky: we do not have the name of the current
189  // parameter set. A placeholder is often used
190  // (e.g. "<top_level>"). Fortunately, since the pset is passed
191  // in, we can just assign to it for a top-level ParameterSet.
192  // However, for nested parameter sets, we need to trim off the
193  // placeholder, and then the key we send
194  // pset.get<fhicl::ParameterSet>(key) is the key relative to the
195  // top-level pset.
196  std::string const& rkey = key();
198  if (nkey == rkey) {
199  pset_ = pset;
200  has_value_ = true;
201  } else {
202  has_value_ = pset.get_if_present<fhicl::ParameterSet>(nkey, pset_);
203  }
204  }
std::string string
Definition: nybbler.cc:12
std::string strip_first_containing_name(std::string const &key)
std::string const & key() const
Definition: ParameterBase.h:38
ParameterSet pset_
Definition: OptionalTable.h:91
template<typename T>
members_t const& fhicl::OptionalTable< T >::get_members ( ) const
inlineoverrideprivatevirtual

Implements fhicl::detail::TableBase.

Definition at line 95 of file OptionalTable.h.

96  {
97  return members_;
98  }
template<typename T>
ParameterSet const& fhicl::OptionalTable< T >::get_PSet ( ) const
inline

Definition at line 68 of file OptionalTable.h.

69  {
70  return pset_;
71  }
ParameterSet pset_
Definition: OptionalTable.h:91
template<typename T>
bool fhicl::OptionalTable< T >::hasValue ( ) const
inline

Definition at line 62 of file OptionalTable.h.

63  {
64  return has_value_;
65  }
template<typename T>
std::optional<T> fhicl::OptionalTable< T >::operator() ( ) const
inline

Definition at line 45 of file OptionalTable.h.

46  {
47  return value_ ? std::make_optional(*value_) : std::nullopt;
48  }
std::shared_ptr< T > value_
Definition: OptionalTable.h:89
STL namespace.
template<typename T>
bool fhicl::OptionalTable< T >::operator() ( T &  value) const
inline

Definition at line 52 of file OptionalTable.h.

53  {
54  if (has_value_) {
55  value = *value_;
56  return true;
57  }
58  return false;
59  }
std::shared_ptr< T > value_
Definition: OptionalTable.h:89
template<typename T >
void fhicl::OptionalTable< T >::print_allowed_configuration ( std::ostream &  os,
std::string const &  tab = std::string(3, ' ') 
) const

Definition at line 176 of file OptionalTable.h.

178  {
179  os << '\n' << tab << detail::optional_parameter_message() << '\n';
180  detail::PrintAllowedConfiguration pc{os};
181  pc.walk_over(*this);
182  }
std::string optional_parameter_message(bool const with_comment=true)
template<typename T >
void fhicl::OptionalTable< T >::validate ( ParameterSet const &  pset,
std::set< std::string > const &  keysToIgnore = {} 
)

Definition at line 165 of file OptionalTable.h.

167  {
168  pset_ = pset;
169  detail::ValidateThenSet vs{pset_, keysToIgnore};
170  cet::for_all(members(), [&vs](auto m) { vs(m.get()); });
171  vs.check_keys();
172  }
std::vector< cet::exempt_ptr< ParameterBase > > const & members() const
Definition: TableBase.h:19
ParameterSet pset_
Definition: OptionalTable.h:91
auto for_all(FwdCont &, Func)

Member Data Documentation

template<typename T>
bool fhicl::OptionalTable< T >::has_value_ {false}
private

Definition at line 90 of file OptionalTable.h.

template<typename T>
members_t fhicl::OptionalTable< T >::members_ {detail::TableMemberRegistry::release_members()}
private

Definition at line 92 of file OptionalTable.h.

template<typename T>
ParameterSet fhicl::OptionalTable< T >::pset_ {}
private

Definition at line 91 of file OptionalTable.h.

template<typename T>
std::shared_ptr<T> fhicl::OptionalTable< T >::value_ {std::make_shared<T>()}
private

Definition at line 89 of file OptionalTable.h.


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