LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::detail::ValuePrinter Class Reference

#include "ValuePrinter.h"

Inheritance diagram for fhicl::detail::ValuePrinter:
fhicl::ParameterSetWalker

Public Types

using key_t = std::string
 
using any_t = std::any
 

Public Member Functions

 ValuePrinter (std::string const &key, unsigned initial_indent_level=0)
 
std::string result () const
 
void do_enter_table (key_t const &k, any_t const &a)
 
void do_enter_sequence (key_t const &k, any_t const &a)
 
void do_atom (key_t const &k, any_t const &a)
 
void do_before_action (key_t const &k, any_t const &a, ParameterSet const *ps)
 
void do_after_action (key_t const &k)
 
void do_exit_table (key_t const &k, any_t const &a)
 
void do_exit_sequence (key_t const &k, any_t const &a)
 

Private Member Functions

void enter_table (key_t const &, any_t const &) override
 
void enter_sequence (key_t const &, any_t const &) override
 
void exit_table (key_t const &, any_t const &) override
 
void exit_sequence (key_t const &, any_t const &) override
 
void atom (key_t const &, any_t const &) override
 
void before_action (key_t const &, any_t const &, ParameterSet const *) override
 
void after_action (key_t const &) override
 
void push_size_ (any_t const &)
 
void pop_size_ ()
 
std::string maybe_indent_ (std::size_t)
 
std::string maybe_nl_ (std::size_t)
 

Private Attributes

std::ostringstream buffer_ {}
 
std::string key_
 
Indentation indent_
 
std::stack< std::size_t > sequence_sizes_
 
std::size_t seq_size_
 
std::size_t table_size_
 
bool print_encapsulated_values_ {false}
 

Detailed Description

Definition at line 86 of file ValuePrinter.h.

Member Typedef Documentation

using fhicl::ParameterSetWalker::any_t = std::any
inherited

Definition at line 79 of file ParameterSetWalker.h.

using fhicl::ParameterSetWalker::key_t = std::string
inherited

Definition at line 78 of file ParameterSetWalker.h.

Constructor & Destructor Documentation

ValuePrinter::ValuePrinter ( std::string const &  key,
unsigned  initial_indent_level = 0 
)

Definition at line 18 of file ValuePrinter.cc.

References indent_, seq_size_, sequence_sizes_, and table_size_.

20  : key_{key_to_search}
21  , indent_{initial_indent_level}
22  , sequence_sizes_{{size_t_max}}
23  , seq_size_{sequence_sizes_.top()}
24  , table_size_{0u}
25 {}
std::stack< std::size_t > sequence_sizes_
Definition: ValuePrinter.h:119

Member Function Documentation

void ValuePrinter::after_action ( key_t const &  key)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 42 of file ValuePrinter.cc.

References key_, and print_encapsulated_values_.

Referenced by result().

43 {
44  if (key_ == key) {
46  }
47 }
void ValuePrinter::atom ( key_t const &  key,
any_t const &  a 
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 106 of file ValuePrinter.cc.

References buffer_, indent_, fhicl::detail::nl(), print_encapsulated_values_, fhicl::detail::atom::printed_prefix(), fhicl::detail::printed_suffix(), seq_size_, and fhicl::detail::atom::value().

Referenced by result().

107 {
109  return;
111  << printed_suffix(key, seq_size_) << nl();
112 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string value(std::any const &)
std::ostringstream buffer_
Definition: ValuePrinter.h:116
std::string printed_prefix(std::string const &key)
std::string nl(std::size_t i=1)
void ValuePrinter::before_action ( key_t const &  key,
any_t const &  a,
ParameterSet const *  ps 
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 29 of file ValuePrinter.cc.

References fhicl::ParameterSet::get(), fhicl::detail::is_table(), key_, print_encapsulated_values_, and table_size_.

Referenced by result().

32 {
33  if (key_ == key) {
35  }
36  if (!is_table(a))
37  return;
38  table_size_ = ps->get<fhicl::ParameterSet>(key).get_all_keys().size();
39 }
bool is_table(std::any const &val)
Definition: coding.h:55
void fhicl::ParameterSetWalker::do_after_action ( key_t const &  k)
inlineinherited

Definition at line 103 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::after_action().

Referenced by fhicl::ParameterSet::walk().

104  {
105  after_action(k);
106  }
virtual void after_action(key_t const &)
void fhicl::ParameterSetWalker::do_atom ( key_t const &  k,
any_t const &  a 
)
inlineinherited

Definition at line 92 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::atom().

Referenced by fhicl::ParameterSet::walk().

93  {
94  atom(k, a);
95  }
virtual void atom(key_t const &, any_t const &)=0
void fhicl::ParameterSetWalker::do_before_action ( key_t const &  k,
any_t const &  a,
ParameterSet const *  ps 
)
inlineinherited

Definition at line 98 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::before_action().

Referenced by fhicl::ParameterSet::walk().

99  {
100  before_action(k, a, ps);
101  }
virtual void before_action(key_t const &, any_t const &, ParameterSet const *)
void fhicl::ParameterSetWalker::do_enter_sequence ( key_t const &  k,
any_t const &  a 
)
inlineinherited

Definition at line 87 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::enter_sequence().

Referenced by fhicl::ParameterSet::walk().

88  {
89  enter_sequence(k, a);
90  }
virtual void enter_sequence(key_t const &, any_t const &)=0
void fhicl::ParameterSetWalker::do_enter_table ( key_t const &  k,
any_t const &  a 
)
inlineinherited

Definition at line 82 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::enter_table().

Referenced by fhicl::ParameterSet::walk().

83  {
84  enter_table(k, a);
85  }
virtual void enter_table(key_t const &, any_t const &)=0
void fhicl::ParameterSetWalker::do_exit_sequence ( key_t const &  k,
any_t const &  a 
)
inlineinherited
void fhicl::ParameterSetWalker::do_exit_table ( key_t const &  k,
any_t const &  a 
)
inlineinherited

Definition at line 109 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::exit_table().

Referenced by fhicl::ParameterSet::walk().

110  {
111  exit_table(k, a);
112  }
virtual void exit_table(key_t const &, any_t const &)
void ValuePrinter::enter_sequence ( key_t const &  key,
any_t const &  a 
)
overrideprivatevirtual
void ValuePrinter::enter_table ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual
void ValuePrinter::exit_sequence ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 83 of file ValuePrinter.cc.

References buffer_, fhicl::detail::sequence::closing_brace(), indent_, maybe_indent_(), fhicl::detail::nl(), fhicl::detail::Indentation::pop(), pop_size_(), print_encapsulated_values_, fhicl::detail::printed_suffix(), and seq_size_.

Referenced by result().

84 {
86  return;
87  // FIXME: To support a printout like:
88  //
89  // empty: []
90  //
91  // We need to first capture the size of the sequence (0) before we
92  // call pop_size_(). However, for non-empty sequences (I think...)
93  // pop_size_ needs to be called before we determine if an
94  // indentation should take place. This needs to be cleaned up.
95  bool const empty_sequence = seq_size_ == 0;
96  indent_.pop();
97  pop_size_();
98  buffer_ << (empty_sequence ? "" : maybe_indent_(seq_size_))
100  << nl();
101 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string maybe_indent_(std::size_t)
std::ostringstream buffer_
Definition: ValuePrinter.h:116
std::string nl(std::size_t i=1)
void ValuePrinter::exit_table ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 61 of file ValuePrinter.cc.

References buffer_, fhicl::detail::table::closing_brace(), indent_, maybe_indent_(), fhicl::detail::nl(), fhicl::detail::Indentation::pop(), print_encapsulated_values_, fhicl::detail::printed_suffix(), seq_size_, and table_size_.

Referenced by result().

62 {
64  return;
65  indent_.pop();
67  << printed_suffix(key, seq_size_) << nl();
68 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string maybe_indent_(std::size_t)
std::ostringstream buffer_
Definition: ValuePrinter.h:116
std::string nl(std::size_t i=1)
std::string closing_brace()
std::string ValuePrinter::maybe_indent_ ( std::size_t  sz)
private

Definition at line 131 of file ValuePrinter.cc.

References indent_.

Referenced by exit_sequence(), exit_table(), and result().

132 {
133  return sz ? indent_() : "";
134 }
std::string ValuePrinter::maybe_nl_ ( std::size_t  sz)
private

Definition at line 137 of file ValuePrinter.cc.

References fhicl::detail::nl().

Referenced by enter_sequence(), enter_table(), and result().

138 {
139  return sz ? nl() : "";
140 }
std::string nl(std::size_t i=1)
void ValuePrinter::pop_size_ ( )
private

Definition at line 124 of file ValuePrinter.cc.

References seq_size_, and sequence_sizes_.

Referenced by exit_sequence(), and result().

125 {
126  sequence_sizes_.pop();
127  seq_size_ = sequence_sizes_.top();
128 }
std::stack< std::size_t > sequence_sizes_
Definition: ValuePrinter.h:119
void ValuePrinter::push_size_ ( any_t const &  a)
private

Definition at line 117 of file ValuePrinter.cc.

References seq_size_, sequence_sizes_, and util::size().

Referenced by enter_sequence(), and result().

118 {
119  sequence_sizes_.emplace(std::any_cast<ps_sequence_t>(a).size());
120  seq_size_ = sequence_sizes_.top();
121 }
std::stack< std::size_t > sequence_sizes_
Definition: ValuePrinter.h:119
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::string fhicl::detail::ValuePrinter::result ( ) const
inline

Member Data Documentation

std::ostringstream fhicl::detail::ValuePrinter::buffer_ {}
private

Definition at line 116 of file ValuePrinter.h.

Referenced by atom(), enter_sequence(), enter_table(), exit_sequence(), exit_table(), and result().

Indentation fhicl::detail::ValuePrinter::indent_
private
std::string fhicl::detail::ValuePrinter::key_
private

Definition at line 117 of file ValuePrinter.h.

Referenced by after_action(), and before_action().

bool fhicl::detail::ValuePrinter::print_encapsulated_values_ {false}
private
std::size_t fhicl::detail::ValuePrinter::seq_size_
private
std::stack<std::size_t> fhicl::detail::ValuePrinter::sequence_sizes_
private

Definition at line 119 of file ValuePrinter.h.

Referenced by pop_size_(), push_size_(), and ValuePrinter().

std::size_t fhicl::detail::ValuePrinter::table_size_
private

Definition at line 121 of file ValuePrinter.h.

Referenced by before_action(), enter_table(), exit_table(), and ValuePrinter().


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