2011CaoTme7: Indentation.cpp

File Indentation.cpp, 1.0 KB (added by jpc, 14 years ago)

C++ Module: Classe Indentation

Line 
1
2#include "Indentation.h"
3
4using namespace std;
5
6
7Indentation::Indentation ()
8 : _tabulationSize(2)
9 , _indentation()
10{ }
11
12
13Indentation& Indentation::operator++ ()
14{
15 _indentation.append ( _tabulationSize, ' ' );
16 return *this;
17}
18
19
20Indentation Indentation::operator++ (int)
21{
22 Indentation before (*this);
23
24 _indentation.append ( _tabulationSize, ' ' );
25 return before;
26}
27
28
29Indentation& Indentation::operator-- ()
30{
31 if ( _indentation.length() > _tabulationSize )
32 _indentation.resize ( _indentation.length() - _tabulationSize );
33 else
34 _indentation.clear ();
35 return *this;
36}
37
38
39Indentation Indentation::operator-- (int)
40{
41 Indentation before (*this);
42
43 if ( _indentation.length() > _tabulationSize )
44 _indentation.resize ( _indentation.length() - _tabulationSize );
45 else
46 _indentation.clear ();
47 return before;
48}
49
50
51ostream& operator<< ( ostream& o, const Indentation& indent )
52{
53 o << indent._indentation;
54 return o;
55}
56
57
58Indentation& indent ()
59{
60 static Indentation* sharedIndent = new Indentation();
61 return *sharedIndent;
62}