LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
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 
73 
74 #endif /* fhiclcpp_types_OptionalAtom_h */
75 
76 // Local variables:
77 // mode: c++
78 // End:
#define NO_DELEGATED_PARAMETERS
std::string get_stringified_value() const override
void do_set_value(fhicl::ParameterSet const &, bool const) override
parameter set interface
#define NO_STD_CONTAINERS
bool operator()(T &value) const
Definition: OptionalAtom.h:43
#define NO_NESTED_TABLE_FRAGMENTS
std::string value(boost::any const &)
std::string name() const
Definition: ParameterBase.h:49
bool hasValue() const
Definition: OptionalAtom.h:53
#define NO_NESTED_FHICL_TYPES_IN_ATOM
std::string comment() const
Definition: ParameterBase.h:54