1 #ifndef fhiclcpp_types_OptionalSequence_h 2 #define fhiclcpp_types_OptionalSequence_h 18 #include <type_traits> 28 template <
typename T, std::size_t N = -1ull>
29 class OptionalSequence final :
public detail::SequenceBase,
30 private detail::RegisterIfTableMember {
36 using ftype = std::array<std::shared_ptr<tt::fhicl_type<T>>, N>;
43 std::function<
bool()> maybeUse);
45 std::optional<value_type>
51 if (
auto value = std::get_if<value_type>(&
value_)) {
52 return std::make_optional(*
value);
56 cet::transform_all(std::get<ftype>(
value_),
58 [](
auto const& elem) {
return (*elem)(); });
59 return std::make_optional(std::move(result));
70 return result.has_value();
80 std::variant<ftype, value_type>
value_;
86 if (
auto value = std::get_if<value_type>(&value_)) {
103 cet::for_all(std::get<ftype>(value_),
112 cet::for_all(std::get<ftype>(value_),
123 template <
typename T>
132 using ftype = std::vector<std::shared_ptr<tt::fhicl_type<T>>>;
139 std::function<
bool()> maybeUse);
141 std::optional<value_type>
147 if (
auto value = std::get_if<value_type>(&
value_)) {
148 return std::make_optional(std::move(*
value));
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));
162 if (
auto result =
operator()()) {
185 if (n <
value.size()) {
187 }
else if (n >
value.size()) {
189 std::string key_fragment{
key()};
195 std::size_t
const pos =
196 key_fragment.find(current_stem) != std::string::npos ?
197 current_stem.size() + 1ul :
199 key_fragment.replace(0ul, pos,
"");
202 for (
auto i =
value.size(); i !=
n; ++i) {
212 if (
auto value = std::get_if<value_type>(&value_)) {
213 return value->size();
223 cet::for_all(std::get<ftype>(value_),
232 cet::for_all(std::get<ftype>(value_),
248 template <
typename T, std::
size_t N>
253 template <
typename T, std::
size_t N>
264 for (std::size_t i{}; i != N; ++i) {
271 template <
typename T, std::
size_t N>
274 std::function<
bool()> maybeUse)
284 for (std::size_t i{}; i != N; ++i) {
291 template <
typename T, std::
size_t N>
304 template <
typename T, std::
size_t N>
320 template <
typename T>
325 template <
typename T>
339 template <
typename T>
342 std::function<
bool()> maybeUse)
355 template <
typename T>
368 template <
typename T>
std::variant< ftype, value_type > value_
void do_prepare_elements_for_validation(std::size_t const n) override
std::size_t size() const noexcept
std::array< tt::return_type< art::InputTag >,-1ull > value_type
#define NO_DELEGATED_PARAMETERS
void check_nargs_for_bounded_sequences(std::string const &key, std::size_t expected, std::size_t provided)
void do_walk_elements(detail::ParameterWalker< tt::const_flavor::require_non_const > &pw) override
bool hasValue() const noexcept
std::size_t get_size() const noexcept override
#define NO_OPTIONAL_TYPES
static void end_of_ctor()
std::function< bool()> AlwaysUse()
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
void do_set_value(fhicl::ParameterSet const &) override
std::array< std::shared_ptr< tt::fhicl_type< art::InputTag >>,-1ull > ftype
std::variant< ftype, value_type > value_
std::string strip_first_containing_name(std::string const &key)
void walk_over(tt::maybe_const_t< ParameterBase, C > &)
RegisterIfTableMember(ParameterBase *pb)
static std::string current()
typename fhicl_type_impl< T >::type fhicl_type
T get(std::string const &key) const
bool operator()(value_type &t) const
std::string const & name() const
void do_prepare_elements_for_validation(std::size_t const n) override
bool hasValue() const noexcept
std::string const & key() const
std::optional< value_type > operator()() const
void do_walk_elements(detail::ParameterWalker< tt::const_flavor::require_const > &pw) const override
#define NO_NESTED_TABLE_FRAGMENTS
void do_walk_elements(detail::ParameterWalker< tt::const_flavor::require_non_const > &pw) override
bool operator()(value_type &t) const
static Name sequence_element(std::size_t const i)
bool do_preset_value(fhicl::ParameterSet const &) override
void do_walk_elements(detail::ParameterWalker< tt::const_flavor::require_const > &pw) const override
std::vector< tt::return_type< T >> value_type
std::optional< value_type > operator()() const
typename return_type_impl< ARGS... >::value_type return_type
std::string const & comment() const
std::vector< std::shared_ptr< tt::fhicl_type< T >>> ftype
std::size_t get_size() const noexcept override
OptionalSequence(Name &&name)