LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
 
 OptionalTable ()
 
void print_allowed_configuration (std::ostream &os, std::string const &tab=std::string(3, ' ')) const
 
std::vector< cet::exempt_ptr< ParameterBase > > const & members () const
 
void validate (ParameterSet const &pset, std::set< std::string > const &ignorable_keys={})
 
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)
 

Protected Member Functions

void finalize_members ()
 
void maybe_implicitly_default ()
 
bool has_value () const
 
ParameterSet const & get_pset () const
 
ParameterSet const & guarantee_pset () const
 

Private Attributes

std::shared_ptr< T > value_ {std::make_shared<T>()}
 

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 >::value_type = T

Definition at line 75 of file OptionalTable.h.

Constructor & Destructor Documentation

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

Definition at line 87 of file OptionalTable.h.

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

88  : OptionalTable{std::move(name), Comment("")}
89  {}
std::string const & name() const
template<typename T >
fhicl::OptionalTable< T >::OptionalTable ( Name &&  name,
Comment &&  comment 
)
explicit
template<typename T >
fhicl::OptionalTable< T >::OptionalTable ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit
template<typename T >
fhicl::OptionalTable< T >::OptionalTable ( ParameterSet const &  pset,
std::set< std::string > const &  keysToIgnore 
)

Definition at line 118 of file OptionalTable.h.

References fhicl::detail::AlwaysUse(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::TableBase::finalize_members(), fhicl::OPTIONAL, fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), and fhicl::detail::TableBase::validate().

120  : TableBase{Name("<top_level>"),
121  Comment(""),
124  , RegisterIfTableMember{this}
125  {
128  validate(pset, keysToIgnore);
129  }
std::function< bool()> AlwaysUse()
void validate(ParameterSet const &pset, std::set< std::string > const &ignorable_keys={})
Definition: TableBase.cc:56
TableBase(Name const &name, Comment const &comment, par_style vt, std::function< bool()> maybeUse)
Definition: TableBase.cc:12
template<typename T>
fhicl::OptionalTable< T >::OptionalTable ( )

Member Function Documentation

void fhicl::detail::TableBase::finalize_members ( )
protectedinherited

Definition at line 37 of file TableBase.cc.

References fhicl::detail::TableBase::members_, and fhicl::detail::TableMemberRegistry::release_members().

Referenced by fhicl::OptionalTable< T >::OptionalTable(), and fhicl::Table< T, KeysToIgnore >::Table().

38  {
39  // This must be called in a derived class **after** the table's
40  // values has been set.
42  }
std::vector< cet::exempt_ptr< ParameterBase > > members_
Definition: TableBase.h:45
static std::vector< base_ptr > release_members()
ParameterSet const & fhicl::detail::TableBase::get_pset ( ) const
protectedinherited

Definition at line 79 of file TableBase.cc.

References fhicl::detail::TableBase::pset_.

80  {
81  return pset_.value();
82  }
std::optional< ParameterSet > pset_
Definition: TableBase.h:44
template<typename T>
ParameterSet const& fhicl::OptionalTable< T >::get_PSet ( ) const
inline

Definition at line 68 of file OptionalTable.h.

69  {
70  return TableBase::guarantee_pset();
71  }
ParameterSet const & fhicl::detail::TableBase::guarantee_pset ( ) const
protectedinherited

Definition at line 85 of file TableBase.cc.

References fhicl::detail::TableBase::pset_.

86  {
87  static ParameterSet const empty_pset;
88  return pset_.has_value() ? *pset_ : empty_pset;
89  }
std::optional< ParameterSet > pset_
Definition: TableBase.h:44
bool fhicl::detail::TableBase::has_value ( ) const
protectedinherited

Definition at line 73 of file TableBase.cc.

References fhicl::detail::TableBase::pset_.

74  {
75  return pset_.has_value();
76  }
std::optional< ParameterSet > pset_
Definition: TableBase.h:44
template<typename T>
bool fhicl::OptionalTable< T >::hasValue ( ) const
inline

Definition at line 62 of file OptionalTable.h.

Referenced by fhicl::OptionalTableAs< T, Config >::hasValue(), and fhicl::OptionalTable< art::Scheduler::Config::DebugConfig >::operator()().

63  {
64  return TableBase::has_value();
65  }
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
void fhicl::detail::TableBase::maybe_implicitly_default ( )
protectedinherited

Definition at line 45 of file TableBase.cc.

References fhicl::DEFAULT, fhicl::detail::TableBase::members_, and fhicl::detail::ParameterBase::set_par_style().

Referenced by fhicl::Table< T, KeysToIgnore >::Table().

46  {
47  bool const implicitly_default =
48  std::all_of(members_.begin(), members_.end(), [](auto p) {
49  return p->has_default() || p->is_optional();
50  });
51  if (implicitly_default)
53  }
std::vector< cet::exempt_ptr< ParameterBase > > members_
Definition: TableBase.h:45
void set_par_style(par_style const vt)
std::vector< cet::exempt_ptr< ParameterBase > > const & fhicl::detail::TableBase::members ( ) const
inherited

Definition at line 31 of file TableBase.cc.

References fhicl::detail::TableBase::members_.

32  {
33  return members_;
34  }
std::vector< cet::exempt_ptr< ParameterBase > > members_
Definition: TableBase.h:45
template<typename T>
std::optional<T> fhicl::OptionalTable< T >::operator() ( ) const
inline

Definition at line 45 of file OptionalTable.h.

Referenced by fhicl::OptionalTable< art::Scheduler::Config::DebugConfig >::operator()().

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

Definition at line 52 of file OptionalTable.h.

53  {
54  auto opt = operator()();
55  if (opt) {
56  value = *value_;
57  }
58  return opt.has_value();
59  }
std::shared_ptr< T > value_
Definition: OptionalTable.h:80
std::optional< T > operator()() const
Definition: OptionalTable.h:45
double value
Definition: spectrum.C:18
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::TableBase::print_allowed_configuration ( std::ostream &  os,
std::string const &  tab = std::string(3, ' ') 
) const
inherited

Definition at line 22 of file TableBase.cc.

References fhicl::detail::optional_parameter_message(), and fhicl::detail::ParameterWalker< C >::walk_over().

Referenced by art::operator<<(), and fhicl::detail::operator<<().

24  {
25  os << '\n' << tab << optional_parameter_message() << '\n';
26  PrintAllowedConfiguration pc{os, false, tab};
27  pc.walk_over(*this);
28  }
std::string optional_parameter_message(bool const with_comment=true)
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
void fhicl::detail::TableBase::validate ( ParameterSet const &  pset,
std::set< std::string > const &  ignorable_keys = {} 
)
inherited

Definition at line 56 of file TableBase.cc.

References fhicl::NameStackRegistry::clear(), fhicl::detail::TableBase::members_, and fhicl::detail::TableBase::pset_.

Referenced by fhicl::OptionalTable< T >::OptionalTable(), and fhicl::Table< T, KeysToIgnore >::Table().

58  {
59  pset_ = std::make_optional(pset);
60  ValidateThenSet vs{pset, ignorable_keys};
61  cet::for_all(members_, [&vs](auto m) { vs.walk_over(*m); });
62 
63  try {
64  vs.check_keys();
65  }
66  catch (detail::validationException const&) {
68  throw;
69  }
70  }
std::vector< cet::exempt_ptr< ParameterBase > > members_
Definition: TableBase.h:45
std::optional< ParameterSet > pset_
Definition: TableBase.h:44

Member Data Documentation

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

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