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 <string>
11 #include <vector>
12 
13 //===================================================================================
14 namespace fhicl {
15  namespace detail {
16 
19 
21  public:
23  bool const showParents,
24  Indentation& ind)
25  : show_{showParents}
26  , names_{showParents ? get_parents(p.key()) :
27  std::vector<std::string>{}}
28  , indent_{ind}
29  {
30  std::ostringstream os;
31 
32  if (show_) {
33 
34  for (auto it = names_.begin(), e = names_.end() - 1; it != e; ++it) {
35  std::string const& name = *it;
36  std::string const& next_name = *std::next(it);
37 
38  // We use the indent_ member so that we can properly
39  // update the indentation level. However, the literal
40  // indented string should not include any characters in it
41  // for the parents of the parameter in question.
42  std::string const indent(indent_().size(), ' ');
43  if (!std::isdigit(name[0])) {
44  if (std::isdigit(next_name[0])) {
45  os << indent << name << ": [ # index: " << next_name << '\n';
46  closingBraces_.push_back(indent + "]\n");
47  } else {
48  os << indent << name << ": {\n";
49  closingBraces_.push_back(indent + "}\n");
50  }
51  } else {
52  if (!std::isdigit(next_name[0])) {
53  os << indent << "{\n";
54  closingBraces_.push_back(indent + "}\n");
55  } else {
56  os << indent << "[ # index: " << next_name << '\n';
57  closingBraces_.push_back(indent + "]\n");
58  }
59  }
60  indent_.push();
61  }
62  } else {
63  }
64 
65  fullPayload_ = os.str();
66  }
67 
68  std::string const&
69  parent_names() const
70  {
71  return fullPayload_;
72  }
73 
76  {
77  if (!show_)
78  return "";
79 
81  for (auto it = closingBraces_.crbegin(), re = closingBraces_.crend();
82  it != re;
83  ++it) {
84  result.append(*it);
85  indent_.pop();
86  }
87  return result;
88  }
89 
90  private:
91  bool show_;
93  std::vector<std::string> names_;
94  std::vector<std::string> closingBraces_{};
96 
97  std::vector<std::string> get_parents(std::string const& k);
98 
99  bool
101  {
102  auto pos = p.key().find_last_of("]");
103  return pos != std::string::npos && pos == p.key().size() - 1;
104  }
105  };
106  }
107 }
108 
109 #endif /* fhiclcpp_types_detail_MaybeDisplayParent_h */
110 
111 // Local variables:
112 // mode: c++
113 // 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::string const & key() const
Definition: ParameterBase.h:44
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
enum BeamMode string