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 <type_traits>
15#include <utility>
16
22
23namespace MGL::Text
24{
27{
28public:
29 /* ------------------------------------------------------------------------- */
33 /* ------------------------------------------------------------------------- */
34 FormatArgument() noexcept
35 : _type(Type::Void)
36 , _i(0)
37 {}
38
39 /* ------------------------------------------------------------------------- */
45 /* ------------------------------------------------------------------------- */
46 template <typename T>
47 FormatArgument(const T &value) noexcept
48 : _type(Type::Void)
49 , _i(0)
50 {
51 // 整数
52 if constexpr (std::is_integral_v<T>)
53 {
54 // 符号付き
55 if constexpr (std::is_signed_v<T>)
56 {
57 _type = Type::Int;
58 _i = value;
59 }
60 // 符号なし
61 else
62 {
63 _type = Type::UnsignedInt;
64 _ui = value;
65 }
66 }
67 // 浮動小数点数
68 else if constexpr (std::is_floating_point_v<T>)
69 {
70 _type = Type::Float;
71 _f = value;
72 }
73 // bool型
74 else if constexpr (std::is_same_v<T, bool>)
75 {
76 _type = Type::Bool;
77 _b = value;
78 }
79 // MGL::STL::string型
80 else if constexpr (std::is_same_v<T, STL::string>)
81 {
82 _type = Type::String;
83 _i = 0;
84 _string = value;
85 }
86 // その他 const char *型に変換可能な型
87 else if constexpr (std::is_convertible_v<T, const char *>)
88 {
89 _type = Type::String;
90 _i = 0;
91 _string = value;
92 }
93 // 上記以外のポインタ型
94 else if constexpr (std::is_pointer_v<T>)
95 {
96 _type = Type::Pointer;
97 _ui = reinterpret_cast<uint64_t>(value);
98 }
99 // それ以外は不明
100 else
101 {
102 static_assert(true, "Unknown format type detected. Please cast int, float, or const char * type.");
103 }
104 }
105
106 [[nodiscard]] STL::string ToString(const FormatOptions &options = FormatOptions()) const noexcept;
107
108 static const char *Parse(FormatOptions &options, const char *parseText) noexcept;
109
110 static STL::vector<IndexedCharacter> ToIndexedCharacters(const FormatOptions &options) noexcept;
111
112private:
114 enum class Type : uint8_t
115 {
116 Void,
117 Int,
118 UnsignedInt,
119 Float,
120 Bool,
121 String,
122 Pointer,
123 };
124
125 [[nodiscard]] bool IsZero() const noexcept;
126 [[nodiscard]] bool IsPositiveValue() const noexcept;
127 [[nodiscard]] bool IsNegativeValue() const noexcept;
128 [[nodiscard]] STL::string ToStringFromNumber(const FormatOptions &options) const noexcept;
129 [[nodiscard]] STL::string ToStringFromDecimal(const FormatOptions &options) const noexcept;
130 [[nodiscard]] STL::string ToHexStringFromValue(const FormatOptions &options) const noexcept;
131
132 static void AlignmentString(STL::string &result, const FormatOptions &options, const STL::string &string) noexcept;
133
134 Type _type;
135 union
136 {
137 int64_t _i;
138 uint64_t _ui;
139 float _f;
140 bool _b;
141 };
142
143 STL::string _string;
144};
145
148
149} // namespace MGL::Text
150
151#endif // INCGUARD_MGL_TEXT_FORMAT_ARGUMENT_H_1622208320
152
153// vim: et ts=4 sw=4 sts=4
テキストフォーマットの引数
Definition mgl_text_format_argument.h:27
FormatArgument(const T &value) noexcept
コンストラクタ
Definition mgl_text_format_argument.h:47
static STL::vector< IndexedCharacter > ToIndexedCharacters(const FormatOptions &options) noexcept
置換オプションをインデックス文字に変換
Definition mgl_text_format_argument.cc:242
FormatArgument() noexcept
コンストラクタ
Definition mgl_text_format_argument.h:34
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
文字列の参照のみを行うファイルパスクラス
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:147
MGL テキストフォーマットのオプション
フォーマットオプション
Definition mgl_text_format_options.h:19