ParameterBase.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_detail_ParameterBase_h
2 #define fhiclcpp_types_detail_ParameterBase_h
3 
4 /*
5  ParameterBase is the most fundamental base class for all fhiclcpp
6  types. The taxonomy is:
7 
8 
9  ParameterBase
10  / | \ \____________________________________
11  / | \___________________ \
12  / | \ \
13  / | \ \
14  AtomBase TableBase SequenceBase DelegateBase
15  | | / | \ \
16  | | / | \ \
17  Atom<T> Table<T> Sequence<T,SZ> Sequence<T> Tuple<T...>
18  DelegatedParameter
19 
20 
21  All concrete Optional* fhiclcpp types also inherit from the
22  corresponding base classes (e.g. OptionalAtom<T> inherits from
23  AtomBase, not OptionalAtomBase). The design is meant to closely
24  follow the classification of FHiCL values, as described in the FHiCL
25  language quick start guide.
26 */
27 
31 
32 #include <string>
33 
34 namespace fhicl {
35 
36  class ParameterSet;
37 
38  namespace detail {
39 
40  //========================================================
41  class ParameterBase {
42  public:
44  key() const
45  {
46  return mdata_.key();
47  }
49  name() const
50  {
51  return mdata_.name();
52  }
54  comment() const
55  {
56  return mdata_.comment();
57  }
58  bool
59  has_default() const
60  {
61  return mdata_.has_default();
62  }
63  bool
64  is_optional() const
65  {
66  return mdata_.is_optional();
67  }
68  bool
70  {
71  return mdata_.is_conditional();
72  }
73  par_type
75  {
76  return mdata_.type();
77  }
78  bool
79  should_use() const
80  {
81  return maybeUse_();
82  }
83 
85  Comment const& comment,
86  par_style const vt,
87  par_type const type,
88  std::function<bool()> maybeUse = AlwaysUse())
89  : mdata_{name, comment, vt, type}, maybeUse_{maybeUse}
90  {}
91 
92  virtual ~ParameterBase() = default;
93 
94  // Modifiers
95  void
96  set_value(fhicl::ParameterSet const& ps, bool trimParents)
97  {
98  do_set_value(ps, trimParents);
99  }
100  void
102  {
103  mdata_.set_par_style(vt);
104  }
105  void
107  {
108  mdata_.set_key(key);
109  }
110 
111  private:
112  virtual void do_set_value(fhicl::ParameterSet const&,
113  bool trimParents) = 0;
114 
116  std::function<bool()> maybeUse_;
117  };
118  }
119 }
120 
121 #endif /* fhiclcpp_types_detail_ParameterBase_h */
122 
123 // Local variables:
124 // mode: c++
125 // End:
const XML_Char * name
Definition: expat.h:151
ParameterBase(Name const &name, Comment const &comment, par_style const vt, par_type const type, std::function< bool()> maybeUse=AlwaysUse())
Definition: ParameterBase.h:84
std::function< bool()> AlwaysUse()
virtual void do_set_value(fhicl::ParameterSet const &, bool trimParents)=0
par_type parameter_type() const
Definition: ParameterBase.h:74
std::function< bool()> maybeUse_
virtual ~ParameterBase()=default
void set_value(fhicl::ParameterSet const &ps, bool trimParents)
Definition: ParameterBase.h:96
void set_key(std::string const &key)
std::string name() const
Definition: ParameterBase.h:49
void set_par_style(par_style const vt)
void set_key(std::string const &key)
std::string key() const
Definition: ParameterBase.h:44
void set_par_style(par_style const vt)
std::string comment() const
Definition: ParameterBase.h:54
enum BeamMode string