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#pragma once
6
7#include "cast.hpp"
8
9namespace hi::inline v1 {
10
15class indent {
16public:
23 [[nodiscard]] constexpr indent(int spaces = 4, char space = ' ') noexcept : _space(space), _spaces(spaces), _depth(0) {}
24
25 [[nodiscard]] constexpr indent(indent const &other) noexcept :
26 _space(other._space), _spaces(other._spaces), _depth(other._depth)
27 {
28 }
29
30 [[nodiscard]] constexpr indent(indent &&other) noexcept : _space(other._space), _spaces(other._spaces), _depth(other._depth)
31 {
32 }
33
34 [[nodiscard]] constexpr indent &operator=(indent const &other) noexcept
35 {
36 // Self-assignment is allowed.
37 _space = other._space;
38 _spaces = other._spaces;
39 _depth = other._depth;
40 return *this;
41 }
42
43 [[nodiscard]] constexpr indent &operator=(indent &&other) noexcept
44 {
45 // Self-assignment is allowed.
46 _space = other._space;
47 _spaces = other._spaces;
48 _depth = other._depth;
49 return *this;
50 }
51
54 [[nodiscard]] operator std::string() const noexcept
55 {
56 return std::string(narrow_cast<std::size_t>(_depth) * narrow_cast<std::size_t>(_spaces), _space);
57 }
58
61 constexpr indent &operator+=(int rhs) noexcept
62 {
63 _depth += rhs;
64 return *this;
65 }
66
69 constexpr indent &operator++() noexcept
70 {
71 ++_depth;
72 return *this;
73 }
74
77 [[nodiscard]] constexpr friend indent operator+(indent lhs, int rhs) noexcept
78 {
79 lhs += rhs;
80 return lhs;
81 }
82
83private:
84 char _space;
85 int _spaces;
86 int _depth;
87};
88
89} // namespace hi::inline v1
Indentation for writing out text files.
Definition indent.hpp:15
constexpr friend indent operator+(indent lhs, int rhs) noexcept
Get an indentation at increased depth.
Definition indent.hpp:77
constexpr indent & operator++() noexcept
Increment the depth of this indentation.
Definition indent.hpp:69
constexpr indent(int spaces=4, char space=' ') noexcept
Constructor This constructor will start indentation at depth 0.
Definition indent.hpp:23
constexpr indent & operator+=(int rhs) noexcept
Increase the depth of this indentation.
Definition indent.hpp:61