HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
indent.hpp
1// Copyright Take Vos 2020, 2022.
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 "utility/module.hpp"
8
9namespace hi::inline v1 {
10
15class indent {
16public:
17 [[nodiscard]] constexpr ~indent() noexcept = default;
18 [[nodiscard]] constexpr indent() noexcept = default;
19 [[nodiscard]] constexpr indent(indent const& other) noexcept = default;
20 [[nodiscard]] constexpr indent(indent&& other) noexcept = default;
21 [[nodiscard]] constexpr indent& operator=(indent const& other) noexcept = default;
22 [[nodiscard]] constexpr indent& operator=(indent&& other) noexcept = default;
23
30 [[nodiscard]] constexpr indent(int spaces, char space = ' ') noexcept : _space(space), _spaces(spaces), _depth(0) {}
31
34 [[nodiscard]] operator std::string() const noexcept
35 {
36 return std::string(narrow_cast<std::size_t>(_depth) * narrow_cast<std::size_t>(_spaces), _space);
37 }
38
41 constexpr indent &operator+=(int rhs) noexcept
42 {
43 _depth += rhs;
44 return *this;
45 }
46
49 constexpr indent &operator++() noexcept
50 {
51 ++_depth;
52 return *this;
53 }
54
57 [[nodiscard]] constexpr friend indent operator+(indent lhs, int rhs) noexcept
58 {
59 lhs += rhs;
60 return lhs;
61 }
62
63private:
64 char _space = ' ';
65 int _spaces = 4;
66 int _depth = 0;
67};
68
69} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:13
Indentation for writing out text files.
Definition indent.hpp:15
constexpr indent(int spaces, char space=' ') noexcept
Constructor This constructor will start indentation at depth 0.
Definition indent.hpp:30
constexpr friend indent operator+(indent lhs, int rhs) noexcept
Get an indentation at increased depth.
Definition indent.hpp:57
constexpr indent & operator++() noexcept
Increment the depth of this indentation.
Definition indent.hpp:49
constexpr indent & operator+=(int rhs) noexcept
Increase the depth of this indentation.
Definition indent.hpp:41