LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Name.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_Name_h
2 #define fhiclcpp_types_Name_h
3 
4 #include <string>
5 
6 namespace fhicl {
7 
8  std::string get_regex_replace_str(std::string const& str);
9 
10  struct Name {
11 
12  explicit Name(std::string const& name = "") : value(name) {}
13  std::string value;
14 
15  static Name
16  sequence_element(std::size_t const i)
17  {
18  return Name{index(i)};
19  }
20 
21  static Name
22  sequence_element(std::string const& key_stem, std::size_t const i)
23  {
24  return Name{key_stem + index(i)};
25  }
26 
27  // Sometimes the key has '[' and ']' literals in it. Those must be
28  // padded with an escape character so the regex library doesn't
29  // think we're trying to specify a character set.
30  static std::string
31  regex_safe(std::string const& key)
32  {
33  return fhicl::get_regex_replace_str(key);
34  }
35 
36  private:
37  static std::string
38  index(std::size_t const i)
39  {
40  return "[" + std::to_string(i) + "]";
41  }
42  };
43 }
44 
45 #endif /* fhiclcpp_types_Name_h */
46 
47 // Local variables:
48 // mode: c++
49 // End:
static Name sequence_element(std::string const &key_stem, std::size_t const i)
Definition: Name.h:22
Name(std::string const &name="")
Definition: Name.h:12
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
parameter set interface
std::string value
Definition: Name.h:13
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
static std::string regex_safe(std::string const &key)
Definition: Name.h:31
std::string get_regex_replace_str(std::string const &str)
Definition: Name.cc:11
static std::string index(std::size_t const i)
Definition: Name.h:38