cutes/variant.h

37 lines
1.1 KiB
C

#ifndef CUTES_VARIANT_H
#define CUTES_VARIANT_H
#include "vmath.h"
#include "mirror.h"
typedef enum VariantType {
Variant_Undefined = 0x0,
Variant_Number = 0x1,
Variant_Vector = 0x2,
Variant_Object = 0x3,
Variant_String = 0x4,
} VariantType;
typedef struct Variant {
VariantType type;
size_t string_size;
union {
double as_number;
Vector as_vector;
Mirror as_object;
char* as_string;
};
} Variant;
extern Variant variant_from_str(const char* str);
extern void destroy_variant(Variant* self);
extern void destroy_contained(Variant* self);
#define NumberVariant(Value_) (Variant){.type = Variant_Number, .as_number = Value_}
#define VectorVariant(Value_) (Variant){.type = Variant_Vector, .as_vector = Value_}
#define ObjectVariant(Value_) (Variant){.type = Variant_Object, .as_object = Value_}
#define StringVariant(Value_, BufSize_) (Variant){.type = Variant_String, .as_string = Value_, .string_size = BufSize_}
#define UndefinedVariant() (Variant){.type = Variant_Undefined }
#endif // !CUTES_VARIANT_H