181 lines
5.0 KiB
C++
181 lines
5.0 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include "../DataManage/RWData.h"
|
|
|
|
class BaseData {
|
|
public:
|
|
BaseData(const std::string& code, const std::string& context) :m_code(code), m_context(context) {}
|
|
virtual ~BaseData() {}
|
|
|
|
virtual void SetValue(float f) {}
|
|
virtual void SetValue(int i) {}
|
|
virtual void SetValue(unsigned int i) {}
|
|
virtual void SetValue(unsigned short us) {}
|
|
virtual void SetValue(short s) {}
|
|
virtual void SetValue(bool b) {}
|
|
virtual void SetValue(const std::string& str) {}
|
|
virtual void SetValue(unsigned char uc) {}
|
|
virtual void SetValue(double uc) {}
|
|
virtual void SetValue(const time_t value) {}
|
|
|
|
std::string GetCode() { return m_code; }
|
|
virtual std::string GetValueStr() { return ""; }
|
|
virtual DATATYPE GetDataType() { return UNKNOW; }
|
|
private:
|
|
std::string m_code; //key编码
|
|
std::string m_context; //中文内容
|
|
|
|
};
|
|
|
|
class FloatData : public BaseData {
|
|
public:
|
|
FloatData(const std::string& code, const std::string& context = u8"", float val = 0.0f)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~FloatData() {}
|
|
|
|
void SetValue(float f) { m_value = f; }
|
|
DATATYPE GetDataType() { return iFLOAT; }
|
|
float GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
float m_value;
|
|
};
|
|
|
|
|
|
class IntData : public BaseData {
|
|
public:
|
|
IntData(const std::string& code, const std::string& context = u8"", int val = 0)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~IntData() {}
|
|
|
|
void SetValue(int i) { m_value = i; }
|
|
DATATYPE GetDataType() { return iINT; }
|
|
int GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
int m_value;
|
|
};
|
|
|
|
class UIntData : public BaseData {
|
|
public:
|
|
UIntData(const std::string& code, const std::string& context = u8"", unsigned int val = 0)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~UIntData() {}
|
|
|
|
void SetValue(unsigned int i) { m_value = i; }
|
|
DATATYPE GetDataType() { return iUINT; }
|
|
unsigned int GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
unsigned int m_value;
|
|
};
|
|
|
|
|
|
class ShortData : public BaseData {
|
|
public:
|
|
ShortData(const std::string& code, const std::string& context = u8"", short val = 0)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~ShortData() {}
|
|
|
|
void SetValue(short s) { m_value = s; }
|
|
DATATYPE GetDataType() { return iSHORT; }
|
|
short GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
short m_value;
|
|
};
|
|
|
|
class UShortData : public BaseData {
|
|
public:
|
|
UShortData(const std::string& code, const std::string& context = u8"", unsigned short val = 0)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~UShortData() {}
|
|
|
|
void SetValue(unsigned short us) { m_value = us; }
|
|
DATATYPE GetDataType() { return iUSHORT; }
|
|
unsigned short GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
unsigned short m_value;
|
|
};
|
|
|
|
|
|
class BoolData : public BaseData {
|
|
public:
|
|
BoolData(const std::string& code, const std::string& context = u8"", bool val = false)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~BoolData() {}
|
|
|
|
void SetValue(bool b) { m_value = b; }
|
|
DATATYPE GetDataType() { return iBOOL; }
|
|
bool GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
bool m_value;
|
|
};
|
|
|
|
|
|
class UcharData : public BaseData {
|
|
public:
|
|
UcharData(const std::string& code, const std::string& context = u8"", unsigned char val = 0)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~UcharData() {}
|
|
|
|
void SetValue(unsigned char uc) { m_value = uc; }
|
|
DATATYPE GetDataType() { return iUCHAR; }
|
|
unsigned char GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
unsigned char m_value;
|
|
};
|
|
|
|
class StrData : public BaseData {
|
|
public:
|
|
StrData(const std::string& code, const std::string& context = u8"", const std::string& val = "")
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~StrData() {}
|
|
|
|
void SetValue(const std::string& str) { m_value = str; }
|
|
DATATYPE GetDataType() { return iSTRING; }
|
|
std::string GetValueStr() { return m_value; }
|
|
private:
|
|
std::string m_value;
|
|
};
|
|
|
|
class DoubleData : public BaseData {
|
|
public:
|
|
DoubleData(const std::string& code, const std::string& context = u8"", const double val = 0.0)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~DoubleData() {}
|
|
|
|
void SetValue(const double value) { m_value = value; }
|
|
DATATYPE GetDataType() { return iDOUBLE; }
|
|
double GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
double m_value;
|
|
};
|
|
|
|
class TimetData : public BaseData {
|
|
public:
|
|
TimetData(const std::string& code, const std::string& context = u8"", const time_t val = 0.0)
|
|
: BaseData(code, context), m_value(val) {
|
|
}
|
|
~TimetData() {}
|
|
|
|
void SetValue(const time_t value) { m_value = value; }
|
|
DATATYPE GetDataType() { return iTIMET; }
|
|
time_t GetValue() { return m_value; }
|
|
std::string GetValueStr() { return std::to_string(m_value); }
|
|
private:
|
|
time_t m_value;
|
|
}; |