9 #include "boost/algorithm/string.hpp" 20 using namespace fhicl;
59 return std::any_cast<
table_t const&>(ex_val.value).
begin();
65 return std::any_cast<
table_t const&>(ex_val.value).
end();
73 return std::any_cast<
table_t const&>(ex_val.value).
empty();
79 intermediate_table::insert(std::string
const& key,
82 std::any
const&
value)
90 auto found_val = pre_insert_(key, value);
91 bool result = (found_val !=
nullptr);
101 auto found_val = pre_insert_(key,
value);
102 bool result = (found_val !=
nullptr);
104 *found_val = std::move(
value);
112 intermediate_table::find(std::string
const& key)
const 115 for (
auto const& name : split(key)) {
117 }
else if (std::isdigit(name[0])) {
120 <<
"-- not a sequence (at part \"" << name <<
"\")";
122 unsigned i = std::atoi(name.c_str());
129 <<
"-- not a table (at part \"" << name <<
"\")";
130 auto const& t = std::any_cast<
table_t const&>(p->
value);
131 auto it = t.
find(name);
143 intermediate_table::exists(std::string
const& key)
const 146 for (
auto const& name : split(key)) {
148 }
else if (std::isdigit(name[0])) {
153 unsigned i = std::atoi(name.c_str());
162 auto const& t = std::any_cast<
table_t const&>(p->
value);
163 auto it = t.
find(name);
174 intermediate_table::erase(std::string
const& key,
bool const in_prolog)
180 auto t(std::any_cast<table_t>(&p->value));
182 auto const names = split(key);
184 (((it = t->find(names[0])) == t->end()) || it->second.in_prolog)) {
187 bool at_sequence(
false);
188 for (
auto const& name : names) {
190 }
else if (std::isdigit(name[0])) {
193 <<
"-- not a sequence (at part \"" << name <<
"\")";
194 auto& s = std::any_cast<
sequence_t&>(p->value);
195 unsigned i = std::atoi(name.c_str());
204 <<
"-- not a table (at part \"" << name <<
"\")";
206 t = std::any_cast<
table_t>(&p->value);
208 if (it == t->end()) {
212 auto prot = p->protection;
213 if (prot == Protection::PROTECT_ERROR) {
215 << ((name != key) ? (std::string(
"Part \"") + name +
216 "\" of specification to be erased\n") :
218 <<
'"' << name <<
"\" is protected on " << p->pretty_src_info()
220 }
else if (prot == Protection::PROTECT_IGNORE) {
228 if (it != t->end()) {
234 intermediate_table::pre_insert_(std::string
const& key,
238 auto& t = std::any_cast<
table_t&>(ex_val.value);
239 auto const names = split(key);
240 auto it = t.find(names[0]);
241 if (it != t.end() && it->second.in_prolog) {
245 auto located = locate_(key, value.
in_prolog);
246 if ((!located.first->is_a(
NIL)) &&
247 value.
protection > located.first->protection) {
249 <<
'"' << key <<
"\" cannot be assigned with increased protection" 250 <<
"\n(previous definition on " << located.first->pretty_src_info()
253 return located.second ? located.first :
nullptr;
256 std::pair<extended_value*, bool>
257 intermediate_table::locate_(std::string
const& key,
bool const in_prolog)
259 std::pair<extended_value*, bool> result(
nullptr,
true);
262 for (
auto const& name : split(key)) {
264 }
else if (std::isdigit(name[0])) {
270 <<
"-- not a sequence (at part \"" << name <<
"\")";
272 unsigned i = std::atoi(name.c_str());
273 while (s.size() <= i) {
274 s.push_back(nil_item());
285 <<
"-- not a table (at part \"" << name <<
"\")";
289 p = &t.emplace(name, nil_item()).first->second;
294 if (prot == Protection::PROTECT_ERROR) {
296 << ((name != key) ? (std::string(
"Part \"") + name +
297 "\" of specification to be overwritten\n") :
299 <<
'"' << key <<
"\" is protected on " << p->
pretty_src_info() <<
'\n';
300 }
else if (prot == Protection::PROTECT_IGNORE) {
301 result.second =
false;
309 std::vector<std::string>
310 intermediate_table::split(std::string
const& key)
313 std::vector<std::string> result;
314 boost::algorithm::split(result, key, boost::algorithm::is_any_of(splitChars));
intermediate_table::complex_t complex_t
bool is_a(value_tag const t) const noexcept
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
fhicl::extended_value::sequence_t sequence_t
intermediate_table::atom_t atom_t
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::string pretty_src_info() const
bool isSnippetMode(bool m=false) noexcept
void set_prolog(bool new_prolog_state)
iterator find(Key const &key)
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.