ValuePrinter.cc
Go to the documentation of this file.
3 #include "fhiclcpp/coding.h"
6 
7 #include <limits>
8 
9 using namespace fhicl;
10 using namespace fhicl::detail;
11 
12 namespace {
13  constexpr auto size_t_max = std::numeric_limits<std::size_t>::max();
14 }
15 
16 //==========================================================================
17 
19  unsigned const initial_indent_level)
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 {}
26 
27 //==========================================================================
28 void
30  any_t const& a,
31  ParameterSet const* ps)
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 }
40 
41 void
43 {
44  if (key_ == key) {
46  }
47 }
48 
49 //==========================================================================
50 
51 void
52 ValuePrinter::enter_table(std::string const& key, std::any const&)
53 {
55  return;
57  indent_.push();
58 }
59 
60 void
61 ValuePrinter::exit_table(std::string const& key, std::any const&)
62 {
64  return;
65  indent_.pop();
67  << printed_suffix(key, seq_size_) << nl();
68 }
69 
70 //==========================================================================
71 
72 void
74 {
76  return;
77  push_size_(a);
79  indent_.push();
80 }
81 
82 void
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 }
102 
103 //==========================================================================
104 
105 void
106 ValuePrinter::atom(std::string const& key, std::any const& a)
107 {
109  return;
111  << printed_suffix(key, seq_size_) << nl();
112 }
113 
114 //=========================================================================
115 
116 void
117 ValuePrinter::push_size_(std::any const& a)
118 {
119  sequence_sizes_.emplace(std::any_cast<ps_sequence_t>(a).size());
120  seq_size_ = sequence_sizes_.top();
121 }
122 
123 void
125 {
126  sequence_sizes_.pop();
127  seq_size_ = sequence_sizes_.top();
128 }
129 
131 ValuePrinter::maybe_indent_(std::size_t const sz)
132 {
133  return sz ? indent_() : "";
134 }
135 
137 ValuePrinter::maybe_nl_(std::size_t const sz)
138 {
139  return sz ? nl() : "";
140 }
std::string printed_suffix(std::string const &key, std::size_t const sz)
std::stack< std::size_t > sequence_sizes_
Definition: ValuePrinter.h:119
void after_action(key_t const &) override
Definition: ValuePrinter.cc:42
std::string printed_prefix(std::string const &key)
std::string string
Definition: nybbler.cc:12
void exit_sequence(key_t const &, any_t const &) override
Definition: ValuePrinter.cc:83
std::string maybe_nl_(std::size_t)
void push_size_(any_t const &)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
ValuePrinter(std::string const &key, unsigned initial_indent_level=0)
Definition: ValuePrinter.cc:18
void enter_sequence(key_t const &, any_t const &) override
Definition: ValuePrinter.cc:73
void atom(key_t const &, any_t const &) override
std::string printed_prefix(std::string const &key)
def key(type, name=None)
Definition: graph.py:13
const double a
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::string value(std::any const &)
std::string maybe_indent_(std::size_t)
static int max(int a, int b)
static constexpr double ps
Definition: Units.h:99
void before_action(key_t const &, any_t const &, ParameterSet const *) override
Definition: ValuePrinter.cc:29
void enter_table(key_t const &, any_t const &) override
Definition: ValuePrinter.cc:52
bool is_table(std::any const &val)
Definition: coding.h:55
std::ostringstream buffer_
Definition: ValuePrinter.h:116
void exit_table(key_t const &, any_t const &) override
Definition: ValuePrinter.cc:61
std::string printed_prefix(std::string const &key)
std::string nl(std::size_t i=1)
std::string closing_brace()