Indenter.h
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 #ifndef NUKLEI_INDENTER_H
8 #define NUKLEI_INDENTER_H
9 
10 #include <string>
11 #include <iostream>
12 
13 namespace nuklei {
14 
15 
16  class Indenter
17  {
18  public:
19  Indenter(std::ostream &out = std::cout, std::string step = " ");
20  ~Indenter();
21 
22  template<class T>
23  friend std::ostream& operator<<(Indenter &idt, const T &t);
24 
25  static int main(int argc, char ** argv);
26 
27  private:
28  static int level;
29  std::ostream &out;
30  std::string step;
31  };
32 
33  template<class T>
34  std::ostream& operator<<(Indenter &idt, const T &t)
35  {
36  std::string tab = "";
37  for (int i=0; i < idt.level; i++)
38  tab += idt.step;
39 
40  idt.out << tab << t;
41  return idt.out;
42  }
43 
44 }
45 
46 #endif
Public namespace.
Definition: Color.cpp:9
Definition: Indenter.h:16
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.