Luna::Variant
Represents a dynamic typed object that stores data in a schema-less (self-described) manner.
class Luna::Variant
Member functions
-
Variant(VariantType type=VariantType::null)
Initializes one empty variant with the specified variant type.
-
Initializes one variant by coping data from another variant.
-
Initializes one variant by moving data from another variant.
-
Initializes one variant of VariantType::number and VariantNumberType::number_i64 and sets its data to the specified value.
-
Initializes one variant of VariantType::number and VariantNumberType::number_u64 and sets its data to the specified value.
-
Initializes one variant of VariantType::number and VariantNumberType::number_f64 and sets its data to the specified value.
-
Initializes one variant of VariantType::string and sets its data to the specified value.
-
Initializes one variant of VariantType::string and sets its data to the specified value.
-
Initializes one variant of VariantType::string and sets its data to the specified value.
-
Initializes one variant of VariantType::boolean and sets its data to the specified value.
-
Variant(const Blob &blob_data)
Initializes one variant of VariantType::blob and sets its data to the specified value.
-
Initializes one variant of VariantType::blob and sets its data to the specified value.
-
Variant & operator=(const Variant &rhs)
Assigns one variant by coping data from another variant.
-
Variant & operator=(Variant &&rhs)
Assigns one variant by moving data from another variant.
-
Assigns one variant with one number. The variant type will be VariantType::number and VariantNumberType::number_u64 after this assignment.
-
Assigns one variant with one number. The variant type will be VariantType::number and VariantNumberType::number_i64 after this assignment.
-
Assigns one variant with one number. The variant type will be VariantType::number and VariantNumberType::number_f64 after this assignment.
-
Variant & operator=(const Name &v)
Assigns one variant with one string. The variant type will be VariantType::string after this assignment.
-
Assigns one variant with one string. The variant type will be VariantType::string after this assignment.
-
Variant & operator=(const c8 *v)
Assigns one variant with one string. The variant type will be VariantType::string after this assignment.
-
Assigns one variant with one Boolean value. The variant type will be VariantType::boolean after this assignment.
-
Variant & operator=(const Blob &blob_data)
Assigns one variant with one blob. The variant type will be VariantType::blob after this assignment.
-
Variant & operator=(Blob &&blob_data)
Assigns one variant with one blob. The variant type will be VariantType::blob after this assignment.
-
bool operator==(const Variant &rhs) const
Compares two variant for equality.
-
bool operator!=(const Variant &rhs) const
Compares two variant for non-equality.
-
Gets the type of the variant.
-
VariantNumberType number_type() const
Gets the number type of the variant.
-
Checks whether the variant is valid.
-
Checks whether the variant contains no child variant.
-
const Variant & at(usize i) const
Gets the child variant when this is an array variant.
-
Gets the child variant when this is an array variant.
-
const Variant & find(const Name &k) const
Gets the child variant when this is an object variant.
-
Variant & find_or_insert(const Name &k)
Gets the child variant with the specified key, or inserts one new child variant with that key if not exists.
-
const Variant & operator[](usize i) const
Shortcut for at.
-
Shortcut for at.
-
const Variant & operator[](const Name &k) const
Shortcut for find.
-
Variant & operator[](const Name &k)
Shortcut for find_or_insert.
-
Gets the number of the child variants of this variant.
-
bool contains(const Name &k) const
Checks whether one child variant with the specified key exists.
-
Variant::value_enumerator values()
Gets one enumerator that can be used to enumerate all child variants of one array variant.
-
Variant::const_value_enumerator values() const
Gets one enumerator that can be used to enumerate all child variants of one array variant.
-
Variant::key_value_enumerator key_values()
Gets one enumerator to enumerate all child key-variant pairs of one object variant.
-
Variant::const_key_value_enumerator key_values() const
Gets one enumerator to enumerate all child key-variant pairs of one object variant.
-
void insert(usize i, const Variant &val)
Copy-inserts one variant to the specified index.
-
void insert(usize i, Variant &&val)
Move-inserts one variant to the specified index.
-
void push_back(const Variant &val)
Copy-inserts one variant to the end of the variant array.
-
Move-inserts one variant to the end of the variant array.
-
Removes one child variant from the current variant.
-
void erase(usize begin, usize end)
Erases one range [begin, end) of child variants from the current variant.
-
Erases the last child variant from the child variants array of the current variant.
-
bool insert(const Name &k, const Variant &val)
Copy-inserts the variant with the specified key as the child variant of the current variant.
-
bool insert(const Name &k, Variant &&val)
Move-inserts the variant with the specified key as the child variant of the current variant.
-
Removes the child variant with the specified key from the current variant.
-
Name str(const Name &default_value=Name()) const
Gets the string of one string variant.
-
const c8 * c_str(const c8 *default_value="") const
Gets the C string of one string variant.
-
i64 inum(i64 default_value=0) const
Gets the data of one number variant as one signed 64-bit integer.
-
u64 unum(u64 default_value=0) const
Gets the data of one number variant as one unsigned 64-bit integer.
-
f64 fnum(f64 default_value=0) const
Gets the data of one number variant as one 64-bit floating-point number.
-
bool boolean(bool default_value=false) const
Gets the data of one Boolean variant.
-
Gets the data pointer of one BLOB variant.
-
const void * blob_data() const
Gets the data pointer of one BLOB variant.
-
Gets the data size, in bytes, of one BLOB variant.
-
Gets the data alignment, in bytes, of one BLOB variant.
-
Detaches and gets the data of one BLOB variant as a Blob object.