#pragma once
#include <whiteout/common_types.h>
#include <whiteout/database/types.h>
#include <string_view>
namespace whiteout::database {
enum class ColumnType {
Int8,
UInt8,
Int16,
UInt16,
Int32,
UInt32,
Int64,
UInt64,
Float,
String,
LocString,
};
u32 columnTypeSize(ColumnType type);
bool columnTypeIsString(ColumnType type);
class Value {
public:
enum class Kind { Null, Int, UInt, Float, String };
Value() = default;
static Value makeInt(i64 v);
static Value makeUInt(u64 v);
static Value makeFloat(f32 v);
static Value makeString(std::string_view v);
Kind kind() const noexcept {
return kind_;
}
bool isNull() const noexcept {
return kind_ == Kind::Null;
}
bool isInt() const noexcept {
return kind_ == Kind::Int;
}
bool isUInt() const noexcept {
return kind_ == Kind::UInt;
}
bool isFloat() const noexcept {
return kind_ == Kind::Float;
}
bool isString() const noexcept {
return kind_ == Kind::String;
}
i64 asInt() const;
u64 asUInt() const;
f32 asFloat() const;
std::string_view asString() const;
private:
Kind kind_ = Kind::Null;
union {
i64 i;
u64 u;
f32 f;
} num_ = {0};
std::string_view str_;
};
}