Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
fhicl::OptionalSequence< T,-1ull > Class Template Referencefinal

#include <OptionalSequence.h>

Inheritance diagram for fhicl::OptionalSequence< T,-1ull >:
fhicl::detail::SequenceBase fhicl::detail::RegisterIfTableMember fhicl::detail::ParameterBase

Public Types

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

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

void do_prepare_elements_for_validation (std::size_t const n) override
 
std::size_t get_size () const noexcept 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>
class fhicl::OptionalSequence< T,-1ull >

Definition at line 124 of file OptionalSequence.h.

Member Typedef Documentation

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

Definition at line 132 of file OptionalSequence.h.

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

Definition at line 133 of file OptionalSequence.h.

Constructor & Destructor Documentation

template<typename T >
fhicl::OptionalSequence< T,-1ull >::OptionalSequence ( Name &&  name)
explicit

Definition at line 321 of file OptionalSequence.h.

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

Definition at line 326 of file OptionalSequence.h.

332  , RegisterIfTableMember{this}
333  , value_{
334  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
335  {
337  }
std::variant< ftype, value_type > value_
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
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48
std::vector< std::shared_ptr< tt::fhicl_type< T >>> ftype
template<typename T >
fhicl::OptionalSequence< T,-1ull >::OptionalSequence ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 340 of file OptionalSequence.h.

347  maybeUse}
348  , RegisterIfTableMember{this}
349  , value_{
350  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
351  {
353  }
std::variant< ftype, value_type > value_
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
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48
std::vector< std::shared_ptr< tt::fhicl_type< T >>> ftype

Member Function Documentation

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

Implements fhicl::detail::SequenceBase.

Definition at line 180 of file OptionalSequence.h.

181  {
182  // We only enter here if we do not have a preset value.
183  auto& value = std::get<ftype>(value_);
184 
185  if (n < value.size()) {
186  value.resize(n);
187  } else if (n > value.size()) {
188 
189  std::string key_fragment{key()};
190  // When emplacing a new element, do not include in the key
191  // argument the current name-stack stem--it will
192  // automatically be prepended.
193  if (!NameStackRegistry::empty()) {
194  std::string const& current_stem = NameStackRegistry::current();
195  std::size_t const pos =
196  key_fragment.find(current_stem) != std::string::npos ?
197  current_stem.size() + 1ul : // + 1ul to account for the '.'
198  0ul;
199  key_fragment.replace(0ul, pos, "");
200  }
201 
202  for (auto i = value.size(); i != n; ++i) {
203  value.emplace_back(
204  new tt::fhicl_type<T>{Name::sequence_element(key_fragment, i)});
205  }
206  }
207  }
std::variant< ftype, value_type > value_
std::string string
Definition: nybbler.cc:12
typename fhicl_type_impl< T >::type fhicl_type
Definition: type_traits.h:315
std::void_t< T > n
static std::string current()
std::string const & key() const
Definition: ParameterBase.h:38
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
template<typename T >
bool fhicl::OptionalSequence< T,-1ull >::do_preset_value ( fhicl::ParameterSet const &  ps)
overrideprivatevirtual

Reimplemented from fhicl::detail::ParameterBase.

Definition at line 357 of file OptionalSequence.h.

358  {
359  if constexpr (std::is_same_v<tt::fhicl_type<T>, Atom<T>>) {
360  auto const trimmed_key = detail::strip_first_containing_name(key());
361  value_ = ps.get<value_type>(trimmed_key);
362  has_value_ = true;
363  return true;
364  }
365  return false;
366  }
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
std::vector< tt::return_type< T >> value_type
template<typename T >
void fhicl::OptionalSequence< T,-1ull >::do_set_value ( fhicl::ParameterSet const &  )
overrideprivatevirtual

Implements fhicl::detail::ParameterBase.

Definition at line 370 of file OptionalSequence.h.

371  {
372  // We do not explicitly set the sequence values here as the
373  // individual elements are set one at a time. However, this
374  // function is reached in the ValidateThenSet algorithm if the
375  // optional parameter is present. Otherwise, this override is
376  // skipped.
377  has_value_ = true;
378  }
template<typename T >
void fhicl::OptionalSequence< T,-1ull >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_non_const > &  pw)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 219 of file OptionalSequence.h.

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

Implements fhicl::detail::SequenceBase.

Definition at line 228 of file OptionalSequence.h.

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

Implements fhicl::detail::SequenceBase.

Definition at line 210 of file OptionalSequence.h.

211  {
212  if (auto value = std::get_if<value_type>(&value_)) {
213  return value->size();
214  }
215  return std::get<ftype>(value_).size();
216  }
std::variant< ftype, value_type > value_
std::size_t size() const noexcept
Definition: SequenceBase.h:33
template<typename T >
bool fhicl::OptionalSequence< T,-1ull >::hasValue ( ) const
inlinenoexcept

Definition at line 170 of file OptionalSequence.h.

171  {
172  return has_value_;
173  }
template<typename T >
std::optional<value_type> fhicl::OptionalSequence< T,-1ull >::operator() ( ) const
inline

Definition at line 142 of file OptionalSequence.h.

143  {
144  if (!has_value_)
145  return std::nullopt;
146 
147  if (auto value = std::get_if<value_type>(&value_)) {
148  return std::make_optional(std::move(*value));
149  }
150 
152  cet::transform_all(std::get<ftype>(value_),
153  std::back_inserter(result),
154  [](auto const& elem) { return (*elem)(); });
155  return std::make_optional(std::move(result));
156  }
std::variant< ftype, value_type > value_
static QCString result
def move(depos, offset)
Definition: depos.py:107
auto transform_all(Container &, OutputIt, UnaryOp)
std::vector< tt::return_type< T >> value_type
template<typename T >
bool fhicl::OptionalSequence< T,-1ull >::operator() ( value_type t) const
inline

Definition at line 160 of file OptionalSequence.h.

161  {
162  if (auto result = operator()()) {
163  t = *result;
164  return true;
165  }
166  return false;
167  }
static QCString result

Member Data Documentation

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

Definition at line 177 of file OptionalSequence.h.

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

Definition at line 176 of file OptionalSequence.h.


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