LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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)
 
 ~PrintAllowedConfiguration ()
 
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 15 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 
)
PrintAllowedConfiguration::~PrintAllowedConfiguration ( )
default

Member Function Documentation

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

Definition at line 161 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().

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

Definition at line 246 of file PrintAllowedConfiguration.cc.

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

247 {
248  buffer_ << maybeName{a, indent_()} << a.stringified_value();
249 }
bool PrintAllowedConfiguration::before_action ( ParameterBase const &  p)
overrideprivate

Definition at line 110 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_.

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

References buffer_, and indent_.

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

Definition at line 96 of file ParameterWalker.h.

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

97  {
98  after_action(p);
99  }
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 124 of file ParameterWalker.h.

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

125  {
126  atom(a);
127  }
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 91 of file ParameterWalker.h.

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

92  {
93  return before_action(p);
94  }
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 113 of file ParameterWalker.h.

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

114  {
115  enter_sequence(s);
116  }
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 102 of file ParameterWalker.h.

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

103  {
104  enter_table(t);
105  }
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 118 of file ParameterWalker.h.

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

119  {
120  exit_sequence(s);
121  }
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 107 of file ParameterWalker.h.

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

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

Definition at line 202 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(), fhicl::SEQ_VECTOR, fhicl::detail::SequenceBase::size(), and util::to_string().

203 {
204  buffer_ << maybeName{s, indent_()} << "[\n";
205 
206  indent_.push();
207 
208  if (s.empty())
209  return;
210 
211  // We want the printout to look like this for sequences with
212  // defaults:
213  //
214  // list1: [
215  // 1, # default
216  // 2 # default
217  // ]
218  //
219  // And like this for vectors w/o defaults (has length 1):
220  //
221  // list2: [
222  // <int>,
223  // ...
224  // ]
225 
226  if (s.has_default() || (s.parameter_type() != par_type::SEQ_VECTOR)) {
227  for (std::size_t i{}; i != s.size() - 1; ++i)
228  keysWithCommas_.emplace(s.key() + "[" + std::to_string(i) + "]");
229  return;
230  }
231 
232  keysWithCommas_.emplace(s.key() + "[0]");
233  keysWithEllipses_.emplace(s.key() + "[0]");
234 }
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
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 62 of file PrintAllowedConfiguration.h.

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

Referenced by after_action(), and before_action().

63  {
64  return p.key() == cachedTopLevelParameter_;
65  }
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 30 of file PrintAllowedConfiguration.h.

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

Definition at line 31 of file PrintAllowedConfiguration.h.

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

Definition at line 29 of file PrintAllowedConfiguration.h.

Referenced by after_action(), and before_action().

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

Definition at line 32 of file PrintAllowedConfiguration.h.

Referenced by before_action(), and PrintAllowedConfiguration().

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

Definition at line 27 of file PrintAllowedConfiguration.h.

Referenced by before_action(), and PrintAllowedConfiguration().


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