LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
extended_value.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // extended_value
4 //
5 // ======================================================================
6 
8 
9 #include <regex>
10 
11 using boost::any_cast;
12 using std::string;
13 
14 // ----------------------------------------------------------------------
15 
16 std::string
18 {
20  return "";
21 
22  switch (tag) {
23 
24  case NIL:
25  case BOOL:
26  case NUMBER:
27  case STRING: {
28  return any_cast<atom_t>(value);
29  }
30 
31  case COMPLEX: {
32  complex_t c = any_cast<complex_t>(value);
33  return '(' + c.first + ',' + c.second + ')';
34  }
35 
36  case SEQUENCE: {
37  sequence_t q = any_cast<sequence_t>(value);
38  string s("[");
39  string sep;
40  for (sequence_t::const_iterator b = q.begin(), e = q.end(), it = b;
41  it != e;
42  ++it) {
43  s.append(sep).append(it->to_string());
44  sep = ",";
45  }
46  return s + ']';
47  }
48 
49  case TABLE: {
50  table_t t = any_cast<table_t>(value);
51  string s("{");
52  string sep;
53  for (table_t::const_iterator b = t.cbegin(), e = t.cend(), it = b;
54  it != e;
55  ++it) {
56  s.append(sep).append(it->first + ':' + it->second.to_string());
57  sep = " ";
58  }
59  return s + '}';
60  }
61 
62  case TABLEID: {
63  return string("@id::") + any_cast<atom_t>(value);
64  }
65 
66  case UNKNOWN:
67  default: {
68  return "";
69  }
70 
71  }; // switch
72 
73 } // to_string()
74 
75 // ----------------------------------------------------------------------
76 
77 void
78 fhicl::extended_value::set_prolog(bool new_prolog_state)
79 {
80  in_prolog = new_prolog_state;
81 
82  switch (tag) {
83 
84  case NIL:
85  case BOOL:
86  case NUMBER:
87  case STRING:
88  case COMPLEX:
89  case TABLEID: {
90  break;
91  }
92 
93  case SEQUENCE: {
94  sequence_t& q = any_cast<sequence_t&>(value);
95  for (sequence_t::iterator it = q.begin(), e = q.end(); it != e; ++it) {
96  it->set_prolog(new_prolog_state);
97  }
98  break;
99  }
100 
101  case TABLE: {
102  table_t& t = any_cast<table_t&>(value);
103  for (table_t::iterator it = t.begin(), e = t.end(); it != e; ++it) {
104  it->second.set_prolog(new_prolog_state);
105  }
106  break;
107  }
108 
109  case UNKNOWN:
110  default: {
111  break;
112  }
113 
114  }; // switch
115 
116 } // set_prolog()
117 
118 std::string
120 {
121  std::string result;
122  static std::regex const splitRE("(.*):([0-9-]*)");
123  std::smatch m;
124  if (std::regex_match(src_info, m, splitRE)) {
125  result =
126  std::string("line ") + m[2].str() + " of file \"" + m[1].str() + '"';
127  } else {
128  result = "<unknown>";
129  }
130  return result;
131 }
132 
133 // ======================================================================
Float_t s
Definition: plot.C:23
iterator begin()
Definition: stdmap_shims.h:155
bool isSnippetMode(bool m)
Definition: parse_shims.cc:9
intermediate_table::iterator iterator
std::pair< std::string, std::string > complex_t
iterator end()
Definition: stdmap_shims.h:177
intermediate_table::const_iterator const_iterator
std::vector< extended_value > sequence_t
const_iterator cbegin() const
Definition: stdmap_shims.h:171
std::string to_string() const
std::string pretty_src_info() const
const_iterator cend() const
Definition: stdmap_shims.h:193
Float_t e
Definition: plot.C:34
void set_prolog(bool new_prolog_state)