LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::OptionalTuple< T > Class Template Reference

#include "type_traits.h"

Inheritance diagram for fhicl::OptionalTuple< T >:
fhicl::detail::SequenceBase fhicl::detail::RegisterIfTableMember fhicl::detail::ParameterBase

Public Types

using ftype = std::tuple< std::shared_ptr< tt::fhicl_type< T >>... >
 
using value_type = std::tuple< tt::return_type< T >... >
 

Public Member Functions

 OptionalTuple (Name &&name)
 
 OptionalTuple (Name &&name, Comment &&comment)
 
 OptionalTuple (Name &&name, Comment &&comment, std::function< bool()> maybeUse)
 
auto operator() () const -> std::optional< value_type >
 
auto operator() (value_type &) const -> bool
 
bool hasValue () const
 
bool empty () const noexcept
 
std::size_t size () const noexcept
 
void prepare_elements_for_validation (std::size_t const n)
 
void walk_elements (ParameterWalker< tt::const_flavor::require_non_const > &pw)
 
void walk_elements (ParameterWalker< tt::const_flavor::require_const > &pw) 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 Types

using PW_non_const = detail::ParameterWalker< tt::const_flavor::require_non_const >
 
using PW_const = detail::ParameterWalker< tt::const_flavor::require_const >
 

Private Member Functions

std::size_t get_size () const noexcept override
 
template<std::size_t... I>
void iterate_over_tuple (PW_non_const &pw, std::index_sequence< I... >)
 
void do_prepare_elements_for_validation (std::size_t const n) override
 
void do_walk_elements (PW_non_const &pw) override
 
template<std::size_t... I>
void iterate_over_tuple (PW_const &pw, std::index_sequence< I... >) const
 
void do_walk_elements (PW_const &pw) const override
 
template<std::size_t I>
void finalize_element ()
 
template<std::size_t... I>
void finalize_elements (std::index_sequence< I... >)
 
template<std::size_t... I>
value_type get_rtype_result (std::index_sequence< I... >) const
 
void do_set_value (fhicl::ParameterSet const &) override
 

Private Attributes

ftype value_
 
bool has_value_ {false}
 

Detailed Description

template<typename... T>
class fhicl::OptionalTuple< T >

Definition at line 40 of file type_traits.h.

Member Typedef Documentation

template<typename... T>
using fhicl::OptionalTuple< T >::ftype = std::tuple<std::shared_ptr<tt::fhicl_type<T>>...>

Definition at line 31 of file OptionalTuple.h.

Definition at line 73 of file OptionalTuple.h.

Definition at line 72 of file OptionalTuple.h.

template<typename... T>
using fhicl::OptionalTuple< T >::value_type = std::tuple<tt::return_type<T>...>

Definition at line 32 of file OptionalTuple.h.

Constructor & Destructor Documentation

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

Definition at line 150 of file OptionalTuple.h.

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

151  : OptionalTuple{std::move(name), Comment("")}
152  {}
OptionalTuple(Name &&name)
std::string const & name() const
template<typename... T>
fhicl::OptionalTuple< T >::OptionalTuple ( Name &&  name,
Comment &&  comment 
)
explicit

Definition at line 155 of file OptionalTuple.h.

References fhicl::detail::AlwaysUse(), fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::OptionalTuple< T >::finalize_elements(), fhicl::detail::ParameterBase::name(), fhicl::OPTIONAL, fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), and fhicl::TUPLE.

156  : SequenceBase{std::move(name),
157  std::move(comment),
161  , RegisterIfTableMember{this}
162  {
163  finalize_elements(std::index_sequence_for<T...>{});
165  }
std::function< bool()> AlwaysUse()
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
Definition: SequenceBase.h:19
std::string const & name() const
void finalize_elements(std::index_sequence< I... >)
std::string const & comment() const
template<typename... T>
fhicl::OptionalTuple< T >::OptionalTuple ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 168 of file OptionalTuple.h.

References fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::OptionalTuple< T >::finalize_elements(), fhicl::detail::ParameterBase::name(), fhicl::OPTIONAL_CONDITIONAL, fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), and fhicl::TUPLE.

171  : SequenceBase{std::move(name),
172  std::move(comment),
175  maybeUse}
176  , RegisterIfTableMember{this}
177  {
178  finalize_elements(std::index_sequence_for<T...>{});
180  }
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
Definition: SequenceBase.h:19
std::string const & name() const
void finalize_elements(std::index_sequence< I... >)
std::string const & comment() const

Member Function Documentation

template<typename... T>
void fhicl::OptionalTuple< T >::do_prepare_elements_for_validation ( std::size_t const  n)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 83 of file OptionalTuple.h.

84  {
86  }
void check_nargs_for_bounded_sequences(std::string const &key, std::size_t expected, std::size_t provided)
std::string const & key() const
Definition: ParameterBase.cc:6
std::size_t get_size() const noexcept override
Definition: OptionalTuple.h:64
Char_t n[5]
template<typename... T>
void fhicl::OptionalTuple< T >::do_set_value ( fhicl::ParameterSet const &  )
inlineoverrideprivatevirtual

Implements fhicl::detail::ParameterBase.

Definition at line 135 of file OptionalTuple.h.

136  {
137  // We do not explicitly set the sequence values here as the
138  // individual elements are set one at a time. However, this
139  // function is reached in the ValidateThenSet algorithm if the
140  // optional parameter is present. Otherwise, this override is
141  // skipped.
142  has_value_ = true;
143  }
template<typename... T>
void fhicl::OptionalTuple< T >::do_walk_elements ( PW_non_const pw)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 89 of file OptionalTuple.h.

90  {
91  iterate_over_tuple(pw, std::index_sequence_for<T...>{});
92  }
void iterate_over_tuple(PW_non_const &pw, std::index_sequence< I... >)
Definition: OptionalTuple.h:77
template<typename... T>
void fhicl::OptionalTuple< T >::do_walk_elements ( PW_const pw) const
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 102 of file OptionalTuple.h.

103  {
104  iterate_over_tuple(pw, std::index_sequence_for<T...>{});
105  }
void iterate_over_tuple(PW_non_const &pw, std::index_sequence< I... >)
Definition: OptionalTuple.h:77
bool fhicl::detail::SequenceBase::empty ( ) const
inlinenoexceptinherited

Definition at line 28 of file SequenceBase.h.

References fhicl::detail::SequenceBase::size().

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

29  {
30  return size() == 0;
31  }
std::size_t size() const noexcept
Definition: SequenceBase.h:33
template<typename... T>
template<std::size_t I>
void fhicl::OptionalTuple< T >::finalize_element ( )
inlineprivate

Definition at line 111 of file OptionalTuple.h.

112  {
113  using elem_ftype = typename std::tuple_element_t<I, ftype>::element_type;
114  std::get<I>(value_) =
115  std::make_shared<elem_ftype>(Name::sequence_element(I));
116  }
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
template<typename... T>
template<std::size_t... I>
void fhicl::OptionalTuple< T >::finalize_elements ( std::index_sequence< I... >  )
inlineprivate

Definition at line 120 of file OptionalTuple.h.

Referenced by fhicl::OptionalTuple< T >::OptionalTuple().

121  {
122  (finalize_element<I>(), ...);
123  }
template<typename... T>
template<std::size_t... I>
value_type fhicl::OptionalTuple< T >::get_rtype_result ( std::index_sequence< I... >  ) const
inlineprivate

Definition at line 129 of file OptionalTuple.h.

Referenced by fhicl::OptionalTuple< T >::operator()().

130  {
131  return value_type{(*std::get<I>(value_))()...};
132  }
std::tuple< tt::return_type< T >... > value_type
Definition: OptionalTuple.h:32
template<typename... T>
std::size_t fhicl::OptionalTuple< T >::get_size ( ) const
inlineoverrideprivatevirtualnoexcept

Implements fhicl::detail::SequenceBase.

Definition at line 64 of file OptionalTuple.h.

Referenced by fhicl::OptionalTuple< ARGS... >::do_prepare_elements_for_validation().

65  {
66  return std::tuple_size<ftype>();
67  }
template<typename... T>
bool fhicl::OptionalTuple< T >::hasValue ( ) const
inline

Definition at line 54 of file OptionalTuple.h.

55  {
56  return has_value_;
57  }
bool fhicl::detail::ParameterBase::is_conditional ( ) const
inherited
template<typename... T>
template<std::size_t... I>
void fhicl::OptionalTuple< T >::iterate_over_tuple ( PW_non_const pw,
std::index_sequence< I... >   
)
inlineprivate

Definition at line 77 of file OptionalTuple.h.

Referenced by fhicl::OptionalTuple< ARGS... >::do_walk_elements().

78  {
79  (pw.walk_over(*std::get<I>(value_)), ...);
80  }
template<typename... T>
template<std::size_t... I>
void fhicl::OptionalTuple< T >::iterate_over_tuple ( PW_const pw,
std::index_sequence< I... >   
) const
inlineprivate

Definition at line 96 of file OptionalTuple.h.

97  {
98  (pw.walk_over(*std::get<I>(value_)), ...);
99  }
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>
auto fhicl::OptionalTuple< T >::operator() ( ) const -> std::optional<value_type>

Definition at line 184 of file OptionalTuple.h.

References fhicl::OptionalTuple< T >::get_rtype_result(), and fhicl::OptionalTuple< T >::has_value_.

Referenced by fhicl::OptionalTuple< T >::operator()().

185  {
186  if (!has_value_)
187  return std::nullopt;
188  return std::make_optional(
189  get_rtype_result(std::index_sequence_for<T...>()));
190  }
value_type get_rtype_result(std::index_sequence< I... >) const
template<typename... T>
auto fhicl::OptionalTuple< T >::operator() ( value_type r) const -> bool

Definition at line 194 of file OptionalTuple.h.

References fhicl::OptionalTuple< T >::operator()(), and r.

195  {
196  auto result = operator()();
197  if (result) {
198  r = *result;
199  }
200  return result.has_value();
201  }
TRandom r
Definition: spectrum.C:23
auto operator()() const -> std::optional< value_type >
void fhicl::detail::SequenceBase::prepare_elements_for_validation ( std::size_t const  n)
inlineinherited

Definition at line 39 of file SequenceBase.h.

References fhicl::detail::SequenceBase::do_prepare_elements_for_validation().

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

40  {
42  }
virtual void do_prepare_elements_for_validation(std::size_t)=0
Char_t n[5]
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::size_t fhicl::detail::SequenceBase::size ( void  ) const
inlinenoexceptinherited
void fhicl::detail::SequenceBase::walk_elements ( ParameterWalker< tt::const_flavor::require_non_const > &  pw)
inlineinherited

Definition at line 44 of file SequenceBase.h.

References fhicl::detail::SequenceBase::do_walk_elements().

45  {
46  do_walk_elements(pw);
47  }
virtual void do_walk_elements(ParameterWalker< tt::const_flavor::require_non_const > &)=0
void fhicl::detail::SequenceBase::walk_elements ( ParameterWalker< tt::const_flavor::require_const > &  pw) const
inlineinherited

Definition at line 49 of file SequenceBase.h.

References fhicl::detail::SequenceBase::do_prepare_elements_for_validation(), fhicl::detail::SequenceBase::do_walk_elements(), and fhicl::detail::SequenceBase::get_size().

50  {
51  do_walk_elements(pw);
52  }
virtual void do_walk_elements(ParameterWalker< tt::const_flavor::require_non_const > &)=0

Member Data Documentation

template<typename... T>
bool fhicl::OptionalTuple< T >::has_value_ {false}
private
template<typename... T>
ftype fhicl::OptionalTuple< T >::value_
private

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