LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
printing_helpers.cc
Go to the documentation of this file.
2 
3 #include <limits>
4 #include <regex>
5 
6 using namespace fhicl;
7 using namespace fhicl::detail;
8 
9 //==================================================================
10 
11 namespace {
12 
13  std::string const UNKNOWN_SRC{"-:1"};
14 
15  inline bool
16  allowed_info(std::string const& src_info)
17  {
18  return !src_info.empty() && src_info != UNKNOWN_SRC;
19  }
20 
21  constexpr auto size_t_max = std::numeric_limits<std::size_t>::max();
22 }
23 
24 //==================================================================
25 
26 std::string
27 detail::print_annotated_info(std::string const& curr_info,
28  std::string const& cached_info)
29 {
30  if (!allowed_info(curr_info))
31  return "";
32  std::string const tag = " # ";
33  std::string const printed_info =
34  curr_info == cached_info ? "\"\"" : curr_info;
35  return tag + printed_info;
36 }
37 
38 std::string
39 detail::print_prefix_annotated_info(std::string const& info)
40 {
41  std::string const printed_info = allowed_info(info) ? info : "";
42  return "#SRC|" + printed_info + "|";
43 }
44 
45 //==================================================================
46 
47 std::string
48 detail::printed_suffix(std::string const& key, std::size_t const sz)
49 {
50  std::string result;
51 
52  if (sz == size_t_max)
53  return result;
54 
55  std::smatch m;
56  if (std::regex_match(key, m, std::regex{R"(.*\[(\d+)\])"}) &&
57  std::stoul(m[1]) != sz - 1) {
58  result = ",";
59  }
60  return result;
61 }
62 
63 //==================================================================
64 // table
65 
66 std::string
67 table::printed_prefix(std::string const& key)
68 {
69  std::string result{opening_brace()};
70  if (!is_sequence_element(key))
71  result = key + ": " + result;
72  return result;
73 }
74 
75 //==================================================================
76 // sequence
77 
78 std::string
79 sequence::printed_prefix(std::string const& key)
80 {
81  std::string result{opening_brace()};
82  if (!is_sequence_element(key))
83  result = key + ": " + result;
84  return result;
85 }
86 
87 //==================================================================
88 // atom
89 
90 std::string
91 atom::printed_prefix(std::string const& key)
92 {
93  return is_sequence_element(key) ? "" : key + ": ";
94 }
95 
96 std::string
97 atom::value(boost::any const& a)
98 {
99  using ps_atom_t = std::string;
100  std::string const str = boost::any_cast<ps_atom_t>(a);
101  return str == std::string(9, '\0') ? "@nil" : str;
102 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string print_annotated_info(std::string const &curr_info, std::string const &cached_info)
bool is_sequence_element(std::string const &key)
std::string opening_brace()
std::string printed_prefix(std::string const &key)
std::string print_prefix_annotated_info(std::string const &curr_info)
Int_t max
Definition: plot.C:27
std::string printed_prefix(std::string const &key)
parameter set interface
std::string value(boost::any const &)
std::string printed_prefix(std::string const &key)
std::string ps_atom_t
Definition: coding.h:45