AGX Dynamics  2.35.0.1
Indentation.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_INDENTATION_H
18 #define AGX_INDENTATION_H
19 
20 #include <agx/Integer.h>
21 #include <agx/String.h>
22 #include <iostream>
23 
24 namespace agx
25 {
27  {
28  public:
29  static const agx::UInt TabSize = 2;
30 
31 
32  Indentation() : m_level(0) {}
33  Indentation(agx::UInt level) : m_level(level) {}
34 
35  agx::UInt getLevel() const { return m_level; }
36  agx::UInt getIndentation() const { return m_level * TabSize; }
37 
43  String apply(const String& string);
44 
45  Indentation& operator+= (int increment) { m_level += increment; return *this; }
46  Indentation& operator-= (int decrement) { m_level -= decrement; return *this; }
47 
48  Indentation operator+ (int increment) const { return Indentation(m_level + increment); }
49  Indentation operator- (int decrement) const { return Indentation(m_level - decrement); }
50 
51  Indentation& operator++() { m_level++; return *this; }
52  Indentation operator++(int) { m_level++; return Indentation(m_level - 1); }
53 
54  Indentation& operator--() { m_level--; return *this; }
55  Indentation operator--(int) { m_level--; return Indentation(m_level + 1); }
56 
57  String str() const { return String(getIndentation(), ' '); }
58  operator String() const { return str(); }
59 
60  private:
61  agx::UInt m_level;
62  };
63 
64 
65  template<typename T>
66  AgXString<T> operator+ ( const Indentation& indentation, const AgXString<T>& str )
67  {
68  return indentation.str() + str;
69  }
70 
71 
72  inline std::ostream& operator<< (std::ostream& stream, const Indentation& indentation)
73  {
74  stream << indentation.str();
75  return stream;
76  }
77 
78 }
79 
80 
81 #endif /* AGX_INDENTATION_H */
#define AGXCORE_EXPORT
Indentation & operator--()
Definition: Indentation.h:54
String str() const
Definition: Indentation.h:57
Indentation operator--(int)
Definition: Indentation.h:55
String apply(const String &string)
Indent a text, applied for each line in input string.
Indentation & operator++()
Definition: Indentation.h:51
agx::UInt getIndentation() const
Definition: Indentation.h:36
Indentation(agx::UInt level)
Definition: Indentation.h:33
agx::UInt getLevel() const
Definition: Indentation.h:35
Indentation operator++(int)
Definition: Indentation.h:52
AGXCABLE_EXPORT SegmentDamage & operator+=(SegmentDamage &lhs, const SegmentDamage &rhs)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
ItT operator-(const ItT &it, const agx::ItOp &inc)
Definition: List.h:101
AgXString< T > operator+(const Indentation &indentation, const AgXString< T > &str)
Definition: Indentation.h:66
AgXString< std::string > String
Definition: String.h:423
uint32_t UInt
Definition: Integer.h:34
std::ostream & operator<<(std::ostream &stream, const AtomicValueT< T > &value)
Definition: AtomicValue.h:109