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

#include <type_traits.h>

Inheritance diagram for fhicl::OptionalSequence< T, N >:
fhicl::detail::SequenceBase fhicl::detail::RegisterIfTableMember fhicl::detail::ParameterBase

Public Types

using ftype = std::array< std::shared_ptr< tt::fhicl_type< T >>, N >
 
using value_type = std::array< tt::return_type< T >, N >
 

Public Member Functions

 OptionalSequence (Name &&name)
 
 OptionalSequence (Name &&name, Comment &&comment)
 
 OptionalSequence (Name &&name, Comment &&comment, std::function< bool()> maybeUse)
 
std::optional< value_typeoperator() () const
 
bool operator() (value_type &t) const
 
bool hasValue () const noexcept
 
- 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 Member Functions

std::size_t get_size () const noexcept override
 
void do_prepare_elements_for_validation (std::size_t const n) override
 
void do_walk_elements (detail::ParameterWalker< tt::const_flavor::require_non_const > &pw) override
 
void do_walk_elements (detail::ParameterWalker< tt::const_flavor::require_const > &pw) const override
 
bool do_preset_value (fhicl::ParameterSet const &) override
 
void do_set_value (fhicl::ParameterSet const &) override
 
- Private Member Functions inherited from fhicl::detail::RegisterIfTableMember
 RegisterIfTableMember (ParameterBase *pb)
 

Private Attributes

std::variant< ftype, value_typevalue_
 
bool has_value_ {false}
 

Detailed Description

template<typename T, std::size_t N = -1ull>
class fhicl::OptionalSequence< T, N >

Definition at line 45 of file type_traits.h.

Member Typedef Documentation

template<typename T, std::size_t N = -1ull>
using fhicl::OptionalSequence< T, N >::ftype = std::array<std::shared_ptr<tt::fhicl_type<T>>, N>

Definition at line 36 of file OptionalSequence.h.

template<typename T, std::size_t N = -1ull>
using fhicl::OptionalSequence< T, N >::value_type = std::array<tt::return_type<T>, N>

Definition at line 37 of file OptionalSequence.h.

Constructor & Destructor Documentation

template<typename T , std::size_t N>
fhicl::OptionalSequence< T, N >::OptionalSequence ( Name &&  name)
explicit

Definition at line 249 of file OptionalSequence.h.

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

Definition at line 254 of file OptionalSequence.h.

260  , RegisterIfTableMember{this}
261  , value_{ftype{nullptr}}
262  {
263  auto& value = std::get<ftype>(value_);
264  for (std::size_t i{}; i != N; ++i) {
265  value.at(i) =
266  std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
267  }
269  }
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
std::array< std::shared_ptr< tt::fhicl_type< T >>, N > ftype
std::variant< ftype, value_type > value_
def move(depos, offset)
Definition: depos.py:107
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48
template<typename T , std::size_t N>
fhicl::OptionalSequence< T, N >::OptionalSequence ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 272 of file OptionalSequence.h.

279  maybeUse}
280  , RegisterIfTableMember{this}
281  , value_{ftype{nullptr}}
282  {
283  auto& value = std::get<ftype>(value_);
284  for (std::size_t i{}; i != N; ++i) {
285  value.at(i) =
286  std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
287  }
289  }
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
std::array< std::shared_ptr< tt::fhicl_type< T >>, N > ftype
std::variant< ftype, value_type > value_
def move(depos, offset)
Definition: depos.py:107
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48

Member Function Documentation

template<typename T, std::size_t N = -1ull>
void fhicl::OptionalSequence< T, N >::do_prepare_elements_for_validation ( std::size_t const  n)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 93 of file OptionalSequence.h.

94  {
96  }
void check_nargs_for_bounded_sequences(std::string const &key, std::size_t expected, std::size_t provided)
std::size_t get_size() const noexcept override
std::void_t< T > n
std::string const & key() const
Definition: ParameterBase.h:38
template<typename T , std::size_t N>
bool fhicl::OptionalSequence< T, N >::do_preset_value ( fhicl::ParameterSet const &  ps)
overrideprivatevirtual

Reimplemented from fhicl::detail::ParameterBase.

Definition at line 293 of file OptionalSequence.h.

294  {
295  if constexpr (std::is_same_v<tt::fhicl_type<T>, Atom<T>>) {
296  auto const trimmed_key = detail::strip_first_containing_name(key());
297  value_ = ps.get<value_type>(trimmed_key);
298  has_value_ = true;
299  return true;
300  }
301  return false;
302  }
std::array< tt::return_type< T >, N > value_type
std::variant< ftype, value_type > value_
std::string strip_first_containing_name(std::string const &key)
typename fhicl_type_impl< T >::type fhicl_type
Definition: type_traits.h:315
static constexpr double ps
Definition: Units.h:99
std::string const & key() const
Definition: ParameterBase.h:38
template<typename T , std::size_t N>
void fhicl::OptionalSequence< T, N >::do_set_value ( fhicl::ParameterSet const &  )
overrideprivatevirtual

Implements fhicl::detail::ParameterBase.

Definition at line 306 of file OptionalSequence.h.

307  {
308  // We do not explicitly set the sequence values here as the
309  // individual elements are set one at a time. However, this
310  // function is reached in the ValidateThenSet algorithm if the
311  // optional parameter is present. Otherwise, this override is
312  // skipped.
313  has_value_ = true;
314  }
template<typename T, std::size_t N = -1ull>
void fhicl::OptionalSequence< T, N >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_non_const > &  pw)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 99 of file OptionalSequence.h.

101  {
102  // We only enter here if we do not have a preset value.
103  cet::for_all(std::get<ftype>(value_),
104  [&pw](auto& e) { pw.walk_over(*e); });
105  }
std::variant< ftype, value_type > value_
const double e
auto for_all(FwdCont &, Func)
template<typename T, std::size_t N = -1ull>
void fhicl::OptionalSequence< T, N >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_const > &  pw) const
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 108 of file OptionalSequence.h.

110  {
111  // We only enter here if we do not have a preset value.
112  cet::for_all(std::get<ftype>(value_),
113  [&pw](auto const& e) { pw.walk_over(*e); });
114  }
std::variant< ftype, value_type > value_
const double e
auto for_all(FwdCont &, Func)
template<typename T, std::size_t N = -1ull>
std::size_t fhicl::OptionalSequence< T, N >::get_size ( ) const
inlineoverrideprivatevirtualnoexcept

Implements fhicl::detail::SequenceBase.

Definition at line 84 of file OptionalSequence.h.

85  {
86  if (auto value = std::get_if<value_type>(&value_)) {
87  return value->size();
88  }
89  return std::get<ftype>(value_).size();
90  }
std::size_t size() const noexcept
Definition: SequenceBase.h:33
std::variant< ftype, value_type > value_
template<typename T, std::size_t N = -1ull>
bool fhicl::OptionalSequence< T, N >::hasValue ( ) const
inlinenoexcept

Definition at line 74 of file OptionalSequence.h.

75  {
76  return has_value_;
77  }
template<typename T, std::size_t N = -1ull>
std::optional<value_type> fhicl::OptionalSequence< T, N >::operator() ( ) const
inline

Definition at line 46 of file OptionalSequence.h.

47  {
48  if (!has_value_)
49  return std::nullopt;
50 
51  if (auto value = std::get_if<value_type>(&value_)) {
52  return std::make_optional(*value); // Do not move!
53  }
54 
56  cet::transform_all(std::get<ftype>(value_),
57  result.begin(),
58  [](auto const& elem) { return (*elem)(); });
59  return std::make_optional(std::move(result));
60  }
static QCString result
std::array< tt::return_type< T >, N > value_type
std::variant< ftype, value_type > value_
def move(depos, offset)
Definition: depos.py:107
auto transform_all(Container &, OutputIt, UnaryOp)
typename return_type_impl< ARGS... >::value_type return_type
Definition: type_traits.h:357
template<typename T, std::size_t N = -1ull>
bool fhicl::OptionalSequence< T, N >::operator() ( value_type t) const
inline

Definition at line 64 of file OptionalSequence.h.

65  {
66  auto const result = operator()();
67  if (result) {
68  t = *result;
69  }
70  return result.has_value();
71  }
static QCString result
std::optional< value_type > operator()() const

Member Data Documentation

template<typename T, std::size_t N = -1ull>
bool fhicl::OptionalSequence< T, N >::has_value_ {false}
private

Definition at line 81 of file OptionalSequence.h.

template<typename T, std::size_t N = -1ull>
std::variant<ftype, value_type> fhicl::OptionalSequence< T, N >::value_
private

Definition at line 80 of file OptionalSequence.h.


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