LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
OptionalSequence.icc
Go to the documentation of this file.
1 #include "fhiclcpp/detail/printing_helpers.h"
2 
3 namespace fhicl {
4 
5  //==================================================================
6  // e.g. OptionalSequence<int,4> ====> std::array<int,4>
7  //
8  template<typename T, std::size_t N>
9  OptionalSequence<T,N>::OptionalSequence(Name&& name)
10  : OptionalSequence{std::move(name), Comment("")}
11  {}
12 
13 
14  template<typename T, std::size_t N>
15  OptionalSequence<T,N>::OptionalSequence(Name&& name,
16  Comment&& comment)
17  : SequenceBase{std::move(name), std::move(comment), par_style::OPTIONAL, par_type::SEQ_ARRAY, detail::AlwaysUse()}
18  , RegisterIfTableMember{this}
19  , value_{{nullptr}}
20  {
21  for (std::size_t i{}; i != N; ++i) {
22  value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i) );
23  }
24  NameStackRegistry::end_of_ctor();
25  }
26 
27  template<typename T, std::size_t N>
28  OptionalSequence<T,N>::OptionalSequence(Name&& name,
29  Comment&& comment,
30  std::function<bool()> maybeUse)
31  : SequenceBase{std::move(name), std::move(comment), par_style::OPTIONAL_CONDITIONAL, par_type::SEQ_ARRAY, maybeUse}
32  , RegisterIfTableMember{this}
33  , value_{{nullptr}}
34  {
35  for (std::size_t i{}; i != N; ++i) {
36  value_.at(i) = std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i) );
37  }
38  NameStackRegistry::end_of_ctor();
39  }
40 
41  template<typename T, std::size_t N>
42  void
43  OptionalSequence<T,N>::do_set_value(fhicl::ParameterSet const&,
44  bool const /*trimParents*/)
45  {
46  // We do not explicitly set the sequence values here as the
47  // individual elements are set one at a time. However, this
48  // function is reached in the ValidateThenSet algorithm if the
49  // optional parameter is present. Otherwise, this override is
50  // skipped.
51  has_value_ = true;
52  }
53 
54 
55  //==================================================================
56  // e.g. OptionalSequence<int> ====> std::vector<int>
57  //
58 
59  template<typename T>
60  OptionalSequence<T,-1ull>::OptionalSequence(Name&& name)
61  : OptionalSequence{std::move(name), Comment("")}
62  {}
63 
64  template<typename T>
65  OptionalSequence<T,-1ull>::OptionalSequence(Name&& name,
66  Comment&& comment)
67  : SequenceBase{std::move(name), std::move(comment), par_style::OPTIONAL, par_type::SEQ_VECTOR, detail::AlwaysUse()}
68  , RegisterIfTableMember{this}
69  {
70  value_.emplace_back(new tt::fhicl_type<T>{Name::sequence_element(0ul)});
71  NameStackRegistry::end_of_ctor();
72  }
73 
74  template<typename T>
75  OptionalSequence<T,-1ull>::OptionalSequence(Name&& name,
76  Comment&& comment,
77  std::function<bool()> maybeUse)
78  : SequenceBase{std::move(name), std::move(comment), par_style::OPTIONAL_CONDITIONAL, par_type::SEQ_VECTOR, maybeUse}
79  , RegisterIfTableMember{this}
80  {
81  value_.emplace_back(new tt::fhicl_type<T>{Name::sequence_element(0ul)});
82  NameStackRegistry::end_of_ctor();
83  }
84 
85  template<typename T>
86  void
87  OptionalSequence<T,-1ull>::do_set_value(fhicl::ParameterSet const&,
88  bool const /*trimParents*/)
89  {
90  // We do not explicitly set the sequence values here as the
91  // individual elements are set one at a time. However, this
92  // function is reached in the ValidateThenSet algorithm if the
93  // optional parameter is present. Otherwise, this override is
94  // skipped.
95  has_value_ = true;
96  }
97 
98 }
99 
100 // Local variables:
101 // mode: c++
102 // End: