LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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 {
20  namespace detail {
21 
22  class Indentation {
23  public:
24  Indentation(unsigned const iil = 0u)
25  : indents_{{std::string(iil * indent_increment, ' ')}}
26  {}
27 
28  Indentation(std::string const& prefix) : indents_{{prefix}} {}
29 
30  std::string const&
31  operator()() const
32  {
33  return indents_.top();
34  }
35 
36  void
37  modify_top(std::string const& s)
38  {
39  assert(!indents_.empty());
40  if (indents_.size() == 1ul) {
41  indents_.top() = s;
42  } else {
43  indents_.pop();
44  indents_.emplace(indents_.top() + s);
45  }
46  }
47 
48  auto
49  size()
50  {
51  return indents_.size();
52  }
53 
54  void
55  pop()
56  {
57  indents_.pop();
58  }
59  void
60  push()
61  {
62  indents_.emplace(indents_.top() + std::string(indent_increment, ' '));
63  }
64 
65  private:
66  static constexpr std::size_t indent_increment = 3u;
67  std::stack<std::string> indents_;
68  };
69  }
70 }
71 
72 #endif /* fhiclcpp_detail_Indentation_h */
73 
74 // Local variables:
75 // mode: c++
76 // End:
Float_t s
Definition: plot.C:23
std::stack< std::string > indents_
Definition: Indentation.h:67
std::string const & operator()() const
Definition: Indentation.h:31
void modify_top(std::string const &s)
Definition: Indentation.h:37
parameter set interface
Indentation(std::string const &prefix)
Definition: Indentation.h:28
static constexpr std::size_t indent_increment
Definition: Indentation.h:66
Indentation(unsigned const iil=0u)
Definition: Indentation.h:24