cutes/variant.h

37 lines
1.1 KiB
C
Raw Normal View History

2024-01-25 13:08:23 +00:00
#ifndef _fencer_variant_h
#define _fencer_variant_h
#include "vmath.h"
#include "mirror.h"
2024-01-25 13:08:23 +00:00
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;
2024-01-25 13:08:23 +00:00
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 // !_fencer_variant_h