1 #include "cetlib/container_algorithms.h"
2 #include "cetlib_except/demangle.h"
3 #include "fhiclcpp/detail/printing_helpers.h"
4 #include "fhiclcpp/types/detail/TableMemberRegistry.h"
5 #include "fhiclcpp/types/detail/ostream_helpers.h"
6 #include "fhiclcpp/types/detail/type_traits_error_msgs.h"
7 #include "fhiclcpp/type_traits.h"
14 //==================================================================
15 // e.g. Sequence<int,4> ====> std::array<int,4>
18 template<typename T, std::size_t N>
19 Sequence<T,N>::Sequence(Name&& name)
20 : Sequence{std::move(name), Comment("")} {}
22 template<typename T, std::size_t N>
23 Sequence<T,N>::Sequence(Name&& name, Comment&& comment)
24 : SequenceBase{std::move(name), std::move(comment), par_style::REQUIRED, par_type::SEQ_ARRAY, detail::AlwaysUse()}
25 , RegisterIfTableMember{this}
28 for (std::size_t i{}; i != N; ++i) {
29 value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
31 NameStackRegistry::end_of_ctor();
34 template<typename T, std::size_t N>
35 Sequence<T,N>::Sequence(Name&& name, Comment&& comment, std::function<bool()> maybeUse)
36 : SequenceBase{std::move(name), std::move(comment), par_style::REQUIRED_CONDITIONAL, par_type::SEQ_ARRAY, maybeUse}
37 , RegisterIfTableMember{this}
40 for (std::size_t i{}; i != N; ++i) {
41 value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
43 NameStackRegistry::end_of_ctor();
46 // c'tors that support defaults
47 template<typename T, std::size_t N>
48 Sequence<T,N>::Sequence(Name&& name, default_type const& defaults)
49 : Sequence(std::move(name), Comment(""), defaults)
52 template<typename T, std::size_t N>
53 Sequence<T,N>::Sequence(Name&& name,
55 default_type const& defaults)
56 : SequenceBase{std::move(name), std::move(comment), par_style::DEFAULT, par_type::SEQ_ARRAY, detail::AlwaysUse()}
57 , RegisterIfTableMember{this}
61 for (auto const & arg : defaults) {
62 value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i), arg);
65 NameStackRegistry::end_of_ctor();
69 template<typename T, std::size_t N>
70 Sequence<T,N>::Sequence(Name&& name,
72 std::function<bool()> maybeUse,
73 default_type const& defaults)
74 : SequenceBase{std::move(name), std::move(comment), par_style::DEFAULT_CONDITIONAL, par_type::SEQ_ARRAY, maybeUse}
75 , RegisterIfTableMember{this}
79 for (auto const & arg : defaults) {
80 value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i), arg);
83 NameStackRegistry::end_of_ctor();
86 //==================================================================
87 // e.g. Sequence<int> ====> std::vector<int>
90 Sequence<T,-1ull>::Sequence(Name&& name)
91 : Sequence{std::move(name), Comment("")}
95 Sequence<T,-1ull>::Sequence(Name&& name, Comment&& comment)
96 : SequenceBase{std::move(name), std::move(comment), par_style::REQUIRED, par_type::SEQ_VECTOR, detail::AlwaysUse()}
97 , RegisterIfTableMember{this}
98 , value_{{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
100 NameStackRegistry::end_of_ctor();
104 Sequence<T,-1ull>::Sequence(Name&& name, Comment&& comment, std::function<bool()> maybeUse)
105 : SequenceBase{std::move(name), std::move(comment), par_style::REQUIRED_CONDITIONAL, par_type::SEQ_VECTOR, maybeUse}
106 , RegisterIfTableMember{this}
107 , value_{{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
109 NameStackRegistry::end_of_ctor();
112 // c'tors that support defaults
114 Sequence<T,-1ull>::Sequence(Name&& name, default_type const& defaults)
115 : Sequence{std::move(name), Comment(""), defaults}
119 Sequence<T,-1ull>::Sequence (Name&& name, Comment&& comment, default_type const& defaults)
120 : SequenceBase{std::move(name), std::move(comment), par_style::DEFAULT, par_type::SEQ_VECTOR, detail::AlwaysUse()}
121 , RegisterIfTableMember{this}
123 static_assert(!tt::is_table<T>::value, NO_DEFAULTS_FOR_TABLE);
125 for (auto const& t : defaults) {
126 value_.emplace_back(new tt::fhicl_type<T>{Name::sequence_element(i), t});
129 NameStackRegistry::end_of_ctor();
134 Sequence<T,-1ull>::Sequence (Name&& name, Comment&& comment, std::function<bool()> maybeUse, default_type const& defaults)
135 : SequenceBase{std::move(name), std::move(comment), par_style::DEFAULT_CONDITIONAL, par_type::SEQ_VECTOR, maybeUse}
136 , RegisterIfTableMember{this}
138 static_assert(!tt::is_table<T>::value, NO_DEFAULTS_FOR_TABLE);
140 for (auto const& t : defaults) {
141 value_.emplace_back(new tt::fhicl_type<T>{Name::sequence_element(i), t});
144 NameStackRegistry::end_of_ctor();