2010CaoTme2: Indentation.cpp

File Indentation.cpp, 974 bytes (added by jpc, 15 years ago)

Indentation C++ Module

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