Maze Builder Docs 8.2.1
Loading...
Searching...
No Matches
processed_text.h
Go to the documentation of this file.
1#ifndef PROCESSED_TEXT_H
2#define PROCESSED_TEXT_H
3
4#include <array>
5#include <type_traits>
6#include <variant>
7
10namespace mazes
11{
13 class processed_text final
14 {
16 using artifacts = std::variant<std::monostate, std::string, std::string_view, char*>;
17
18 static constexpr auto DIRTY_INDEX = 0, PROCESSED_INDEX = 1, BUFFER_SIZE = 2;
19
20 public:
23 [[nodiscard]] artifacts get_dirty() const noexcept { return doubled_buffer.at(DIRTY_INDEX); }
24
27 [[nodiscard]] artifacts get_processed() const noexcept { return doubled_buffer.at(PROCESSED_INDEX); }
28
31 void set_dirty(artifacts anything) noexcept { doubled_buffer.at(DIRTY_INDEX) = std::move(anything); }
32
35 void set_processed(artifacts anything) noexcept { doubled_buffer.at(PROCESSED_INDEX) = std::move(anything); }
36
39 bool set(const std::string_view sv) noexcept
40 {
41 set_dirty(std::string{sv});
42 return true;
43 }
44
48 [[nodiscard]] bool is_clean() const noexcept
49 {
50 return std::visit([]<typename T0>(const T0& value) -> bool
51 {
52 using T = std::decay_t<T0>;
53 if constexpr (std::is_same_v<T, std::monostate>)
54 {
55 return true; // Consider monostate as clean
56 }
57 else if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>)
58 {
59 return value.empty();
60 }
61 else if constexpr (std::is_same_v<T, char*>)
62 {
63 return value == nullptr || *value == '\0';
64 }
65 else
66 {
67 return false;
68 }
69 }, get_dirty());
70 }
71
72 private:
73 std::array<artifacts, BUFFER_SIZE> doubled_buffer;
74 };
75}
76
77#endif // PROCESSED_TEXT_H
Class for managing processed text resources.
Definition processed_text.h:14
bool is_clean() const noexcept
Checks if the dirty artifact is clean - empty or null.
Definition processed_text.h:48
artifacts get_processed() const noexcept
Gets the processed artifact.
Definition processed_text.h:27
bool set(const std::string_view sv) noexcept
Required by resource_management::load(id, string_view). Stores sv as the dirty (unprocessed) value; r...
Definition processed_text.h:39
void set_processed(artifacts anything) noexcept
Sets the processed artifact.
Definition processed_text.h:35
artifacts get_dirty() const noexcept
Gets the dirty (unprocessed) artifact and the processed artifact.
Definition processed_text.h:23
void set_dirty(artifacts anything) noexcept
Sets the dirty (unprocessed) artifact and the processed artifact.
Definition processed_text.h:31