OptionalAtom.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_OptionalAtom_h
2 #define fhiclcpp_types_OptionalAtom_h
3 
5 #include "fhiclcpp/type_traits.h"
8 #include "fhiclcpp/types/Name.h"
15 
16 #include <sstream>
17 #include <string>
18 
19 namespace fhicl {
20 
21  //========================================================
22  template <typename T>
23  class OptionalAtom final : public detail::AtomBase,
24  private detail::RegisterIfTableMember {
25  public:
31 
32  //=====================================================
33  // User-friendly
34  // ... c'tors
35  explicit OptionalAtom(Name&& name);
36  explicit OptionalAtom(Name&& name, Comment&& comment);
37  explicit OptionalAtom(Name&& name,
38  Comment&& comment,
39  std::function<bool()> maybeUse);
40 
41  // ... Accessors
42  bool
43  operator()(T& value) const
44  {
45  if (has_value_) {
46  value = value_;
47  return true;
48  }
49  return false;
50  }
51 
52  bool
53  hasValue() const
54  {
55  return has_value_;
56  }
57 
58  // Expert-only
59  using value_type = T;
60 
61  OptionalAtom();
62 
63  private:
64  T value_{};
65  bool has_value_{false};
66 
67  std::string get_stringified_value() const override;
68  void do_set_value(fhicl::ParameterSet const&, bool const) override;
69  };
70 }
71 
72 #include "fhiclcpp/types/detail/OptionalAtom.icc"
73 
74 #endif /* fhiclcpp_types_OptionalAtom_h */
75 
76 // Local variables:
77 // mode: c++
78 // End:
const XML_Char * name
Definition: expat.h:151
#define NO_DELEGATED_PARAMETERS
std::string get_stringified_value() const override
const XML_Char int const XML_Char * value
Definition: expat.h:331
void do_set_value(fhicl::ParameterSet const &, bool const) override
#define NO_STD_CONTAINERS
bool operator()(T &value) const
Definition: OptionalAtom.h:43
#define NO_NESTED_TABLE_FRAGMENTS
bool hasValue() const
Definition: OptionalAtom.h:53
double T
Definition: Xdiff_gwt.C:5
#define NO_NESTED_FHICL_TYPES_IN_ATOM
std::string comment() const
Definition: ParameterBase.h:54
enum BeamMode string