LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
fhicl::detail::PrintAllowedConfiguration Class Reference

#include "PrintAllowedConfiguration.h"

Inheritance diagram for fhicl::detail::PrintAllowedConfiguration:
fhicl::detail::ParameterWalker< tt::const_flavor::require_const >

Public Member Functions

 PrintAllowedConfiguration (std::ostream &os, bool const showParents=false, std::string const &prefix=std::string(3, ' '), bool const stlf=false)
 
void walk_over (tt::maybe_const_t< ParameterBase, C > &)
 
bool do_before_action (tt::maybe_const_t< ParameterBase, C > &p)
 
void do_after_action (tt::maybe_const_t< ParameterBase, C > &p)
 
void do_enter_table (tt::maybe_const_t< TableBase, C > &t)
 
void do_exit_table (tt::maybe_const_t< TableBase, C > &t)
 
void do_enter_sequence (tt::maybe_const_t< SequenceBase, C > &s)
 
void do_exit_sequence (tt::maybe_const_t< SequenceBase, C > &s)
 
void do_atom (tt::maybe_const_t< AtomBase, C > &a)
 
void do_delegated_parameter (tt::maybe_const_t< DelegateBase, C > &dp)
 

Private Member Functions

bool before_action (ParameterBase const &) override
 
void after_action (ParameterBase const &) override
 
void enter_table (TableBase const &) override
 
void exit_table (TableBase const &) override
 
void enter_sequence (SequenceBase const &) override
 
void exit_sequence (SequenceBase const &) override
 
void atom (AtomBase const &) override
 
void delegated_parameter (DelegateBase const &) override
 
void cacheTopLevelParameter (ParameterBase const &p)
 
void maybeReleaseTopLevelParameter (ParameterBase const &p)
 
bool suppressFormat (ParameterBase const &p)
 

Private Attributes

std::ostream & buffer_
 
Indentation indent_
 
bool suppressTopLevelFormatting_
 
std::string cachedTopLevelParameter_ {}
 
std::stack< MaybeDisplayParentmps_ {}
 
std::unordered_set< std::string > keysWithCommas_ {}
 
std::unordered_set< std::string > keysWithEllipses_ {}
 
bool showParentsForFirstParam_
 

Detailed Description

Definition at line 18 of file PrintAllowedConfiguration.h.

Constructor & Destructor Documentation

PrintAllowedConfiguration::PrintAllowedConfiguration ( std::ostream &  os,
bool const  showParents = false,
std::string const &  prefix = std::string(3, ' '),
bool const  stlf = false 
)

Member Function Documentation

void PrintAllowedConfiguration::after_action ( ParameterBase const &  p)
overrideprivate

Definition at line 157 of file PrintAllowedConfiguration.cc.

References fhicl::ATOM, buffer_, fhicl::detail::ParameterBase::has_default(), indent_, fhicl::detail::ParameterBase::is_conditional(), fhicl::detail::ParameterBase::is_optional(), fhicl::detail::ParameterBase::key(), maybeReleaseTopLevelParameter(), fhicl::detail::Indentation::modify_top(), mps_, fhicl::detail::ParameterBase::parameter_type(), and suppressFormat().

158 {
159  buffer_ << suffix(keysWithCommas_, keysWithEllipses_, p.key(), indent_());
160 
161  if (p.has_default() && p.parameter_type() == par_type::ATOM)
162  buffer_ << " # default";
163 
164  if (!suppressFormat(p)) {
165  if (p.is_conditional()) {
166  indent_.modify_top("└" + string_repeat(30, "─"));
167  buffer_ << '\n' << indent_();
168  indent_.modify_top(std::string(3, ' '));
169  } else if (p.is_optional()) {
170  indent_.modify_top(std::string(3, ' '));
171  }
172  }
173 
175  buffer_ << '\n' << mps_.top().closing_braces();
176  mps_.pop();
177 }
void maybeReleaseTopLevelParameter(ParameterBase const &p)
void modify_top(std::string const &s)
Definition: Indentation.h:37
std::unordered_set< std::string > keysWithCommas_
std::unordered_set< std::string > keysWithEllipses_
void PrintAllowedConfiguration::atom ( AtomBase const &  a)
overrideprivate

Definition at line 242 of file PrintAllowedConfiguration.cc.

References buffer_, indent_, and fhicl::detail::AtomBase::stringified_value().

243 {
244  buffer_ << maybeName{a, indent_()} << a.stringified_value();
245 }
bool PrintAllowedConfiguration::before_action ( ParameterBase const &  p)
overrideprivate

Definition at line 106 of file PrintAllowedConfiguration.cc.

References buffer_, cacheTopLevelParameter(), fhicl::detail::ParameterBase::comment(), indent_, fhicl::detail::ParameterBase::is_conditional(), fhicl::detail::ParameterBase::is_optional(), fhicl::detail::is_sequence_element(), fhicl::detail::ParameterBase::key(), fhicl::detail::Indentation::modify_top(), mps_, showParentsForFirstParam_, fhicl::detail::Indentation::size(), suppressFormat(), and suppressTopLevelFormatting_.

107 {
108 
111 
112  if (!suppressFormat(p)) {
113 
114  if (p.is_conditional()) {
115  buffer_ << '\n';
116  indent_.modify_top("┌" + string_repeat(30, "─"));
117  buffer_ << non_whitespace(indent_(), indent_.size()) << '\n';
118  indent_.modify_top("│ ");
119  }
120 
121  if (!p.comment().empty()) {
122  if (!p.is_conditional())
123  buffer_ << non_whitespace(indent_(), indent_.size()) << '\n';
124  for (auto const& line : cet::split_by_regex(p.comment(), "\n"))
125  buffer_ << indent_() << "## " << line << '\n';
126  }
127  }
128 
129  if (!is_sequence_element(p.key())) {
130  buffer_ << non_whitespace(indent_(), indent_.size()) << '\n';
131 
132  // In general, optional parameters cannot be template arguments to
133  // sequences. However, the implementation for 'TupleAs' uses
134  // OptionalTuple<...> as the holding type of the sequence
135  // elements. In the case where we have Sequence< TupleAs<> >, the
136  // TupleAs entries will be prefaced with '#', and we don't want
137  // that. Therefore, we modify the top indentation fragment only
138  // if the parameter is not a sequence element.
139 
140  if (p.is_optional()) {
141  if (p.is_conditional())
142  indent_.modify_top("│# ");
143  else
144  indent_.modify_top(" # ");
145  }
146  }
147 
150 
151  buffer_ << mps_.top().parent_names();
152 
153  return true;
154 }
bool is_sequence_element(std::string const &key)
void modify_top(std::string const &s)
Definition: Indentation.h:37
void cacheTopLevelParameter(ParameterBase const &p)
void fhicl::detail::PrintAllowedConfiguration::cacheTopLevelParameter ( ParameterBase const &  p)
inlineprivate
void PrintAllowedConfiguration::delegated_parameter ( DelegateBase const &  dp)
overrideprivate

Definition at line 250 of file PrintAllowedConfiguration.cc.

References buffer_, and indent_.

251 {
252  buffer_ << maybeName{dp, indent_()} << "<< delegated >>";
253 }
void fhicl::detail::ParameterWalker< C >::do_after_action ( tt::maybe_const_t< ParameterBase, C > &  p)
inlineinherited

Definition at line 98 of file ParameterWalker.h.

References fhicl::detail::ParameterWalker< C >::after_action().

99  {
100  after_action(p);
101  }
virtual void after_action(tt::maybe_const_t< ParameterBase, C > &)
void fhicl::detail::ParameterWalker< C >::do_atom ( tt::maybe_const_t< AtomBase, C > &  a)
inlineinherited

Definition at line 126 of file ParameterWalker.h.

References fhicl::detail::ParameterWalker< C >::atom().

127  {
128  atom(a);
129  }
virtual void atom(tt::maybe_const_t< AtomBase, C > &)=0
bool fhicl::detail::ParameterWalker< C >::do_before_action ( tt::maybe_const_t< ParameterBase, C > &  p)
inlineinherited

Definition at line 93 of file ParameterWalker.h.

References fhicl::detail::ParameterWalker< C >::before_action().

94  {
95  return before_action(p);
96  }
virtual bool before_action(tt::maybe_const_t< ParameterBase, C > &)
void fhicl::detail::ParameterWalker< C >::do_enter_sequence ( tt::maybe_const_t< SequenceBase, C > &  s)
inlineinherited

Definition at line 115 of file ParameterWalker.h.

References fhicl::detail::ParameterWalker< C >::enter_sequence().

116  {
117  enter_sequence(s);
118  }
Float_t s
Definition: plot.C:23
virtual void enter_sequence(tt::maybe_const_t< SequenceBase, C > &)=0
void fhicl::detail::ParameterWalker< C >::do_enter_table ( tt::maybe_const_t< TableBase, C > &  t)
inlineinherited

Definition at line 104 of file ParameterWalker.h.

References fhicl::detail::ParameterWalker< C >::enter_table().

105  {
106  enter_table(t);
107  }
virtual void enter_table(tt::maybe_const_t< TableBase, C > &)=0
void fhicl::detail::ParameterWalker< C >::do_exit_sequence ( tt::maybe_const_t< SequenceBase, C > &  s)
inlineinherited

Definition at line 120 of file ParameterWalker.h.

References fhicl::detail::ParameterWalker< C >::exit_sequence().

121  {
122  exit_sequence(s);
123  }
Float_t s
Definition: plot.C:23
virtual void exit_sequence(tt::maybe_const_t< SequenceBase, C > &)
void fhicl::detail::ParameterWalker< C >::do_exit_table ( tt::maybe_const_t< TableBase, C > &  t)
inlineinherited

Definition at line 109 of file ParameterWalker.h.

References fhicl::detail::ParameterWalker< C >::exit_table().

110  {
111  exit_table(t);
112  }
virtual void exit_table(tt::maybe_const_t< TableBase, C > &)
void PrintAllowedConfiguration::enter_sequence ( SequenceBase const &  s)
overrideprivate

Definition at line 198 of file PrintAllowedConfiguration.cc.

References buffer_, fhicl::detail::SequenceBase::empty(), fhicl::detail::ParameterBase::has_default(), indent_, fhicl::detail::ParameterBase::key(), fhicl::detail::ParameterBase::parameter_type(), fhicl::detail::Indentation::push(), s, fhicl::SEQ_VECTOR, fhicl::detail::SequenceBase::size(), and util::flags::to_string().

199 {
200  buffer_ << maybeName{s, indent_()} << "[\n";
201 
202  indent_.push();
203 
204  if (s.empty())
205  return;
206 
207  // We want the printout to look like this for sequences with
208  // defaults:
209  //
210  // list1: [
211  // 1, # default
212  // 2 # default
213  // ]
214  //
215  // And like this for vectors w/o defaults (has length 1):
216  //
217  // list2: [
218  // <int>,
219  // ...
220  // ]
221 
222  if (s.has_default() || (s.parameter_type() != par_type::SEQ_VECTOR)) {
223  for (std::size_t i{}; i != s.size() - 1; ++i)
224  keysWithCommas_.emplace(s.key() + "[" + std::to_string(i) + "]");
225  return;
226  }
227 
228  keysWithCommas_.emplace(s.key() + "[0]");
229  keysWithEllipses_.emplace(s.key() + "[0]");
230 }
Float_t s
Definition: plot.C:23
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
std::unordered_set< std::string > keysWithCommas_
std::unordered_set< std::string > keysWithEllipses_
void PrintAllowedConfiguration::enter_table ( TableBase const &  t)
overrideprivate
void PrintAllowedConfiguration::exit_sequence ( SequenceBase const &  )
overrideprivate
void PrintAllowedConfiguration::exit_table ( TableBase const &  )
overrideprivate
void fhicl::detail::PrintAllowedConfiguration::maybeReleaseTopLevelParameter ( ParameterBase const &  p)
inlineprivate
bool fhicl::detail::PrintAllowedConfiguration::suppressFormat ( ParameterBase const &  p)
inlineprivate

Definition at line 64 of file PrintAllowedConfiguration.h.

References cachedTopLevelParameter_, and fhicl::detail::ParameterBase::key().

Referenced by after_action(), and before_action().

65  {
66  return p.key() == cachedTopLevelParameter_;
67  }
void fhicl::detail::ParameterWalker< C >::walk_over ( tt::maybe_const_t< ParameterBase, C > &  )
inherited

Member Data Documentation

std::ostream& fhicl::detail::PrintAllowedConfiguration::buffer_
private
std::string fhicl::detail::PrintAllowedConfiguration::cachedTopLevelParameter_ {}
private
Indentation fhicl::detail::PrintAllowedConfiguration::indent_
private
std::unordered_set<std::string> fhicl::detail::PrintAllowedConfiguration::keysWithCommas_ {}
private

Definition at line 32 of file PrintAllowedConfiguration.h.

std::unordered_set<std::string> fhicl::detail::PrintAllowedConfiguration::keysWithEllipses_ {}
private

Definition at line 33 of file PrintAllowedConfiguration.h.

std::stack<MaybeDisplayParent> fhicl::detail::PrintAllowedConfiguration::mps_ {}
private

Definition at line 31 of file PrintAllowedConfiguration.h.

Referenced by after_action(), and before_action().

bool fhicl::detail::PrintAllowedConfiguration::showParentsForFirstParam_
private

Definition at line 34 of file PrintAllowedConfiguration.h.

Referenced by before_action(), and PrintAllowedConfiguration().

bool fhicl::detail::PrintAllowedConfiguration::suppressTopLevelFormatting_
private

Definition at line 29 of file PrintAllowedConfiguration.h.

Referenced by before_action(), and PrintAllowedConfiguration().


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