LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 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.

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

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  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::vector< std::string > closingBraces_
std::string indent(std::size_t const i)
std::vector< std::string > names_
Float_t e
Definition: plot.C:35
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.

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

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

Definition at line 14 of file MaybeDisplayParent.cc.

Referenced by MaybeDisplayParent().

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  }
bool fhicl::detail::MaybeDisplayParent::is_sequence_element ( ParameterBase const &  p)
inlineprivate

Definition at line 97 of file MaybeDisplayParent.h.

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

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

Definition at line 66 of file MaybeDisplayParent.h.

References fullPayload_.

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.

Referenced by closing_braces(), and MaybeDisplayParent().

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

Definition at line 89 of file MaybeDisplayParent.h.

Referenced by MaybeDisplayParent(), and parent_names().

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

Definition at line 92 of file MaybeDisplayParent.h.

Referenced by closing_braces(), and MaybeDisplayParent().

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

Definition at line 90 of file MaybeDisplayParent.h.

Referenced by MaybeDisplayParent().

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

Definition at line 88 of file MaybeDisplayParent.h.

Referenced by closing_braces(), and MaybeDisplayParent().


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