LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 <regex>
5 #include <string>
6 
7 namespace fhicl {
8 
9  std::string const get_regex_replace_str(std::string const& str);
10 
11  struct Name {
12 
13  explicit Name(std::string const& name = "") : value(name) {}
14  std::string value;
15 
16  static Name
17  sequence_element(std::size_t const i)
18  {
19  return Name{index(i)};
20  }
21 
22  static Name
23  sequence_element(std::string const& key_stem, std::size_t const i)
24  {
25  return Name{key_stem + index(i)};
26  }
27 
28  // Sometimes the key has '[' and ']' literals in it. Those must be
29  // padded with an escape character so the regex library doesn't
30  // think we're trying to specify a character set.
31  static std::string
32  regex_safe(std::string const& key)
33  {
34  return fhicl::get_regex_replace_str(key);
35  }
36 
37  private:
38  static std::string
39  index(std::size_t const i)
40  {
41  return "[" + std::to_string(i) + "]";
42  }
43  };
44 }
45 
46 #endif /* fhiclcpp_types_Name_h */
47 
48 // Local variables:
49 // mode: c++
50 // End:
static Name sequence_element(std::string const &key_stem, std::size_t const i)
Definition: Name.h:23
std::string const get_regex_replace_str(std::string const &istr)
Definition: Name.cc:8
Name(std::string const &name="")
Definition: Name.h:13
parameter set interface
std::string value
Definition: Name.h:14
static Name sequence_element(std::size_t const i)
Definition: Name.h:17
static std::string regex_safe(std::string const &key)
Definition: Name.h:32
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
static std::string index(std::size_t const i)
Definition: Name.h:39