LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Atom.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  Atom<T>::Atom(Name&& name,
8  Comment&& comment)
9  : AtomBase{std::move(name), std::move(comment), par_style::REQUIRED, detail::AlwaysUse()}
10  , RegisterIfTableMember{this}
11  , value_{std::make_shared<T>()}
12  {
13  NameStackRegistry::end_of_ctor();
14  }
15 
16  template <typename T>
17  Atom<T>::Atom(Name&& name,
18  Comment&& comment,
19  std::function<bool()> maybeUse)
20  : AtomBase{std::move(name), std::move(comment), par_style::REQUIRED_CONDITIONAL, maybeUse}
21  , RegisterIfTableMember{this}
22  , value_{std::make_shared<T>()}
23  {
24  NameStackRegistry::end_of_ctor();
25  }
26 
27  template <typename T>
28  Atom<T>::Atom(Name&& name,
29  Comment&& comment,
30  T const& dflt_value)
31  : AtomBase{std::move(name), std::move(comment), par_style::DEFAULT, detail::AlwaysUse()}
32  , RegisterIfTableMember{this}
33  , value_{std::make_shared<T>(dflt_value)}
34  {
35  NameStackRegistry::end_of_ctor();
36  }
37 
38  template <typename T>
39  Atom<T>::Atom(Name&& name,
40  Comment&& comment,
41  std::function<bool()> maybeUse,
42  T const& dflt_value)
43  : AtomBase{std::move(name), std::move(comment), par_style::DEFAULT_CONDITIONAL, maybeUse}
44  , RegisterIfTableMember{this}
45  , value_{std::make_shared<T>(dflt_value)}
46  {
47  NameStackRegistry::end_of_ctor();
48  }
49 
50  template <typename T>
51  Atom<T>::Atom(Name&& name)
52  : Atom{std::move(name), Comment("")}
53  {}
54 
55  template <typename T>
56  Atom<T>::Atom(Name&& name, T const& dflt_value)
57  : Atom{std::move(name), Comment(""), dflt_value}
58  {}
59 
60  template <typename T>
61  std::string
62  Atom<T>::get_stringified_value() const
63  {
64  std::stringstream oss;
65  if (has_default()) {
66  using namespace detail::yes_defaults;
67  oss << maybe_quotes<T>(*value_) ;
68  }
69  else {
70  using namespace detail::no_defaults;
71  oss << expected_types<T>();
72  }
73  return oss.str();
74  }
75 
76  template <typename T>
77  void
78  Atom<T>::do_set_value(fhicl::ParameterSet const& pset, bool const trimParent)
79  {
80  std::string const& rkey = key();
81  std::string const& key = trimParent ? detail::strip_first_containing_name(rkey) : rkey;
82 
83  if (has_default())
84  pset.get_if_present<T>(key, *value_);
85  else
86  value_ = std::make_shared<T>(pset.get<T>(key));
87  }
88 
89 }
90 
91 // Local variables:
92 // mode: c++
93 // End: