summaryrefslogtreecommitdiff
path: root/include/llvm/Support/IOManip.h
blob: fa9228f576a646c1526692c89876e2b3237b0c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//===----------------- IOManip.h - iostream manipulators ---------*- C++ -*===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Manipulators to do special-purpose formatting.
//
//===----------------------------------------------------------------------===//

namespace llvm {
  /// Indent - Insert spaces into the character output stream.  The
  /// "level" is multiplied by the "scale" to calculate the number of
  /// spaces to insert.  "level" can represent something like loop
  /// nesting level, for example.
  ///
  class Indent {
  public:
    explicit Indent(int lvl, int amt = 2)
        : level(lvl), scale(amt) {}

    template<typename OStream>
    OStream &operator()(OStream &out) const {
      for(int i = 0; i < level*scale; ++i) {
        out << " ";
      }
      return out;
    }

  private:
    int level;
    int scale;
  };

  template<typename OStream>
  OStream &operator<<(OStream &out, const Indent &indent)
  {
    return(indent(out));
  }
}