LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
OptionalAtom.icc
Go to the documentation of this file.
1 #include "fhiclcpp/detail/printing_helpers.h"
2 #include "fhiclcpp/types/detail/strip_containing_names.h"
3 
4 namespace fhicl {
5 
6  template <typename T>
7  OptionalAtom<T>::OptionalAtom(Name&& name)
8  : OptionalAtom<T>::OptionalAtom(std::move(name), Comment(""))
9  {}
10 
11  template <typename T>
12  OptionalAtom<T>::OptionalAtom(Name&& name,
13  Comment&& comment )
14  : AtomBase{std::move(name), std::move(comment), par_style::OPTIONAL, detail::AlwaysUse()}
15  , RegisterIfTableMember{this}
16  {
17  NameStackRegistry::end_of_ctor();
18  }
19 
20  template <typename T>
21  OptionalAtom<T>::OptionalAtom(Name&& name,
22  Comment&& comment,
23  std::function<bool()> maybeUse)
24  : AtomBase{std::move(name), std::move(comment), par_style::OPTIONAL_CONDITIONAL, maybeUse}
25  , RegisterIfTableMember{this}
26  {
27  NameStackRegistry::end_of_ctor();
28  }
29 
30  template <typename T>
31  std::string
32  OptionalAtom<T>::get_stringified_value() const
33  {
34  std::stringstream oss;
35  if (has_value_) {
36  using namespace detail::yes_defaults;
37  oss << maybe_quotes<T>(value_) ;
38  }
39  else {
40  using namespace detail::no_defaults;
41  oss << expected_types<T>();
42  }
43  return oss.str();
44  }
45 
46  template <typename T>
47  void
48  OptionalAtom<T>::do_set_value(fhicl::ParameterSet const& pset, bool const trimParent)
49  {
50  std::string const& rkey = key();
51  std::string const& key = trimParent ? detail::strip_first_containing_name(rkey) : rkey;
52  has_value_ = pset.get_if_present<T>(key, value_);
53  }
54 
55 }
56 
57 // Local variables:
58 // mode: c++
59 // End: