1 | |
---|
2 | #include "Indentation.h" |
---|
3 | |
---|
4 | using namespace std; |
---|
5 | |
---|
6 | |
---|
7 | Indentation::Indentation () |
---|
8 | : _tabulationSize(2) |
---|
9 | , _indentation() |
---|
10 | { } |
---|
11 | |
---|
12 | |
---|
13 | Indentation& Indentation::operator++ () |
---|
14 | { |
---|
15 | _indentation.append ( _tabulationSize, ' ' ); |
---|
16 | return *this; |
---|
17 | } |
---|
18 | |
---|
19 | |
---|
20 | Indentation Indentation::operator++ (int) |
---|
21 | { |
---|
22 | Indentation before (*this); |
---|
23 | |
---|
24 | _indentation.append ( _tabulationSize, ' ' ); |
---|
25 | return before; |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | Indentation& 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 | |
---|
39 | Indentation 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 | |
---|
51 | ostream& operator<< ( ostream& o, const Indentation& indent ) |
---|
52 | { |
---|
53 | o << indent._indentation; |
---|
54 | return o; |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | Indentation& indent () |
---|
59 | { |
---|
60 | static Indentation* sharedIndent = new Indentation(); |
---|
61 | return *sharedIndent; |
---|
62 | } |
---|