LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
extended_value.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_extended_value_h
2 #define fhiclcpp_extended_value_h
3 
4 // ======================================================================
5 //
6 // extended_value
7 //
8 // ======================================================================
9 
10 #include "fhiclcpp/Protection.h"
11 #include "fhiclcpp/fwd.h"
12 #include "fhiclcpp/stdmap_shims.h"
13 
14 #include <any>
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 // ----------------------------------------------------------------------
20 
21 namespace fhicl {
22  enum value_tag {
24  NIL,
32  };
33 }
34 
35 // ----------------------------------------------------------------------
36 
38 public:
39  using atom_t = std::string;
40  using complex_t = std::pair<std::string, std::string>;
41  using sequence_t = std::vector<extended_value>;
43 
46 
48  value_tag const tag,
49  std::any const value,
50  Protection const protection,
51  std::string src = {})
52  : in_prolog{in_prolog}
53  , tag{tag}
54  , value{value}
55  , src_info{std::move(src)}
56  , protection{protection}
57  {}
58 
59  extended_value(bool const in_prolog,
60  value_tag const tag,
61  std::any const value,
62  std::string src = {})
63  : in_prolog{in_prolog}, tag{tag}, value{value}, src_info{std::move(src)}
64  {}
65 
66  bool
67  is_a(value_tag const t) const noexcept
68  {
69  return t == tag;
70  }
71 
72  std::string to_string() const;
73 
74  void set_prolog(bool new_prolog_state);
75 
76  void
77  set_src_info(std::string const& src)
78  {
79  src_info = src;
80  }
81 
82  void
84  {
85  // See notes below.
86  protection = Protection::NONE;
87  }
88 
89  std::string pretty_src_info() const;
90 
91  operator atom_t() const { return std::any_cast<atom_t>(value); }
92  operator complex_t() const { return std::any_cast<complex_t>(value); }
93  operator sequence_t() const { return std::any_cast<sequence_t>(value); }
94  operator table_t() const { return std::any_cast<table_t>(value); }
95 
96  bool in_prolog{false};
98  std::any value{};
99  std::string src_info{};
100 
101  // Protection corresponds to the binding of a name to a value, and
102  // not the value per se. The protection data member is thus
103  // separate from the other data of this class but retained here for
104  // navigational convenience. Care must therefore be taken when
105  // implementing '@local::' (e.g.):
106  //
107  // x @protect_ignore: 14 // -> protection for x is PROTECT_IGNORE
108  // y: @local::x // -> protection for y should be NONE
109  //
110  // The reset_protection() member function is called while parsing y
111  // to ensure that x's protection does not propagate to y.
113 
114 }; // extended_value
115 
116 // ======================================================================
117 
118 #endif /* fhiclcpp_extended_value_h */
119 
120 // Local Variables:
121 // mode: c++
122 // End:
bool is_a(value_tag const t) const noexcept
extended_value(bool const in_prolog, value_tag const tag, std::any const value, Protection const protection, std::string src={})
std::pair< std::string, std::string > complex_t
Protection
Definition: Protection.h:7
void set_src_info(std::string const &src)
parameter set interface
std::vector< extended_value > sequence_t
shims::map< std::string, extended_value > table_t
extended_value(bool const in_prolog, value_tag const tag, std::any const value, std::string src={})
std::string to_string() const
std::string pretty_src_info() const
void set_prolog(bool new_prolog_state)