Public Member Functions | Private Member Functions | Private Attributes | List of all members
fhicl::detail::MaybeDisplayParent Class Reference

#include <MaybeDisplayParent.h>

Public Member Functions

 MaybeDisplayParent (ParameterBase const &p, bool const showParents, Indentation &ind)
 
std::string const & parent_names () const
 
std::string closing_braces () const
 

Private Member Functions

std::vector< std::stringget_parents (std::string const &k)
 
bool is_sequence_element (ParameterBase const &p)
 

Private Attributes

bool show_
 
std::string fullPayload_ {}
 
std::vector< std::stringnames_
 
std::vector< std::stringclosingBraces_ {}
 
Indentationindent_
 

Detailed Description

Definition at line 18 of file MaybeDisplayParent.h.

Constructor & Destructor Documentation

fhicl::detail::MaybeDisplayParent::MaybeDisplayParent ( ParameterBase const &  p,
bool const  showParents,
Indentation ind 
)
inline

Definition at line 20 of file MaybeDisplayParent.h.

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  }
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
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::vector< std::string > names_
std::vector< std::string > get_parents(std::string const &k)

Member Function Documentation

std::string fhicl::detail::MaybeDisplayParent::closing_braces ( ) const
inline

Definition at line 72 of file MaybeDisplayParent.h.

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  }
static QCString result
std::string string
Definition: nybbler.cc:12
std::vector< std::string > closingBraces_
QCString & append(const char *s)
Definition: qcstring.cpp:383
std::vector< std::string > fhicl::detail::MaybeDisplayParent::get_parents ( std::string const &  k)
private

Definition at line 14 of file MaybeDisplayParent.cc.

15  {
16  std::vector<std::string> parents;
17  for (auto const& key : cet::split_by_regex(k, re_dot))
18  for (auto const& token :
19  cet::split_by_regex(std::regex_replace(key, re_index, ",$1"), ","))
20  parents.push_back(token);
21 
22  // Skip first key, which is something like "<some_label>" in the context
23  // whenever this function is called.
24  return std::vector<std::string>(parents.begin() + 1, parents.end());
25  }
std::vector< std::string > split_by_regex(std::string const &str, std::regex const &reDelimSet)
def key(type, name=None)
Definition: graph.py:13
bool fhicl::detail::MaybeDisplayParent::is_sequence_element ( ParameterBase const &  p)
inlineprivate

Definition at line 97 of file MaybeDisplayParent.h.

98  {
99  auto pos = p.key().find_last_of("]");
100  return pos != std::string::npos && pos == p.key().size() - 1;
101  }
p
Definition: test.py:223
std::string const& fhicl::detail::MaybeDisplayParent::parent_names ( ) const
inline

Definition at line 66 of file MaybeDisplayParent.h.

67  {
68  return fullPayload_;
69  }

Member Data Documentation

std::vector<std::string> fhicl::detail::MaybeDisplayParent::closingBraces_ {}
private

Definition at line 91 of file MaybeDisplayParent.h.

std::string fhicl::detail::MaybeDisplayParent::fullPayload_ {}
private

Definition at line 89 of file MaybeDisplayParent.h.

Indentation& fhicl::detail::MaybeDisplayParent::indent_
private

Definition at line 92 of file MaybeDisplayParent.h.

std::vector<std::string> fhicl::detail::MaybeDisplayParent::names_
private

Definition at line 90 of file MaybeDisplayParent.h.

bool fhicl::detail::MaybeDisplayParent::show_
private

Definition at line 88 of file MaybeDisplayParent.h.


The documentation for this class was generated from the following files: