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 "boost/any.hpp"
11 #include "fhiclcpp/Protection.h"
12 #include "fhiclcpp/fwd.h"
13 #include "stdmap_shims.h"
14 
15 #include <map>
16 #include <string>
17 #include <vector>
18 
19 // ----------------------------------------------------------------------
20 
21 namespace fhicl {
22  enum value_tag {
24  NIL,
32  };
33 }
34 
35 // ----------------------------------------------------------------------
36 
38 public:
40  using complex_t = std::pair<std::string, std::string>;
41  using sequence_t = std::vector<extended_value>;
43 
44  extended_value() = default;
45 
47  value_tag const tag,
48  boost::any const value,
49  Protection const protection,
50  std::string const& src = {})
51  : in_prolog{in_prolog}
52  , tag{tag}
53  , value{value}
54  , src_info{src}
55  , protection{protection}
56  {}
57 
58  extended_value(bool const in_prolog,
59  value_tag const tag,
60  boost::any const value,
61  std::string const& src = {})
62  : in_prolog{in_prolog}, tag{tag}, value{value}, src_info{src}
63  {}
64 
65  bool
66  is_a(value_tag t) const
67  {
68  return t == tag;
69  }
70 
71  std::string to_string() const;
72 
73  void set_prolog(bool new_prolog_state);
74 
75  void
77  {
78  src_info = src;
79  }
80 
82 
83  operator atom_t() const { return boost::any_cast<atom_t>(value); }
84 
85  operator complex_t() const { return boost::any_cast<complex_t>(value); }
86 
87  operator sequence_t() const { return boost::any_cast<sequence_t>(value); }
88 
89  operator table_t() const { return boost::any_cast<table_t>(value); }
90 
91  bool in_prolog{false};
93  boost::any value{};
96 
97 }; // extended_value
98 
99 // ======================================================================
100 
101 #endif /* fhiclcpp_extended_value_h */
102 
103 // Local Variables:
104 // mode: c++
105 // End:
std::pair< std::string, std::string > complex_t
Protection
Definition: Protection.h:7
const XML_Char int const XML_Char * value
Definition: expat.h:331
extended_value(bool const in_prolog, value_tag const tag, boost::any const value, Protection const protection, std::string const &src={})
void set_src_info(std::string const &src)
std::vector< extended_value > sequence_t
bool is_a(value_tag t) const
shims::map< std::string, extended_value > table_t
extended_value(bool const in_prolog, value_tag const tag, boost::any const value, std::string const &src={})
std::string to_string() const
std::string pretty_src_info() const
void set_prolog(bool new_prolog_state)
enum BeamMode string