33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Angle.h>
61 0.0000000000000000001,
67 template<
class t_type>
85 template<
class t_type>
88 return _parse<t_type>(in, out, Invalid_Value, check_overflow);
90 template<
class t_type>
91 static constexpr t_type
parseUInt(
const char* in,
const char** out, t_type Invalid_Value,
bool check_overflow)
93 if (*in <
'0' || *in >
'9')
99 for (
uint04 i = 0; i < MaxDigits<t_type>() - 1; i++)
101 if (*in <
'0' || *in >
'9')
103 check_overflow =
false;
111 if (*in >=
'0' && *in <=
'9')
113 t_type new_value = (value * 10) + (*in -
'0');
115 if (new_value < value)
117 value = Invalid_Value;
122 if (*in >
'0' && *in <
'9')
123 value = Invalid_Value;
132 template <
class t_
int_type,
typename t_type>
133 static t_type
parseFloat(
const char* c,
const char** out_s, t_type Invalid_Value,
bool check_overflow)
139 return Invalid_Value;
141 bool inv = (*c ==
'-');
142 if (inv || *c ==
'+')
144 t_int_type value = 0;
151 return Invalid_Value;
157 const char* c_old = c;
165 while (*c >=
'0' && *c <=
'9')
169 if (*c ==
'e' || *c ==
'E')
177 float_value = -float_value;
189 if (*in >=
'0' && *in <=
'9')
190 value = (value << 4u) + (*in -
'0');
191 else if (*in >=
'A' && *in <=
'F')
192 value = (value << 4u) + (*in -
'A') + 10;
193 else if (*in >=
'a' && *in <=
'f')
194 value = (value << 4u) + (*in -
'a') + 10;
207 template<
class t_
char_type>
211 if (in >=
'0' && in <=
'9')
213 else if (in >=
'a' && in <=
'f')
214 out = 10u + in -
'a';
215 else if (in >=
'A' && in <=
'F')
216 out = 10u + in -
'A';
223 template<
class t_
char_type>
231 template<
class t_type>
232 static t_type _parse(
const char* in,
const char** out, t_type Invalid_Value,
bool check_overflow);
235 static inline uint01 _parse(
const char* in,
const char** out,
uint01 Invalid_Value,
bool check_overflow)
237 if (*in ==
'+') in++;
238 return parseUInt(in, out, Invalid_Value, check_overflow);
241 static inline uint02 _parse(
const char* in,
const char** out,
uint02 Invalid_Value,
bool check_overflow)
243 if (*in ==
'+') in++;
244 return parseUInt(in, out, Invalid_Value, check_overflow);
247 static inline uint04 _parse(
const char* in,
const char** out,
uint04 Invalid_Value,
bool check_overflow)
249 if (*in ==
'+') in++;
250 return parseUInt(in, out, Invalid_Value, check_overflow);
253 static inline uint08 _parse(
const char* in,
const char** out,
uint08 Invalid_Value,
bool check_overflow)
255 if (*in ==
'+') in++;
256 return parseUInt(in, out, Invalid_Value, check_overflow);
259 static inline sint01 _parse(
const char* in,
const char** out,
sint01 Invalid_Value,
bool check_overflow)
261 bool inv = (*in ==
'-');
262 if (inv || *in ==
'+')
266 return Invalid_Value;
267 return inv ? -value : value;
270 static inline sint02 _parse(
const char* in,
const char** out,
sint02 Invalid_Value,
bool check_overflow)
272 bool inv = (*in ==
'-');
273 if (inv || *in ==
'+')
277 return Invalid_Value;
278 return inv ? -value : value;
282 static inline sint04 _parse(
const char* in,
const char** out,
sint04 Invalid_Value,
bool check_overflow)
284 bool inv = (*in ==
'-');
285 if (inv || *in ==
'+')
289 return Invalid_Value;
290 return inv ? -value : value;
294 static inline sint08 _parse(
const char* in,
const char** out,
sint08 Invalid_Value,
bool check_overflow)
296 bool inv = (*in ==
'-');
297 if (inv || *in ==
'+')
301 return Invalid_Value;
310 static inline fltp04 _parse(
const char* in,
const char** out,
fltp04 Invalid_Value,
bool check_overflow)
316 static inline fltp08 _parse(
const char* in,
const char** out,
fltp08 Invalid_Value,
bool check_overflow)
323 static inline uint04 parseOctal(
const char* in,
const char** out =
nullptr)
328 if (*in <
'0' || *in >
'7')
330 value = (value << 3) + (*in -
'0');
345 template<
class t_
char_type>
346 static uint04 strtoul_cppstyle(
const t_char_type* in,
const t_char_type** out =
nullptr)
350 return 'x' == in[1] ? strtoul16(in + 2, out) : strtoul8(in + 1, out);
352 return strtoul10(in, out);
355 static inline Angle<sint04> _parse(
const char* in,
const char** out, Angle<sint04> Invalid_Value,
bool check_overflow)
357 return Angle<sint04>(NumberParser::_parse<sint04>(in, out, Invalid_Value.internal<
false>(), check_overflow));
360 static inline Angle<fltp08> _parse(
const char* in,
const char** out, Angle<fltp08> Invalid_Value,
bool check_overflow)
362 return Angle<fltp08>(NumberParser::_parse<fltp08>(in, out, Invalid_Value.internal<
false>(), check_overflow));
365 static inline Angle<fltp04> _parse(
const char* in,
const char** out, Angle<fltp04> Invalid_Value,
bool check_overflow)
367 return Angle<fltp04>(NumberParser::_parse<fltp04>(in, out, Invalid_Value.internal<
false>(), check_overflow));
Definition NumberParser.hpp:83
static t_type parse(const char *in, const char **out=nullptr, t_type Invalid_Value=Constant< t_type >::Invalid, bool check_overflow=true)
Definition NumberParser.hpp:86
static constexpr t_type parseUInt(const char *in, const char **out, t_type Invalid_Value, bool check_overflow)
Definition NumberParser.hpp:91
static uint01 HexOctetToDecimal(const t_char_type *in)
Definition NumberParser.hpp:224
static uint04 HexDigitToDecimal(t_char_type in)
Definition NumberParser.hpp:208
static uint04 parseHex(const char *in, const char **out=nullptr)
Definition NumberParser.hpp:184
static t_type parseFloat(const char *c, const char **out_s, t_type Invalid_Value, bool check_overflow)
Definition NumberParser.hpp:133
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
constexpr uint04 MaxDigits< uint02 >()
Definition NumberParser.hpp:73
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:71
constexpr uint04 MaxDigits< uint04 >()
Definition NumberParser.hpp:76
constexpr uint04 MaxDigits()
For a given number type, returns the maximum number of digits the number type can represent.
constexpr uint04 MaxDigits< sint08 >()
Definition NumberParser.hpp:79
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
constexpr const fltp08 fast_atof_table[20]
Data for quick text to number lookup.
Definition NumberParser.hpp:41
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
int8_t sint01
-Defines an alias representing a 1 byte, signed integer. -Can represent exact integer values -127 thr...
Definition BaseValues.hpp:50
constexpr uint04 MaxDigits< uint01 >()
Definition NumberParser.hpp:70
constexpr uint04 MaxDigits< sint04 >()
Definition NumberParser.hpp:77
constexpr uint04 MaxDigits< sint01 >()
Definition NumberParser.hpp:71
constexpr uint04 MaxDigits< uint08 >()
Definition NumberParser.hpp:80
int16_t sint02
-Defines an alias representing a 2 byte, signed integer. -Can represent exact integer values -32767 t...
Definition BaseValues.hpp:57
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
constexpr uint04 MaxDigits< sint02 >()
Definition NumberParser.hpp:74
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:88
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
static const t_type Invalid
Definition BaseValues.hpp:234