LeviLamina
Loading...
Searching...
No Matches
Tag.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/platform/Result.h"
7
8// auto generated forward declare list
9// clang-format off
10class IDataInput;
11class IDataOutput;
12class PrintStream;
13// clang-format on
14
15enum class SnbtFormat : uint {
16 Minimize = 0,
17 CompoundLineFeed = 1 << 0,
18 ArrayLineFeed = 1 << 1,
19 Colored = 1 << 2,
20 Console = 1 << 3,
21 ForceAscii = 1 << 4,
22 ForceQuote = 1 << 5,
23 CommentMarks = 1 << 6,
24 Jsonify = ForceQuote | CommentMarks,
25 PartialLineFeed = CompoundLineFeed,
26 AlwaysLineFeed = CompoundLineFeed | ArrayLineFeed,
27 PrettyFilePrint = PartialLineFeed,
28 PrettyChatPrint = PrettyFilePrint | Colored,
29 PrettyConsolePrint = PrettyFilePrint | Colored | Console,
30};
31[[nodiscard]] constexpr SnbtFormat operator|(SnbtFormat const l, SnbtFormat const r) noexcept {
32 return static_cast<SnbtFormat>(
33 static_cast<std::underlying_type_t<SnbtFormat>>(l) | static_cast<std::underlying_type_t<SnbtFormat>>(r)
34 );
35}
36[[nodiscard]] constexpr SnbtFormat operator&(SnbtFormat const l, SnbtFormat const r) noexcept {
37 return static_cast<SnbtFormat>(
38 static_cast<std::underlying_type_t<SnbtFormat>>(l) & static_cast<std::underlying_type_t<SnbtFormat>>(r)
39 );
40}
41
42class Tag {
43protected:
44 constexpr Tag() = default;
45
46public:
47 // Tag inner types define
48 enum class Type : uchar {
49 End = 0x0,
50 Byte = 0x1,
51 Short = 0x2,
52 Int = 0x3,
53 Int64 = 0x4,
54 Float = 0x5,
55 Double = 0x6,
56 ByteArray = 0x7,
57 String = 0x8,
58 List = 0x9,
59 Compound = 0xA,
60 IntArray = 0xB,
61 NumTagTypes = 0xC,
62 };
63 using enum Type;
64
65 template <std::derived_from<Tag> T>
66 T const* as_ptr() const {
67 return static_cast<T const*>(this);
68 }
69 template <std::derived_from<Tag> T>
70 T* as_ptr() {
71 return static_cast<T*>(this);
72 }
73 template <std::derived_from<Tag> T>
74 T const& as() const {
75 return *static_cast<T const*>(this);
76 }
77 template <std::derived_from<Tag> T>
78 T& as() {
79 return *static_cast<T*>(this);
80 }
81
82 [[nodiscard]] bool operator==(Tag const& other) const { return equals(other); }
83
84 LLNDAPI std::string toSnbt(SnbtFormat snbtFormat = SnbtFormat::PrettyFilePrint, uchar indent = 4) const noexcept;
85
86public:
87 // virtual functions
88 // NOLINTBEGIN
89 virtual ~Tag() = default;
90
91 virtual void deleteChildren();
92
93 virtual void write(::IDataOutput& dos) const = 0;
94
95 virtual ::Bedrock::Result<void> load(::IDataInput& dis) = 0;
96
97 virtual ::std::string toString() const = 0;
98
99 virtual ::Tag::Type getId() const = 0;
100
101 virtual bool equals(::Tag const& rhs) const = 0;
102
103 virtual void print(::PrintStream& out) const;
104
105 virtual void print(::std::string const& prefix, ::PrintStream& out) const;
106
107 virtual ::std::unique_ptr<::Tag> copy() const = 0;
108
109 virtual uint64 hash() const = 0;
110 // NOLINTEND
111
112public:
113 // static functions
114 // NOLINTBEGIN
115 MCAPI static ::Bedrock::Result<::std::unique_ptr<::Tag>> newTag(::Tag::Type type);
116 // NOLINTEND
117
118public:
119 // virtual function thunks
120 // NOLINTBEGIN
121 MCFOLD void $deleteChildren();
122
123 MCAPI void $print(::PrintStream& out) const;
124
125 MCAPI void $print(::std::string const& prefix, ::PrintStream& out) const;
126
127
128 // NOLINTEND
129};
Definition IDataInput.h:8
Definition IDataOutput.h:5
Definition PrintStream.h:5