HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
indent.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5
6#pragma once
7
8#include "cast.hpp"
9
10namespace tt {
11
16class indent {
17public:
24 [[nodiscard]] constexpr indent(int spaces = 4, char space = ' ') noexcept :
25 _space(space), _spaces(spaces), _depth(0) {}
26
27 [[nodiscard]] constexpr indent(indent const &other) noexcept :
28 _space(other._space), _spaces(other._spaces), _depth(other._depth) {}
29
30 [[nodiscard]] constexpr indent(indent &&other) noexcept :
31 _space(other._space), _spaces(other._spaces), _depth(other._depth) {}
32
33 [[nodiscard]] constexpr indent &operator=(indent const &other) noexcept
34 {
35 // Self-assignment is allowed.
36 _space = other._space;
37 _spaces = other._spaces;
38 _depth = other._depth;
39 return *this;
40 }
41
42 [[nodiscard]] constexpr indent &operator=(indent &&other) noexcept
43 {
44 // Self-assignment is allowed.
45 _space = other._space;
46 _spaces = other._spaces;
47 _depth = other._depth;
48 return *this;
49 }
50
53 [[nodiscard]] operator std::string () const noexcept
54 {
55 return std::string(narrow_cast<size_t>(_depth) * narrow_cast<size_t>(_spaces), _space);
56 }
57
60 constexpr indent &operator+=(int rhs) noexcept
61 {
62 _depth += rhs;
63 return *this;
64 }
65
68 constexpr indent &operator++() noexcept
69 {
70 ++_depth;
71 return *this;
72 }
73
76 [[nodiscard]] constexpr friend indent operator+(indent lhs, int rhs) noexcept
77 {
78 lhs += rhs;
79 return lhs;
80 }
81
82private:
83 char _space;
84 int _spaces;
85 int _depth;
86};
87
88
89}
90
Indentation for writing out text files.
Definition indent.hpp:16
constexpr indent & operator+=(int rhs) noexcept
Increase the depth of this indentation.
Definition indent.hpp:60
constexpr indent & operator++() noexcept
Increment the depth of this indentation.
Definition indent.hpp:68
constexpr friend indent operator+(indent lhs, int rhs) noexcept
Get an indentation at increased depth.
Definition indent.hpp:76
constexpr indent(int spaces=4, char space=' ') noexcept
Constructor This constructor will start indentation at depth 0.
Definition indent.hpp:24