LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::extended_value Class Reference

#include "extended_value.h"

Public Types

using atom_t = std::string
 
using complex_t = std::pair< std::string, std::string >
 
using sequence_t = std::vector< extended_value >
 
using table_t = shims::map< std::string, extended_value >
 

Public Member Functions

 extended_value ()
 
 ~extended_value ()
 
 extended_value (bool const in_prolog, value_tag const tag, std::any const value, Protection const protection, std::string src={})
 
 extended_value (bool const in_prolog, value_tag const tag, std::any const value, std::string src={})
 
bool is_a (value_tag const t) const noexcept
 
std::string to_string () const
 
void set_prolog (bool new_prolog_state)
 
void set_src_info (std::string const &src)
 
void reset_protection ()
 
std::string pretty_src_info () const
 
 operator atom_t () const
 
 operator complex_t () const
 
 operator sequence_t () const
 
 operator table_t () const
 

Public Attributes

bool in_prolog {false}
 
value_tag tag {UNKNOWN}
 
std::any value {}
 
std::string src_info {}
 
Protection protection {Protection::NONE}
 

Detailed Description

Definition at line 37 of file extended_value.h.

Member Typedef Documentation

using fhicl::extended_value::atom_t = std::string

Definition at line 39 of file extended_value.h.

using fhicl::extended_value::complex_t = std::pair<std::string, std::string>

Definition at line 40 of file extended_value.h.

Definition at line 41 of file extended_value.h.

Definition at line 42 of file extended_value.h.

Constructor & Destructor Documentation

fhicl::extended_value::extended_value ( )
default
fhicl::extended_value::~extended_value ( )
default
fhicl::extended_value::extended_value ( bool const  in_prolog,
value_tag const  tag,
std::any const  value,
Protection const  protection,
std::string  src = {} 
)
inline

Definition at line 47 of file extended_value.h.

References src_info.

51  {})
53  , tag{tag}
54  , value{value}
55  , src_info{std::move(src)}
57  {}
fhicl::extended_value::extended_value ( bool const  in_prolog,
value_tag const  tag,
std::any const  value,
std::string  src = {} 
)
inline

Definition at line 59 of file extended_value.h.

References src_info.

62  {})
63  : in_prolog{in_prolog}, tag{tag}, value{value}, src_info{std::move(src)}
64  {}

Member Function Documentation

bool fhicl::extended_value::is_a ( value_tag const  t) const
inlinenoexcept
fhicl::extended_value::operator atom_t ( ) const
inline

Definition at line 91 of file extended_value.h.

References value.

91 { return std::any_cast<atom_t>(value); }
intermediate_table::atom_t atom_t
fhicl::extended_value::operator complex_t ( ) const
inline

Definition at line 92 of file extended_value.h.

References value.

92 { return std::any_cast<complex_t>(value); }
intermediate_table::complex_t complex_t
fhicl::extended_value::operator sequence_t ( ) const
inline

Definition at line 93 of file extended_value.h.

References value.

93 { return std::any_cast<sequence_t>(value); }
fhicl::extended_value::sequence_t sequence_t
fhicl::extended_value::operator table_t ( ) const
inline

Definition at line 94 of file extended_value.h.

References value.

94 { return std::any_cast<table_t>(value); }
std::string fhicl::extended_value::pretty_src_info ( ) const

Definition at line 120 of file extended_value.cc.

References src_info.

Referenced by fhicl::intermediate_table::locate_(), and reset_protection().

121 {
122  std::string result;
123  static std::regex const splitRE("(.*):([0-9-]*)");
124  std::smatch m;
125  if (std::regex_match(src_info, m, splitRE)) {
126  result =
127  std::string("line ") + m[2].str() + " of file \"" + m[1].str() + '"';
128  } else {
129  result = "<unknown>";
130  }
131  return result;
132 }
void fhicl::extended_value::reset_protection ( )
inline

Definition at line 83 of file extended_value.h.

References fhicl::NONE, and pretty_src_info().

84  {
85  // See notes below.
87  }
void fhicl::extended_value::set_prolog ( bool  new_prolog_state)

Definition at line 79 of file extended_value.cc.

References fhicl::BOOL, fhicl::COMPLEX, e, in_prolog, fhicl::NIL, fhicl::NUMBER, fhicl::SEQUENCE, fhicl::STRING, fhicl::TABLE, fhicl::TABLEID, tag, fhicl::UNKNOWN, and value.

Referenced by is_a(), and fhicl::intermediate_table::locate_().

80 {
81  in_prolog = new_prolog_state;
82 
83  switch (tag) {
84 
85  case NIL:
86  case BOOL:
87  case NUMBER:
88  case STRING:
89  case COMPLEX:
90  case TABLEID: {
91  break;
92  }
93 
94  case SEQUENCE: {
95  auto& q = any_cast<sequence_t&>(value);
96  for (auto& e : q) {
97  e.set_prolog(new_prolog_state);
98  }
99  break;
100  }
101 
102  case TABLE: {
103  auto& t = any_cast<table_t&>(value);
104  for (auto& pr : t) {
105  pr.second.set_prolog(new_prolog_state);
106  }
107  break;
108  }
109 
110  case UNKNOWN:
111  default: {
112  break;
113  }
114 
115  }; // switch
116 
117 } // set_prolog()
fhicl::extended_value::sequence_t sequence_t
Float_t e
Definition: plot.C:35
void fhicl::extended_value::set_src_info ( std::string const &  src)
inline

Definition at line 77 of file extended_value.h.

References src_info.

78  {
79  src_info = src;
80  }
std::string fhicl::extended_value::to_string ( ) const

Definition at line 22 of file extended_value.cc.

References fhicl::BOOL, fhicl::COMPLEX, in_prolog, shims::isSnippetMode(), fhicl::NIL, fhicl::NUMBER, fhicl::SEQUENCE, fhicl::STRING, fhicl::TABLE, fhicl::TABLEID, tag, fhicl::UNKNOWN, and value.

Referenced by is_a().

23 {
25  return "";
26 
27  switch (tag) {
28 
29  case NIL:
30  case BOOL:
31  case NUMBER:
32  case STRING: {
33  return any_cast<atom_t>(value);
34  }
35 
36  case COMPLEX: {
37  auto c = any_cast<complex_t>(value);
38  return '(' + c.first + ',' + c.second + ')';
39  }
40 
41  case SEQUENCE: {
42  auto q = any_cast<sequence_t>(value);
43  string s("[");
44  string sep;
45  for (auto const& v : q) {
46  s.append(sep).append(v.to_string());
47  sep = ",";
48  }
49  return s + ']';
50  }
51 
52  case TABLE: {
53  auto t = any_cast<table_t>(value);
54  string s("{");
55  string sep;
56  for (auto const& pr : t) {
57  s.append(sep).append(pr.first + ':' + pr.second.to_string());
58  sep = " ";
59  }
60  return s + '}';
61  }
62 
63  case TABLEID: {
64  return string("@id::") + any_cast<atom_t>(value);
65  }
66 
67  case UNKNOWN:
68  default: {
69  return "";
70  }
71 
72  }; // switch
73 
74 } // to_string()
intermediate_table::complex_t complex_t
fhicl::extended_value::sequence_t sequence_t
intermediate_table::atom_t atom_t
bool isSnippetMode(bool m=false) noexcept

Member Data Documentation

bool fhicl::extended_value::in_prolog {false}
Protection fhicl::extended_value::protection {Protection::NONE}
std::string fhicl::extended_value::src_info {}

Definition at line 99 of file extended_value.h.

Referenced by extended_value(), pretty_src_info(), and set_src_info().

value_tag fhicl::extended_value::tag {UNKNOWN}

Definition at line 97 of file extended_value.h.

Referenced by fhicl::detail::encode(), is_a(), set_prolog(), and to_string().


The documentation for this class was generated from the following files: