MaybeDisplayParent.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_detail_MaybeDisplayParent_h
2 #define fhiclcpp_types_detail_MaybeDisplayParent_h
3 
4 #include "cetlib/exempt_ptr.h"
7 
8 #include <cctype>
9 #include <sstream>
10 #include <vector>
11 
12 //===================================================================================
13 namespace fhicl {
14  namespace detail {
15 
18 
20  public:
22  bool const showParents,
23  Indentation& ind)
24  : show_{showParents}
25  , names_{showParents ? get_parents(p.key()) :
26  std::vector<std::string>{}}
27  , indent_{ind}
28  {
29  std::ostringstream os;
30 
31  if (show_) {
32 
33  for (auto it = names_.begin(), e = names_.end() - 1; it != e; ++it) {
34  std::string const& name = *it;
35  std::string const& next_name = *std::next(it);
36 
37  // We use the indent_ member so that we can properly
38  // update the indentation level. However, the literal
39  // indented string should not include any characters in it
40  // for the parents of the parameter in question.
41  std::string const indent(indent_().size(), ' ');
42  if (!std::isdigit(name[0])) {
43  if (std::isdigit(next_name[0])) {
44  os << indent << name << ": [ # index: " << next_name << '\n';
45  closingBraces_.push_back(indent + "]\n");
46  } else {
47  os << indent << name << ": {\n";
48  closingBraces_.push_back(indent + "}\n");
49  }
50  } else {
51  if (!std::isdigit(next_name[0])) {
52  os << indent << "{\n";
53  closingBraces_.push_back(indent + "}\n");
54  } else {
55  os << indent << "[ # index: " << next_name << '\n';
56  closingBraces_.push_back(indent + "]\n");
57  }
58  }
59  indent_.push();
60  }
61  } else {
62  }
63 
64  fullPayload_ = os.str();
65  }
66 
67  std::string const&
68  parent_names() const
69  {
70  return fullPayload_;
71  }
72 
75  {
76  if (!show_)
77  return "";
78 
80  for (auto it = closingBraces_.crbegin(), re = closingBraces_.crend();
81  it != re;
82  ++it) {
83  result.append(*it);
84  indent_.pop();
85  }
86  return result;
87  }
88 
89  private:
90  bool show_;
92  std::vector<std::string> names_;
93  std::vector<std::string> closingBraces_{};
95 
96  std::vector<std::string> get_parents(std::string const& k);
97 
98  bool
100  {
101  auto pos = p.key().find_last_of("]");
102  return pos != std::string::npos && pos == p.key().size() - 1;
103  }
104  };
105  }
106 }
107 
108 #endif /* fhiclcpp_types_detail_MaybeDisplayParent_h */
109 
110 // Local variables:
111 // mode: c++
112 // End:
const XML_Char * name
Definition: expat.h:151
set< int >::iterator it
bool is_sequence_element(ParameterBase const &p)
const char * p
Definition: xmltok.h:285
std::vector< std::string > closingBraces_
std::string indent(std::size_t const i)
std::vector< std::string > names_
std::string const & parent_names() const
std::vector< std::string > get_parents(std::string const &k)
MaybeDisplayParent(ParameterBase const &p, bool const showParents, Indentation &ind)
Float_t e
Definition: plot.C:35
void next()
Definition: show_event.C:84
std::string key() const
Definition: ParameterBase.h:44
enum BeamMode string