a8/a8/xvalue.h
aozhiwei c1f8ea93f7 1
2022-12-13 18:25:13 +08:00

96 lines
2.5 KiB
C++

#pragma once
namespace a8
{
const int XVT_NULL = 0;
const int XVT_INT = 1;
const int XVT_UINT = 2;
const int XVT_INT64 = 3;
const int XVT_UINT64 = 4;
const int XVT_STRING = 5;
const int XVT_FLOAT = 6;
const int XVT_WSTRING = 7;
const int XVT_USERDATA = 8;
class XValue
{
public:
XValue();
~XValue();
XValue(const XValue& xv);
XValue(int v);
XValue(unsigned int v);
XValue(long v);
XValue(unsigned long v);
XValue(double v);
XValue(void* userdata);
XValue(const char* v);
XValue(const std::string& v);
XValue(std::string& v);
XValue(long long v);
XValue(unsigned long long v);
void Set(void* user_data);
void Set(a8::XValue v);
void Set(int v);
void Set(long v);
void Set(unsigned int v);
void Set(unsigned long v);
void Set(long long v);
void Set(unsigned long long v);
void Set(const char* v);
void Set(const std::string& v);
void Set(const wchar_t* v);
void SetDynData(const char* v, unsigned int len);
void SetUserData(void *userdata, int datasize);
void Set(double v);
void SetNull();
void DeepCopy(a8::XValue& to);
int Type() const;
bool IsNull();
bool IsNumber();
bool IsString();
int GetInt() const;
unsigned int GetUInt() const;
long long GetInt64() const;
unsigned long long GetUInt64() const;
double GetDouble() const;
std::string GetString() const;
std::wstring GetWString() const;
void* GetUserData() const;
operator bool() const;
operator unsigned char() const;
operator short() const;
operator unsigned short() const;
operator int() const;
operator unsigned int() const;
operator long() const;
operator unsigned long() const;
operator double() const;
operator long long() const;
operator unsigned long long() const;
operator std::string () const;
const a8::XValue& operator=(const a8::XValue& xv);
bool IsUserData();
private:
unsigned char type_ = XVT_NULL;
union {
long long int_value;
double float_value;
char* str_value;
wchar_t* wstr_value;
void* user_data;
} value_ = {0};
unsigned int data_size_ = 0;
void OnReset();
};
}