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::detail {
15 
17 
19  public:
21  bool const showParents,
22  Indentation& ind)
23  : show_{showParents}
24  , names_{showParents ? get_parents(p.key()) : std::vector<std::string>{}}
25  , indent_{ind}
26  {
27  std::ostringstream os;
28 
29  if (show_) {
30 
31  for (auto it = names_.begin(), e = names_.end() - 1; it != e; ++it) {
32  std::string const& name = *it;
33  std::string const& next_name = *std::next(it);
34 
35  // We use the indent_ member so that we can properly
36  // update the indentation level. However, the literal
37  // indented string should not include any characters in it
38  // for the parents of the parameter in question.
39  std::string const indent(indent_().size(), ' ');
40  if (!std::isdigit(name[0])) {
41  if (std::isdigit(next_name[0])) {
42  os << indent << name << ": [ # index: " << next_name << '\n';
43  closingBraces_.push_back(indent + "]\n");
44  } else {
45  os << indent << name << ": {\n";
46  closingBraces_.push_back(indent + "}\n");
47  }
48  } else {
49  if (!std::isdigit(next_name[0])) {
50  os << indent << "{\n";
51  closingBraces_.push_back(indent + "}\n");
52  } else {
53  os << indent << "[ # index: " << next_name << '\n';
54  closingBraces_.push_back(indent + "]\n");
55  }
56  }
57  indent_.push();
58  }
59  } else {
60  }
61 
62  fullPayload_ = os.str();
63  }
64 
65  std::string const&
66  parent_names() const
67  {
68  return fullPayload_;
69  }
70 
73  {
74  if (!show_)
75  return "";
76 
78  for (auto it = closingBraces_.crbegin(), re = closingBraces_.crend();
79  it != re;
80  ++it) {
81  result.append(*it);
82  indent_.pop();
83  }
84  return result;
85  }
86 
87  private:
88  bool show_;
90  std::vector<std::string> names_;
91  std::vector<std::string> closingBraces_{};
93 
94  std::vector<std::string> get_parents(std::string const& k);
95 
96  bool
98  {
99  auto pos = p.key().find_last_of("]");
100  return pos != std::string::npos && pos == p.key().size() - 1;
101  }
102  };
103 }
104 
105 #endif /* fhiclcpp_types_detail_MaybeDisplayParent_h */
106 
107 // Local variables:
108 // mode: c++
109 // End:
static QCString name
Definition: declinfo.cpp:673
static QCString result
std::string string
Definition: nybbler.cc:12
bool is_sequence_element(ParameterBase const &p)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::vector< std::string > closingBraces_
const double e
p
Definition: test.py:223
std::string const & key() const
Definition: ParameterBase.h:38
std::vector< std::string > names_
std::string const & parent_names() const
MaybeDisplayParent(ParameterBase const &p, bool const showParents, Indentation &ind)
std::vector< std::string > get_parents(std::string const &k)
QCString & append(const char *s)
Definition: qcstring.cpp:383