18 , mType(Type::UnsignedInteger)
24 , mType(Type::SignedInteger)
30 , mType(Type::UnsignedInteger)
36 , mType(Type::SignedInteger)
42 , mType(Type::UnsignedInteger)
48 , mType(Type::SignedInteger)
54 , mType(Type::UnsignedInteger)
60 , mType(Type::SignedInteger)
66 , mType(Type::UnsignedInteger)
83 const std::string_view& value) noexcept
84 : mType(Type::StringView)
86 mStringView.Data = value.data();
87 mStringView.Length = value.length();
127 return TryGetInteger(value);
132 return TryGetInteger(value);
137 return TryGetInteger(value);
142 return TryGetInteger(value);
147 return TryGetInteger(value);
152 return TryGetInteger(value);
157 return TryGetInteger(value);
162 return TryGetInteger(value);
167 return TryGetInteger(value);
172 if (mType == Type::Float)
177 else if (mType == Type::SignedInteger || mType == Type::UnsignedInteger)
182 else if (mType == Type::StringView)
184 const char*
end = mStringView.Data + mStringView.Length;
186 float tempValue = {};
188 const auto result =
FromChars(mStringView.Data,
end, tempValue);
190 if (result.ec == std::errc() && result.ptr ==
end)
202 if (mType == Type::Float)
207 else if (mType == Type::Double)
212 else if (mType == Type::SignedInteger || mType == Type::UnsignedInteger)
217 else if (mType == Type::StringView)
219 const char*
end = mStringView.Data + mStringView.Length;
221 double tempValue = {};
223 const auto result =
FromChars(mStringView.Data,
end, tempValue);
225 if (result.ec == std::errc() && result.ptr ==
end)
237 if (mType != Type::StringView)
240 value = std::string_view(mStringView.Data, mStringView.Length);
254 return std::to_string(
static_cast<uint64_t
>(
mInteger));
256 return std::to_string(
mFloat);
258 return std::to_string(
mDouble);
275 return wxString() <<
static_cast<uint64_t
>(
mInteger);
277 return wxString() <<
mFloat;
287template <
typename ResultType>
291 constexpr int64_t maxValue = std::numeric_limits<ResultType>::max();
293 if (minValue <= value && value <= maxValue)
295 output =
static_cast<ResultType
>(value);
302template <
typename ResultType>
305 constexpr uint64_t maxValue = std::numeric_limits<ResultType>::max();
306 const uint64_t unsignedValue =
static_cast<uint64_t
>(value);
308 if (unsignedValue <= maxValue)
310 output =
static_cast<ResultType
>(unsignedValue);
317template <
typename ResultType>
320 static_assert(std::is_integral_v<ResultType>);
322 if (mType == Type::SignedInteger)
326 else if (mType == Type::UnsignedInteger)
328 return CheckInteger(value,
static_cast<uint64_t
>(mInteger));
330 else if (mType == Type::StringView)
332 const char*
end = mStringView.Data + mStringView.Length;
334 ResultType tempValue = {};
336 const auto result =
FromChars(mStringView.Data,
end, tempValue);
338 if (result.ec == std::errc() && result.ptr ==
end)
FromCharsResult FromChars(const char *buffer, const char *last, float &value) noexcept
Parse a string into a single precision floating point value, always uses the dot as decimal.
Declare functions to convert numeric types to string representation.
bool CheckInteger(ResultType &output, int64_t value) noexcept
bool IsUnsignedInteger() const noexcept
Check if view has the UnsignedInteger type.
std::string ToString() const
Convert the view value to an UTF8 string.
bool IsNull() const noexcept
Check if view is Null.
wxString ToWString() const
Convert the view value to wxString.
bool IsSignedInteger() const noexcept
Check if view has the SignedInteger type.
struct XMLAttributeValueView::@138::@140 mStringView
XMLAttributeValueView()=default
Construct an uninitialized view of type Null.
Type
Type of the value represented by the XMLAttributeValueView.
@ Float
The value is a single precision floating point value.
@ SignedInteger
The value is a signed integer.
@ UnsignedInteger
The value is an unsigned integer.
@ Null
The value is not initialized.
@ StringView
The value is a string_view.
@ Double
The value is a double precision floating point value.
bool IsStringView() const noexcept
Check if view has the StringView type.
bool TryGetInteger(ResultType &value) const noexcept
bool IsFloat() const noexcept
Check if view has the Float type.
bool IsDouble() const noexcept
Check if view has the Double type.
Type GetType() const noexcept
Get the view type.
bool TryGet(bool &value) const noexcept
Try to get a boolean value from the view.
const char * end(const char *str) noexcept