Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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
 
- Public Member Functions inherited from fhicl::detail::SequenceBase
 SequenceBase (Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
 
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
 
- 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 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 Member Functions inherited from fhicl::detail::RegisterIfTableMember
 RegisterIfTableMember (ParameterBase *pb)
 

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.

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

Definition at line 155 of file OptionalTuple.h.

161  , RegisterIfTableMember{this}
162  {
163  finalize_elements(std::index_sequence_for<T...>{});
165  }
std::string const & name() const
Definition: ParameterBase.h:43
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
def move(depos, offset)
Definition: depos.py:107
void finalize_elements(std::index_sequence< I... >)
std::string const & comment() const
Definition: ParameterBase.h:48
template<typename... T>
fhicl::OptionalTuple< T >::OptionalTuple ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 168 of file OptionalTuple.h.

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

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::void_t< T > n
std::size_t get_size() const noexcept override
Definition: OptionalTuple.h:64
std::string const & key() const
Definition: ParameterBase.h:38
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
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.

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.

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.

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  }
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.

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  }
template<typename... T>
auto fhicl::OptionalTuple< T >::operator() ( ) const -> std::optional<value_type>

Definition at line 184 of file OptionalTuple.h.

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.

195  {
196  auto result = operator()();
197  if (result) {
198  r = *result;
199  }
200  return result.has_value();
201  }
static QCString result
auto operator()() const -> std::optional< value_type >

Member Data Documentation

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

Definition at line 61 of file OptionalTuple.h.

template<typename... T>
ftype fhicl::OptionalTuple< T >::value_
private

Definition at line 60 of file OptionalTuple.h.


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