LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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::string > get_parents (std::string const &k)
 
bool is_sequence_element (ParameterBase const &p)
 

Private Attributes

bool show_
 
std::string fullPayload_ {}
 
std::vector< std::string > names_
 
std::vector< std::string > closingBraces_ {}
 
Indentationindent_
 

Detailed Description

Definition at line 19 of file MaybeDisplayParent.h.

Constructor & Destructor Documentation

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

Definition at line 21 of file MaybeDisplayParent.h.

References closingBraces_, e, fullPayload_, get_parents(), art::detail::indent(), indent_, names_, fhicl::detail::Indentation::push(), and show_.

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  }
std::vector< std::string > closingBraces_
std::string indent(std::size_t const i)
std::vector< std::string > names_
Float_t e
Definition: plot.C:34
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 74 of file MaybeDisplayParent.h.

References closingBraces_, indent_, fhicl::detail::Indentation::pop(), and show_.

75  {
76  if (!show_)
77  return "";
78 
79  std::string result;
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  }
std::vector< std::string > closingBraces_
std::vector< std::string > fhicl::detail::MaybeDisplayParent::get_parents ( std::string const &  k)
private

Definition at line 16 of file MaybeDisplayParent.cc.

Referenced by MaybeDisplayParent().

17  {
18  std::regex const r_index{"\\[(\\d+)\\]"};
19  std::vector<std::string> parents;
20  for (auto const& key : cet::split_by_regex(k, "\\."))
21  for (auto const& token :
22  cet::split_by_regex(std::regex_replace(key, r_index, ",$1"), ","))
23  parents.push_back(token);
24 
25  // Skip first key, which is something like "<some_label>" in the context
26  // whenever this function is called.
27  return std::vector<std::string>(parents.begin() + 1, parents.end());
28  }
bool fhicl::detail::MaybeDisplayParent::is_sequence_element ( ParameterBase const &  p)
inlineprivate

Definition at line 99 of file MaybeDisplayParent.h.

References fhicl::detail::ParameterBase::key().

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

Definition at line 68 of file MaybeDisplayParent.h.

References fullPayload_.

69  {
70  return fullPayload_;
71  }

Member Data Documentation

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

Definition at line 93 of file MaybeDisplayParent.h.

Referenced by closing_braces(), and MaybeDisplayParent().

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

Definition at line 91 of file MaybeDisplayParent.h.

Referenced by MaybeDisplayParent(), and parent_names().

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

Definition at line 94 of file MaybeDisplayParent.h.

Referenced by closing_braces(), and MaybeDisplayParent().

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

Definition at line 92 of file MaybeDisplayParent.h.

Referenced by MaybeDisplayParent().

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

Definition at line 90 of file MaybeDisplayParent.h.

Referenced by closing_braces(), and MaybeDisplayParent().


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