LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
Sequence.icc
Go to the documentation of this file.
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"
8 
9 #include <iostream>
10 #include <string>
11 
12 namespace fhicl {
13 
14  //==================================================================
15  // e.g. Sequence<int,4> ====> std::array<int,4>
16  //
17 
18  template<typename T, std::size_t N>
19  Sequence<T,N>::Sequence(Name&& name)
20  : Sequence{std::move(name), Comment("")} {}
21 
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}
26  , value_{{nullptr}}
27  {
28  for (std::size_t i{}; i != N; ++i) {
29  value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
30  }
31  NameStackRegistry::end_of_ctor();
32  }
33 
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}
38  , value_{{nullptr}}
39  {
40  for (std::size_t i{}; i != N; ++i) {
41  value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
42  }
43  NameStackRegistry::end_of_ctor();
44  }
45 
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)
50  {}
51 
52  template<typename T, std::size_t N>
53  Sequence<T,N>::Sequence(Name&& name,
54  Comment&& comment,
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}
58  , value_{{nullptr}}
59  {
60  std::size_t i{};
61  for (auto const & arg : defaults) {
62  value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i), arg);
63  ++i;
64  }
65  NameStackRegistry::end_of_ctor();
66  }
67 
68 
69  template<typename T, std::size_t N>
70  Sequence<T,N>::Sequence(Name&& name,
71  Comment&& comment,
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}
76  , value_{{nullptr}}
77  {
78  std::size_t i{};
79  for (auto const & arg : defaults) {
80  value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i), arg);
81  ++i;
82  }
83  NameStackRegistry::end_of_ctor();
84  }
85 
86  //==================================================================
87  // e.g. Sequence<int> ====> std::vector<int>
88  //
89  template<typename T>
90  Sequence<T,-1ull>::Sequence(Name&& name)
91  : Sequence{std::move(name), Comment("")}
92  {}
93 
94  template<typename T>
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))}}
99  {
100  NameStackRegistry::end_of_ctor();
101  }
102 
103  template<typename T>
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))}}
108  {
109  NameStackRegistry::end_of_ctor();
110  }
111 
112  // c'tors that support defaults
113  template<typename T>
114  Sequence<T,-1ull>::Sequence(Name&& name, default_type const& defaults)
115  : Sequence{std::move(name), Comment(""), defaults}
116  {}
117 
118  template<typename T>
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}
122  {
123  static_assert(!tt::is_table<T>::value, NO_DEFAULTS_FOR_TABLE);
124  std::size_t i{};
125  for (auto const& t : defaults) {
126  value_.emplace_back(new tt::fhicl_type<T>{Name::sequence_element(i), t});
127  ++i;
128  }
129  NameStackRegistry::end_of_ctor();
130  }
131 
132 
133  template<typename T>
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}
137  {
138  static_assert(!tt::is_table<T>::value, NO_DEFAULTS_FOR_TABLE);
139  std::size_t i{};
140  for (auto const& t : defaults) {
141  value_.emplace_back(new tt::fhicl_type<T>{Name::sequence_element(i), t});
142  ++i;
143  }
144  NameStackRegistry::end_of_ctor();
145  }
146 
147 }
148 
149 // Local variables:
150 // mode: c++
151 // End: