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...> DelegatedParameter
18 
19 
20  All concrete Optional* fhiclcpp types also inherit from the
21  corresponding base classes (e.g. OptionalAtom<T> inherits from
22  AtomBase, not OptionalAtomBase). The design is meant to closely
23  follow the classification of FHiCL values, as described in the FHiCL
24  language quick start guide.
25 */
26 
27 #include "fhiclcpp/fwd.h"
31 
32 namespace fhicl::detail {
33 
34  //========================================================
35  class ParameterBase {
36  public:
37  std::string const&
38  key() const
39  {
40  return mdata_.key();
41  }
42  std::string const&
43  name() const
44  {
45  return mdata_.name();
46  }
47  std::string const&
48  comment() const
49  {
50  return mdata_.comment();
51  }
52  bool
53  has_default() const
54  {
55  return mdata_.has_default();
56  }
57  bool
58  is_optional() const
59  {
60  return mdata_.is_optional();
61  }
62  bool
64  {
65  return mdata_.is_conditional();
66  }
67  par_type
69  {
70  return mdata_.type();
71  }
72  bool
73  should_use() const
74  {
75  return maybeUse_();
76  }
77 
79  Comment const& comment,
80  par_style const vt,
81  par_type const type,
82  std::function<bool()> maybeUse = AlwaysUse())
83  : mdata_{name, comment, vt, type}, maybeUse_{maybeUse}
84  {}
85 
86  virtual ~ParameterBase() = default;
87 
88  // Modifiers
89  void
91  {
92  do_set_value(ps);
93  }
94  bool
96  {
97  return do_preset_value(ps);
98  }
99  void
101  {
102  mdata_.set_par_style(vt);
103  }
104 
105  private:
106  virtual bool do_preset_value(fhicl::ParameterSet const&) { return false; }
107  virtual void do_set_value(fhicl::ParameterSet const&) = 0;
108 
110  std::function<bool()> maybeUse_;
111  };
112 }
113 
114 #endif /* fhiclcpp_types_detail_ParameterBase_h */
115 
116 // Local variables:
117 // mode: c++
118 // End:
std::string const & name() const
Definition: ParameterBase.h:43
void set_value(fhicl::ParameterSet const &ps)
Definition: ParameterBase.h:90
bool preset_value(fhicl::ParameterSet const &ps)
Definition: ParameterBase.h:95
std::string string
Definition: nybbler.cc:12
ParameterBase(Name const &name, Comment const &comment, par_style const vt, par_type const type, std::function< bool()> maybeUse=AlwaysUse())
Definition: ParameterBase.h:78
std::string const & name() const
std::function< bool()> AlwaysUse()
virtual void do_set_value(fhicl::ParameterSet const &)=0
par_type parameter_type() const
Definition: ParameterBase.h:68
static constexpr double ps
Definition: Units.h:99
std::string const & key() const
Definition: ParameterBase.h:38
std::function< bool()> maybeUse_
virtual ~ParameterBase()=default
std::string const & comment() const
std::string const & comment() const
Definition: ParameterBase.h:48
std::string const & key() const
virtual bool do_preset_value(fhicl::ParameterSet const &)
void set_par_style(par_style const vt)
void function(int client, int *resource, int parblock, int *test, int p)
void set_par_style(par_style const vt)