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

#include <Prettifier.h>

Inheritance diagram for fhicl::detail::Prettifier:
fhicl::ParameterSetWalker

Public Member Functions

 Prettifier (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 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_ {}
 
Indentation indent_
 
std::stack< std::size_t > sequence_sizes_
 
std::size_t seq_size_
 
std::size_t table_size_
 

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 Prettifier.h.

Constructor & Destructor Documentation

Prettifier::Prettifier ( unsigned  initial_indent_level = 0)

Definition at line 18 of file Prettifier.cc.

19  : indent_{initial_indent_level}
20  , sequence_sizes_{{size_t_max}}
21  , seq_size_{sequence_sizes_.top()}
22  , table_size_{0u}
23 {}
std::stack< std::size_t > sequence_sizes_
Definition: Prettifier.h:116

Member Function Documentation

void Prettifier::atom ( key_t const &  key,
any_t const &  a 
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 85 of file Prettifier.cc.

86 {
88  << printed_suffix(key, seq_size_) << nl();
89 }
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: Prettifier.h:114
std::string printed_prefix(std::string const &key)
std::string nl(std::size_t i=1)
void Prettifier::before_action ( key_t const &  key,
any_t const &  a,
ParameterSet const *  ps 
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 27 of file Prettifier.cc.

30 {
31  if (!is_table(a))
32  return;
33  table_size_ = ps->get<fhicl::ParameterSet>(key).get_all_keys().size();
34 }
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 Prettifier::enter_sequence ( key_t const &  key,
any_t const &  a 
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 56 of file Prettifier.cc.

57 {
58  push_size_(a);
60  indent_.push();
61 }
std::string printed_prefix(std::string const &key)
void push_size_(any_t const &)
Definition: Prettifier.cc:94
def key(type, name=None)
Definition: graph.py:13
const double a
std::ostringstream buffer_
Definition: Prettifier.h:114
std::string maybe_nl_(std::size_t)
Definition: Prettifier.cc:114
void Prettifier::enter_table ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 39 of file Prettifier.cc.

40 {
42  indent_.push();
43 }
std::string printed_prefix(std::string const &key)
def key(type, name=None)
Definition: graph.py:13
std::ostringstream buffer_
Definition: Prettifier.h:114
std::string maybe_nl_(std::size_t)
Definition: Prettifier.cc:114
void Prettifier::exit_sequence ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 64 of file Prettifier.cc.

65 {
66  // FIXME: To support a printout like:
67  //
68  // empty: []
69  //
70  // We need to first capture the size of the sequence (0) before we
71  // call pop_size_(). However, for non-empty sequences (I think...)
72  // pop_size_ needs to be called before we determine if an
73  // indentation should take place. This needs to be cleaned up.
74  bool const empty_sequence = seq_size_ == 0;
75  indent_.pop();
76  pop_size_();
77  buffer_ << (empty_sequence ? "" : maybe_indent_(seq_size_))
79  << nl();
80 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string maybe_indent_(std::size_t)
Definition: Prettifier.cc:108
def key(type, name=None)
Definition: graph.py:13
std::ostringstream buffer_
Definition: Prettifier.h:114
std::string nl(std::size_t i=1)
void Prettifier::exit_table ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 46 of file Prettifier.cc.

47 {
48  indent_.pop();
50  << printed_suffix(key, seq_size_) << nl();
51 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string maybe_indent_(std::size_t)
Definition: Prettifier.cc:108
def key(type, name=None)
Definition: graph.py:13
std::ostringstream buffer_
Definition: Prettifier.h:114
std::string nl(std::size_t i=1)
std::string closing_brace()
std::string Prettifier::maybe_indent_ ( std::size_t  sz)
private

Definition at line 108 of file Prettifier.cc.

109 {
110  return sz ? indent_() : "";
111 }
std::string Prettifier::maybe_nl_ ( std::size_t  sz)
private

Definition at line 114 of file Prettifier.cc.

115 {
116  return sz ? nl() : "";
117 }
std::string nl(std::size_t i=1)
void Prettifier::pop_size_ ( )
private

Definition at line 101 of file Prettifier.cc.

102 {
103  sequence_sizes_.pop();
104  seq_size_ = sequence_sizes_.top();
105 }
std::stack< std::size_t > sequence_sizes_
Definition: Prettifier.h:116
void Prettifier::push_size_ ( any_t const &  a)
private

Definition at line 94 of file Prettifier.cc.

95 {
96  sequence_sizes_.emplace(std::any_cast<ps_sequence_t>(a).size());
97  seq_size_ = sequence_sizes_.top();
98 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
const double a
std::stack< std::size_t > sequence_sizes_
Definition: Prettifier.h:116
std::string fhicl::detail::Prettifier::result ( ) const
inline

Definition at line 91 of file Prettifier.h.

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

Member Data Documentation

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

Definition at line 114 of file Prettifier.h.

Indentation fhicl::detail::Prettifier::indent_
private

Definition at line 115 of file Prettifier.h.

std::size_t fhicl::detail::Prettifier::seq_size_
private

Definition at line 117 of file Prettifier.h.

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

Definition at line 116 of file Prettifier.h.

std::size_t fhicl::detail::Prettifier::table_size_
private

Definition at line 118 of file Prettifier.h.


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