LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
NameStackRegistry.cc
Go to the documentation of this file.
2 #include "fhiclcpp/exception.h"
4 
5 #include <numeric>
6 #include <regex>
7 
8 namespace {
9  std::regex const re_sequence_element{R"(\[\d+\])"};
10 }
11 
12 namespace fhicl {
13  std::string
14  NameStackRegistry::full_key(std::string const& name)
15  {
16  if (name.empty()) {
17  throw exception{error::other, "NameStackRegistry::full_key"}
18  << "Cannot insert empty name into 'NameStackRegistry'.\n";
19  }
20 
21  auto& names = instance_().names_;
22  if (names.empty() || std::regex_match(name, re_sequence_element)) {
23  names.emplace_back(name);
24  } else {
25  names.emplace_back("." + name);
26  }
27  return std::accumulate(names.begin(), names.end(), std::string{});
28  }
29 
30  void
32  {
33  instance_().names_.pop_back();
34  }
35 
36  void
38  {
39  instance_().names_.clear();
40  }
41 
42  bool
44  {
45  return instance_().names_.empty();
46  }
47 
48  std::string
50  {
51  return instance_().names_.back();
52  }
53 
56  {
57  // The use of the registry is restricted to the construction of
58  // fhiclcpp types. As construction happens on only one thread,
59  // it is sufficient for each thread to have its own copy.
60  // Although a thread-local static would be appropriate here, not
61  // all implementations adequately support thread-local variables
62  // for the use case here. We thus use a custom-built per-thread
63  // cache.
65  return registry.slot_for_current_thread();
66  }
67 }
static NameStackRegistry & instance_()
static std::string current()
parameter set interface
static std::string full_key(std::string const &key)
std::vector< std::string > names_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33