27 #ifndef IDLFE_AST_VARIANT_H_
28 #define IDLFE_AST_VARIANT_H_
33 #include <forward_list>
92 return (uint8_t)val_.u.ui;
100 return (
char)val_.u.ui;
108 return (
wchar_t)val_.u.ui;
116 return (uint16_t)val_.u.ui;
124 return (int16_t)val_.u.i;
132 return (uint32_t)val_.u.ui;
140 return (int32_t)val_.u.i;
166 return (
float)val_.u.d;
174 return (
double)val_.u.d;
208 return *val_.u.enum_item;
216 return *val_.u.constant;
265 move (std::move (src));
331 val_ ((
long double)v)
337 val_ ((
long double)v)
392 bool to_boolean ()
const
394 assert (is_integral ());
395 return val_.u.i != 0;
398 uint8_t to_octet ()
const;
400 char to_char ()
const
402 return (
char)to_octet ();
405 wchar_t to_wchar ()
const
407 return (
wchar_t)to_unsigned_short ();
410 uint16_t to_unsigned_short ()
const;
411 int16_t to_short ()
const;
412 uint32_t to_unsigned_long ()
const;
413 int32_t to_long ()
const;
414 uint64_t to_unsigned_long_long ()
const;
415 int64_t to_long_long ()
const;
416 float to_float ()
const;
417 double to_double ()
const;
418 long double to_long_double ()
const;
420 typedef uint64_t Key;
422 Key to_key () const noexcept
428 return (Key)val_.u.enum_item;
432 bool is_integral () const noexcept
437 bool is_signed () const noexcept
442 bool is_floating_point () const noexcept
448 friend class Builder;
450 void clear () noexcept;
451 void copy (const
Variant& src);
454 static
void check_fp ();
456 static
void append (std::
string& s,
unsigned c);
458 [[noreturn]] static
void throw_out_of_range ();
471 const EnumItem* enum_item;
472 const Constant* constant;
480 U (
const int64_t& src) :
484 U (
const uint64_t& src) :
488 U (
const long double& src) :
492 U (std::string&& src) :
496 U (std::wstring&& src) :
500 U (
const Fixed& src) :
504 U (
const EnumItem& src) :
508 U (
const Constant& src) :
515 int data [
sizeof (U) /
sizeof (
int)];
529 template <
typename T>
534 template <
typename T>
542 typedef std::forward_list <Variant> Variants;
Stores the constant value.
const std::string & as_string() const noexcept
Variant(const EnumItem &item) noexcept
VT::ENUM_ITEM.
Variant(char v) noexcept
VT::CHAR.
Variant(std::wstring &&v) noexcept
VT::WSTRING.
Variant(uint8_t v) noexcept
VT::OCTET.
Variant(wchar_t v) noexcept
VT::WCHAR.
wchar_t as_wchar() const noexcept
Variant(const Constant &constant) noexcept
VT::CONSTANT.
Variant(uint16_t v) noexcept
VT::USHORT.
Variant(int32_t v) noexcept
VT::LONG.
const std::wstring & as_wstring() const noexcept
const Variant & dereference_const() const noexcept
Variant(double v) noexcept
VT::DOUBLE.
Variant & operator=(const Variant &src)
Copy assignment.
Variant(long double v) noexcept
VT::LONGDOUBLE.
Variant(uint64_t v) noexcept
VT::ULONGLONG.
bool as_bool() const noexcept
const Fixed & as_Fixed() const noexcept
Variant(Variant &&src) noexcept
Move constructor.
VT vtype() const noexcept
Variant(std::string &&v) noexcept
VT::STRING.
long double as_long_double() const noexcept
float as_float() const noexcept
uint32_t as_unsigned_long() const noexcept
Variant(bool v) noexcept
VT::BOOLEAN.
Variant(float v) noexcept
VT::FLOAT.
int16_t as_short() const noexcept
Variant(const wchar_t *s)
VT::WSTRING.
Variant(int64_t v) noexcept
VT::LONGLONG.
Variant(const Variant &src)
Copy constructor.
const Constant & as_constant() const noexcept
int32_t as_long() const noexcept
std::string to_string() const
double as_double() const noexcept
Variant(uint32_t v) noexcept
VT::ULONG.
uint16_t as_unsigned_short() const noexcept
@ CHAR
Variant::as_char ()
@ OCTET
Variant::as_octet ()
@ ULONG
Variant::as_unsigned_long ()
@ STRING
Variant::as_string ()
@ ENUM_ITEM
Variant::as_enum_item ()
@ CONSTANT
Variant::as_constant ()
@ ULONGLONG
Variant::as_unsigned_long_long ()
@ SHORT
Variant::as_short ()
@ LONGDOUBLE
Variant::as_long_double ()
@ USHORT
Variant::as_unsigned_short ()
@ LONG
Variant::as_long ()
@ BOOLEAN
Variant::as_bool ()
@ FIXED
Variant::as_Fixed ();.
@ WSTRING
Variant::as_wstring ()
@ WCHAR
Variant::as_wchar ()
@ LONGLONG
Variant::as_long_long ()
@ FLOAT
Variant::as_float ()
@ DOUBLE
Variant::as_double ()
Variant(const Fixed &v) noexcept
VT::FIXED.
Variant(const char *s)
VT::STRING.
Variant(int16_t v) noexcept
VT::SHORT.
int64_t as_long_long() const noexcept
bool empty() const noexcept
uint64_t as_unsigned_long_long() const noexcept
char as_char() const noexcept
uint8_t as_octet() const noexcept
const EnumItem & as_enum_item() const noexcept
Abstract Syntax Tree namespace.