MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_text_format_argument.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_TEXT_FORMAT_ARGUMENT_H_1622208320
12#define INCGUARD_MGL_TEXT_FORMAT_ARGUMENT_H_1622208320
13
14#include <utility>
15
21
22namespace MGL::Text
23{
26{
27public:
28 /* ------------------------------------------------------------------------- */
32 /* ------------------------------------------------------------------------- */
33 FormatArgument() noexcept
34 : _type(Type::Void)
35 , _i(0)
36 {}
37
38 /* ------------------------------------------------------------------------- */
43 /* ------------------------------------------------------------------------- */
44 FormatArgument(unsigned long long value) noexcept
45 : _type(Type::UnsignedInt)
46 , _ui(value)
47 {}
48
49 /* ------------------------------------------------------------------------- */
54 /* ------------------------------------------------------------------------- */
55 FormatArgument(unsigned long value) noexcept
56 : FormatArgument(static_cast<uint64_t>(value))
57 {}
58
59 /* ------------------------------------------------------------------------- */
64 /* ------------------------------------------------------------------------- */
65 FormatArgument(unsigned int value) noexcept
66 : FormatArgument(static_cast<uint64_t>(value))
67 {}
68
69 /* ------------------------------------------------------------------------- */
74 /* ------------------------------------------------------------------------- */
75 FormatArgument(unsigned short value) noexcept
76 : FormatArgument(static_cast<uint64_t>(value))
77 {}
78
79 /* ------------------------------------------------------------------------- */
84 /* ------------------------------------------------------------------------- */
85 FormatArgument(unsigned char value) noexcept
86 : FormatArgument(static_cast<uint64_t>(value))
87 {}
88
89 /* ------------------------------------------------------------------------- */
94 /* ------------------------------------------------------------------------- */
95 FormatArgument(long long value) noexcept
96 : _type(Type::Int)
97 , _i(value)
98 {}
99
100 /* ------------------------------------------------------------------------- */
105 /* ------------------------------------------------------------------------- */
106 FormatArgument(long value) noexcept
107 : FormatArgument(static_cast<int64_t>(value))
108 {}
109
110 /* ------------------------------------------------------------------------- */
115 /* ------------------------------------------------------------------------- */
116 FormatArgument(int value) noexcept
117 : FormatArgument(static_cast<int64_t>(value))
118 {}
119
120 /* ------------------------------------------------------------------------- */
125 /* ------------------------------------------------------------------------- */
126 FormatArgument(short value) noexcept
127 : FormatArgument(static_cast<int64_t>(value))
128 {}
129
130 /* ------------------------------------------------------------------------- */
135 /* ------------------------------------------------------------------------- */
136 FormatArgument(char value) noexcept
137 : FormatArgument(static_cast<int64_t>(value))
138 {}
139
140 /* ------------------------------------------------------------------------- */
145 /* ------------------------------------------------------------------------- */
146 FormatArgument(float value) noexcept
147 : _type(Type::Float)
148 , _ui(0)
149 {
150 _f = value;
151 }
152
153 /* ------------------------------------------------------------------------- */
158 /* ------------------------------------------------------------------------- */
159 FormatArgument(double value) noexcept
160 : _type(Type::Float)
161 , _ui(0)
162 {
163 _f = static_cast<float>(value);
164 }
165
166 /* ------------------------------------------------------------------------- */
171 /* ------------------------------------------------------------------------- */
172 FormatArgument(bool value) noexcept
173 : _type(Type::Bool)
174 , _ui(0)
175 {
176 _b = value;
177 }
178
179 /* ------------------------------------------------------------------------- */
184 /* ------------------------------------------------------------------------- */
186 : _type(Type::String)
187 , _i(0)
188 , _string(std::move(value))
189 {}
190
191 /* ------------------------------------------------------------------------- */
196 /* ------------------------------------------------------------------------- */
197 FormatArgument(const char *value) noexcept
198 : _type(Type::String)
199 , _i(0)
200 , _string(value)
201 {}
202
203 /* ------------------------------------------------------------------------- */
208 /* ------------------------------------------------------------------------- */
209 FormatArgument(const File::PathView &value) noexcept
210 : _type(Type::String)
211 , _i(0)
212 , _string(value)
213 {}
214
215 /* ------------------------------------------------------------------------- */
220 /* ------------------------------------------------------------------------- */
221 FormatArgument(const File::Path &value) noexcept
222 : _type(Type::String)
223 , _i(0)
224 , _string(value)
225 {}
226
227 /* ------------------------------------------------------------------------- */
235 /* ------------------------------------------------------------------------- */
236 FormatArgument(const void *value) noexcept
237 : _type(Type::Pointer)
238 , _ui(reinterpret_cast<uint64_t>(value))
239 {}
240
241 [[nodiscard]] STL::string ToString(const FormatOptions &options = FormatOptions()) const noexcept;
242
243 static const char *Parse(FormatOptions &options, const char *parseText) noexcept;
244
245 static STL::vector<IndexedCharacter> ToIndexedCharacters(const FormatOptions &options) noexcept;
246
247private:
249 enum class Type : uint8_t
250 {
251 Void,
252 Int,
253 UnsignedInt,
254 Float,
255 Bool,
256 String,
257 Pointer,
258 };
259
260 [[nodiscard]] bool IsZero() const noexcept;
261 [[nodiscard]] bool IsPositiveValue() const noexcept;
262 [[nodiscard]] bool IsNegativeValue() const noexcept;
263 [[nodiscard]] STL::string ToStringFromNumber(const FormatOptions &options) const noexcept;
264 [[nodiscard]] STL::string ToStringFromDecimal(const FormatOptions &options) const noexcept;
265 [[nodiscard]] STL::string ToHexStringFromValue(const FormatOptions &options) const noexcept;
266
267 static void AlignmentString(STL::string &result, const FormatOptions &options, const STL::string &string) noexcept;
268
269 Type _type;
270 union
271 {
272 int64_t _i;
273 uint64_t _ui;
274 float _f;
275 bool _b;
276 };
277
278 STL::string _string;
279};
280
283
284} // namespace MGL::Text
285
286#endif // INCGUARD_MGL_TEXT_FORMAT_ARGUMENT_H_1622208320
287
288// vim: et ts=4 sw=4 sts=4
ファイルパスクラス
Definition mgl_file_path.h:20
文字列の参照のみを行うファイルパスクラス
Definition mgl_file_path_view.h:20
テキストフォーマットの引数
Definition mgl_text_format_argument.h:26
FormatArgument(const char *value) noexcept
コンストラクタ(const char *)
Definition mgl_text_format_argument.h:197
FormatArgument(double value) noexcept
コンストラクタ(double)
Definition mgl_text_format_argument.h:159
FormatArgument(char value) noexcept
コンストラクタ(char)
Definition mgl_text_format_argument.h:136
FormatArgument(unsigned long long value) noexcept
コンストラクタ(unsigned long long)
Definition mgl_text_format_argument.h:44
FormatArgument(const File::PathView &value) noexcept
コンストラクタ(File::PathView)
Definition mgl_text_format_argument.h:209
FormatArgument(const void *value) noexcept
コンストラクタ(const void *)
Definition mgl_text_format_argument.h:236
FormatArgument(unsigned char value) noexcept
コンストラクタ(unsigned char)
Definition mgl_text_format_argument.h:85
static STL::vector< IndexedCharacter > ToIndexedCharacters(const FormatOptions &options) noexcept
置換オプションをインデックス文字に変換
Definition mgl_text_format_argument.cc:242
FormatArgument(unsigned long value) noexcept
コンストラクタ(unsigned long)
Definition mgl_text_format_argument.h:55
FormatArgument(long long value) noexcept
コンストラクタ(long long)
Definition mgl_text_format_argument.h:95
FormatArgument(short value) noexcept
コンストラクタ(short)
Definition mgl_text_format_argument.h:126
FormatArgument() noexcept
コンストラクタ
Definition mgl_text_format_argument.h:33
FormatArgument(int value) noexcept
コンストラクタ(int)
Definition mgl_text_format_argument.h:116
FormatArgument(unsigned int value) noexcept
コンストラクタ(unsigned int)
Definition mgl_text_format_argument.h:65
FormatArgument(bool value) noexcept
コンストラクタ(bool)
Definition mgl_text_format_argument.h:172
FormatArgument(float value) noexcept
コンストラクタ(float)
Definition mgl_text_format_argument.h:146
FormatArgument(long value) noexcept
コンストラクタ(long)
Definition mgl_text_format_argument.h:106
STL::string ToString(const FormatOptions &options=FormatOptions()) const noexcept
文字列に変換
Definition mgl_text_format_argument.cc:32
static const char * Parse(FormatOptions &options, const char *parseText) noexcept
フォーマット文字列のパース
Definition mgl_text_format_argument.cc:93
FormatArgument(STL::string value) noexcept
コンストラクタ(STL::string)
Definition mgl_text_format_argument.h:185
FormatArgument(unsigned short value) noexcept
コンストラクタ(unsigned short)
Definition mgl_text_format_argument.h:75
FormatArgument(const File::Path &value) noexcept
コンストラクタ(File::Path)
Definition mgl_text_format_argument.h:221
文字列の参照のみを行うファイルパスクラス
MGL STLコンテナの代替
std::vector< T, Allocator< T > > vector
std::vectorの代替
Definition mgl_stl_containers.h:51
MGL STL文字列クラスの代替
basic_string< char > string
std::stringの代替
Definition mgl_stl_string.h:25
MGL テキスト関連各種宣言
uint16_t IndexedCharacter
インデックス化文字
Definition mgl_text_defs.h:30
STL::vector< FormatArgument > FormatArgs
テキストフォーマットの引数の配列
Definition mgl_text_format_argument.h:282
MGL テキストフォーマットのオプション
フォーマットオプション
Definition mgl_text_format_options.h:19