Public Member Functions | Private Member Functions | Private Attributes | List of all members
fhicl::detail::ValuePrinter Class Reference

#include <ValuePrinter.h>

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

Public Member Functions

 ValuePrinter (std::string const &key, unsigned initial_indent_level=0)
 
std::string result () const
 
- Public Member Functions inherited from fhicl::ParameterSetWalker
virtual ~ParameterSetWalker () noexcept=default
 
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}
 

Additional Inherited Members

- Public Types inherited from fhicl::ParameterSetWalker
using key_t = std::string
 
using any_t = std::any
 

Detailed Description

Definition at line 86 of file ValuePrinter.h.

Constructor & Destructor Documentation

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

Definition at line 18 of file ValuePrinter.cc.

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.

43 {
44  if (key_ == key) {
46  }
47 }
def key(type, name=None)
Definition: graph.py:13
void ValuePrinter::atom ( key_t const &  key,
any_t const &  a 
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 106 of file ValuePrinter.cc.

107 {
109  return;
111  << printed_suffix(key, seq_size_) << nl();
112 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
def key(type, name=None)
Definition: graph.py:13
const double a
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.

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 }
def key(type, name=None)
Definition: graph.py:13
const double a
static constexpr double ps
Definition: Units.h:99
bool is_table(std::any const &val)
Definition: coding.h:55
void ValuePrinter::enter_sequence ( key_t const &  key,
any_t const &  a 
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 73 of file ValuePrinter.cc.

74 {
76  return;
77  push_size_(a);
79  indent_.push();
80 }
std::string printed_prefix(std::string const &key)
std::string maybe_nl_(std::size_t)
void push_size_(any_t const &)
def key(type, name=None)
Definition: graph.py:13
const double a
std::ostringstream buffer_
Definition: ValuePrinter.h:116
void ValuePrinter::enter_table ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 52 of file ValuePrinter.cc.

53 {
55  return;
57  indent_.push();
58 }
std::string maybe_nl_(std::size_t)
std::string printed_prefix(std::string const &key)
def key(type, name=None)
Definition: graph.py:13
std::ostringstream buffer_
Definition: ValuePrinter.h:116
void ValuePrinter::exit_sequence ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 83 of file ValuePrinter.cc.

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)
def key(type, name=None)
Definition: graph.py:13
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.

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)
def key(type, name=None)
Definition: graph.py:13
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.

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

Definition at line 137 of file ValuePrinter.cc.

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.

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.

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:92
const double a
std::string fhicl::detail::ValuePrinter::result ( ) const
inline

Definition at line 91 of file ValuePrinter.h.

92  {
93  return buffer_.str();
94  }
std::ostringstream buffer_
Definition: ValuePrinter.h:116

Member Data Documentation

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

Definition at line 116 of file ValuePrinter.h.

Indentation fhicl::detail::ValuePrinter::indent_
private

Definition at line 118 of file ValuePrinter.h.

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

Definition at line 117 of file ValuePrinter.h.

bool fhicl::detail::ValuePrinter::print_encapsulated_values_ {false}
private

Definition at line 122 of file ValuePrinter.h.

std::size_t fhicl::detail::ValuePrinter::seq_size_
private

Definition at line 120 of file ValuePrinter.h.

std::stack<std::size_t> fhicl::detail::ValuePrinter::sequence_sizes_
private

Definition at line 119 of file ValuePrinter.h.

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

Definition at line 121 of file ValuePrinter.h.


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