Indentation.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_detail_Indentation_h
2 #define fhiclcpp_detail_Indentation_h
3 
4 // =========================================================
5 //
6 // Indentation
7 //
8 // Used for providing appropriate indentation for
9 // ParameterSet::to_indented_string.
10 //
11 // The 'pop' and 'push' commands must be used symmetrically.
12 //
13 // =========================================================
14 
15 #include <cassert>
16 #include <stack>
17 #include <string>
18 
19 namespace fhicl::detail {
20 
21  class Indentation {
22  public:
23  explicit Indentation(unsigned const iil = 0u)
24  : indents_{{std::string(iil * indent_increment, ' ')}}
25  {}
26 
27  explicit Indentation(std::string const& prefix) : indents_{{prefix}} {}
28 
29  std::string const&
30  operator()() const
31  {
32  return indents_.top();
33  }
34 
35  void
37  {
38  assert(!indents_.empty());
39  if (indents_.size() == 1ul) {
40  indents_.top() = s;
41  } else {
42  indents_.pop();
43  indents_.emplace(indents_.top() + s);
44  }
45  }
46 
47  auto
48  size()
49  {
50  return indents_.size();
51  }
52 
53  void
54  pop()
55  {
56  indents_.pop();
57  }
58  void
59  push()
60  {
61  indents_.emplace(indents_.top() + std::string(indent_increment, ' '));
62  }
63 
64  private:
65  static constexpr std::size_t indent_increment = 3u;
66  std::stack<std::string> indents_;
67  };
68 }
69 
70 #endif /* fhiclcpp_detail_Indentation_h */
71 
72 // Local variables:
73 // mode: c++
74 // End:
std::stack< std::string > indents_
Definition: Indentation.h:66
std::string string
Definition: nybbler.cc:12
std::string const & operator()() const
Definition: Indentation.h:30
void modify_top(std::string const &s)
Definition: Indentation.h:36
Indentation(std::string const &prefix)
Definition: Indentation.h:27
static constexpr std::size_t indent_increment
Definition: Indentation.h:65
Indentation(unsigned const iil=0u)
Definition: Indentation.h:23
static QCString * s
Definition: config.cpp:1042