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

#include "Prettifier.h"

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

Public Types

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

Public Member Functions

 Prettifier (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 ()
 
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_
 

Detailed Description

Definition at line 88 of file Prettifier.h.

Member Typedef Documentation

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

Definition at line 80 of file ParameterSetWalker.h.

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

Definition at line 79 of file ParameterSetWalker.h.

Constructor & Destructor Documentation

Prettifier::Prettifier ( unsigned  initial_indent_level = 0)

Definition at line 17 of file Prettifier.cc.

References seq_size_, sequence_sizes_, and table_size_.

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

Member Function Documentation

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

Implements fhicl::ParameterSetWalker.

Definition at line 84 of file Prettifier.cc.

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

Referenced by result().

85 {
87  << printed_suffix(key, seq_size_) << nl();
88 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::ostringstream buffer_
Definition: Prettifier.h:116
std::string value(boost::any const &)
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 26 of file Prettifier.cc.

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

Referenced by result().

29 {
30  if (!is_table(a))
31  return;
32  table_size_ = ps->get<fhicl::ParameterSet>(key).get_all_keys().size();
33 }
bool is_table(boost::any const &val)
Definition: coding.h:56
void fhicl::ParameterSetWalker::do_after_action ( )
inlineinherited

Definition at line 104 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::after_action().

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

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

Definition at line 93 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::atom().

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

94  {
95  atom(k, a);
96  }
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 99 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::before_action().

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

100  {
101  before_action(k, a, ps);
102  }
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 88 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::enter_sequence().

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

89  {
90  enter_sequence(k, a);
91  }
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 83 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::enter_table().

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

84  {
85  enter_table(k, a);
86  }
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 110 of file ParameterSetWalker.h.

References fhicl::ParameterSetWalker::exit_table().

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

111  {
112  exit_table(k, a);
113  }
virtual void exit_table(key_t const &, any_t const &)
void Prettifier::enter_sequence ( key_t const &  key,
any_t const &  a 
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 55 of file Prettifier.cc.

References buffer_, indent_, maybe_nl_(), fhicl::detail::sequence::printed_prefix(), fhicl::detail::Indentation::push(), push_size_(), and seq_size_.

Referenced by result().

56 {
57  push_size_(a);
59  indent_.push();
60 }
std::string printed_prefix(std::string const &key)
void push_size_(any_t const &)
Definition: Prettifier.cc:93
std::ostringstream buffer_
Definition: Prettifier.h:116
std::string maybe_nl_(std::size_t)
Definition: Prettifier.cc:113
void Prettifier::enter_table ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Implements fhicl::ParameterSetWalker.

Definition at line 38 of file Prettifier.cc.

References buffer_, indent_, maybe_nl_(), fhicl::detail::table::printed_prefix(), fhicl::detail::Indentation::push(), and table_size_.

Referenced by result().

39 {
41  indent_.push();
42 }
std::string printed_prefix(std::string const &key)
std::ostringstream buffer_
Definition: Prettifier.h:116
std::string maybe_nl_(std::size_t)
Definition: Prettifier.cc:113
void Prettifier::exit_sequence ( key_t const &  key,
any_t const &   
)
overrideprivatevirtual

Reimplemented from fhicl::ParameterSetWalker.

Definition at line 63 of file Prettifier.cc.

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

Referenced by result().

64 {
65  // FIXME: To support a printout like:
66  //
67  // empty: []
68  //
69  // We need to first capture the size of the sequence (0) before we
70  // call pop_size_(). However, for non-empty sequences (I think...)
71  // pop_size_ needs to be called before we determine if an
72  // indentation should take place. This needs to be cleaned up.
73  bool const empty_sequence = seq_size_ == 0;
74  indent_.pop();
75  pop_size_();
76  buffer_ << (empty_sequence ? "" : maybe_indent_(seq_size_))
78  << nl();
79 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string maybe_indent_(std::size_t)
Definition: Prettifier.cc:107
std::ostringstream buffer_
Definition: Prettifier.h:116
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 45 of file Prettifier.cc.

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

Referenced by result().

46 {
47  indent_.pop();
49  << printed_suffix(key, seq_size_) << nl();
50 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::string maybe_indent_(std::size_t)
Definition: Prettifier.cc:107
std::ostringstream buffer_
Definition: Prettifier.h:116
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 107 of file Prettifier.cc.

References indent_.

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

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

Definition at line 113 of file Prettifier.cc.

References fhicl::detail::nl().

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

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

Definition at line 100 of file Prettifier.cc.

References seq_size_, and sequence_sizes_.

Referenced by exit_sequence(), and result().

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

Definition at line 93 of file Prettifier.cc.

References seq_size_, and sequence_sizes_.

Referenced by enter_sequence(), and result().

94 {
95  sequence_sizes_.emplace(boost::any_cast<ps_sequence_t>(a).size());
96  seq_size_ = sequence_sizes_.top();
97 }
std::stack< std::size_t > sequence_sizes_
Definition: Prettifier.h:118
std::string fhicl::detail::Prettifier::result ( void  ) const
inline

Definition at line 93 of file Prettifier.h.

References atom(), before_action(), buffer_, enter_sequence(), enter_table(), exit_sequence(), exit_table(), maybe_indent_(), maybe_nl_(), pop_size_(), and push_size_().

94  {
95  return buffer_.str();
96  }
std::ostringstream buffer_
Definition: Prettifier.h:116

Member Data Documentation

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

Definition at line 116 of file Prettifier.h.

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

Indentation fhicl::detail::Prettifier::indent_
private
std::size_t fhicl::detail::Prettifier::seq_size_
private
std::stack<std::size_t> fhicl::detail::Prettifier::sequence_sizes_
private

Definition at line 118 of file Prettifier.h.

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

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

Definition at line 120 of file Prettifier.h.

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


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