181 lines
5.0 KiB
C
Raw Normal View History

2024-04-12 15:51:41 +08:00
#pragma once
#include <string>
#include "../DataManage/RWData.h"
class BaseData {
public:
2024-05-06 10:49:15 +08:00
BaseData(const std::string& code, const std::string& context) :m_code(code), m_context(context) {}
2024-04-12 15:51:41 +08:00
virtual ~BaseData() {}
virtual void SetValue(float f) {}
virtual void SetValue(int i) {}
2024-05-06 10:49:15 +08:00
virtual void SetValue(unsigned int i) {}
2024-04-12 15:51:41 +08:00
virtual void SetValue(unsigned short us) {}
virtual void SetValue(short s) {}
virtual void SetValue(bool b) {}
2024-05-06 10:49:15 +08:00
virtual void SetValue(const std::string& str) {}
virtual void SetValue(unsigned char uc) {}
2024-05-28 13:28:07 +08:00
virtual void SetValue(double uc) {}
2024-05-30 11:18:10 +08:00
virtual void SetValue(const time_t value) {}
2024-04-12 15:51:41 +08:00
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:
2024-05-06 10:49:15 +08:00
FloatData(const std::string& code, const std::string& context = u8"", float val = 0.0f)
2024-04-16 17:36:27 +08:00
: BaseData(code, context), m_value(val) {
2024-04-12 15:51:41 +08:00
}
~FloatData() {}
void SetValue(float f) { m_value = f; }
DATATYPE GetDataType() { return iFLOAT; }
float GetValue() { return m_value; }
2024-05-06 10:49:15 +08:00
std::string GetValueStr() { return std::to_string(m_value); }
2024-04-12 15:51:41 +08:00
private:
float m_value;
};
class IntData : public BaseData {
public:
2024-05-06 10:49:15 +08:00
IntData(const std::string& code, const std::string& context = u8"", int val = 0)
2024-04-16 17:36:27 +08:00
: BaseData(code, context), m_value(val) {
2024-04-12 15:51:41 +08:00
}
~IntData() {}
void SetValue(int i) { m_value = i; }
2024-05-11 17:43:38 +08:00
DATATYPE GetDataType() { return iINT; }
2024-04-12 15:51:41 +08:00
int GetValue() { return m_value; }
2024-05-06 10:49:15 +08:00
std::string GetValueStr() { return std::to_string(m_value); }
2024-04-12 15:51:41 +08:00
private:
int m_value;
};
2024-05-06 10:49:15 +08:00
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; }
2024-05-11 17:43:38 +08:00
DATATYPE GetDataType() { return iUINT; }
2024-05-06 10:49:15 +08:00
unsigned int GetValue() { return m_value; }
std::string GetValueStr() { return std::to_string(m_value); }
private:
unsigned int m_value;
};
2024-04-12 15:51:41 +08:00
class ShortData : public BaseData {
public:
2024-05-06 10:49:15 +08:00
ShortData(const std::string& code, const std::string& context = u8"", short val = 0)
2024-04-16 17:36:27 +08:00
: BaseData(code, context), m_value(val) {
2024-04-12 15:51:41 +08:00
}
~ShortData() {}
void SetValue(short s) { m_value = s; }
DATATYPE GetDataType() { return iSHORT; }
short GetValue() { return m_value; }
2024-05-06 10:49:15 +08:00
std::string GetValueStr() { return std::to_string(m_value); }
2024-04-12 15:51:41 +08:00
private:
short m_value;
};
class UShortData : public BaseData {
public:
2024-05-06 10:49:15 +08:00
UShortData(const std::string& code, const std::string& context = u8"", unsigned short val = 0)
2024-04-16 17:36:27 +08:00
: BaseData(code, context), m_value(val) {
2024-04-12 15:51:41 +08:00
}
~UShortData() {}
void SetValue(unsigned short us) { m_value = us; }
DATATYPE GetDataType() { return iUSHORT; }
unsigned short GetValue() { return m_value; }
2024-05-06 10:49:15 +08:00
std::string GetValueStr() { return std::to_string(m_value); }
2024-04-12 15:51:41 +08:00
private:
unsigned short m_value;
};
class BoolData : public BaseData {
public:
2024-05-06 10:49:15 +08:00
BoolData(const std::string& code, const std::string& context = u8"", bool val = false)
2024-04-16 17:36:27 +08:00
: BaseData(code, context), m_value(val) {
2024-04-12 15:51:41 +08:00
}
~BoolData() {}
void SetValue(bool b) { m_value = b; }
DATATYPE GetDataType() { return iBOOL; }
bool GetValue() { return m_value; }
2024-05-06 10:49:15 +08:00
std::string GetValueStr() { return std::to_string(m_value); }
2024-04-12 15:51:41 +08:00
private:
bool m_value;
};
class UcharData : public BaseData {
public:
2024-05-06 10:49:15 +08:00
UcharData(const std::string& code, const std::string& context = u8"", unsigned char val = 0)
2024-04-16 17:36:27 +08:00
: BaseData(code, context), m_value(val) {
2024-04-12 15:51:41 +08:00
}
~UcharData() {}
2024-05-06 10:49:15 +08:00
void SetValue(unsigned char uc) { m_value = uc; }
2024-04-12 15:51:41 +08:00
DATATYPE GetDataType() { return iUCHAR; }
2024-05-06 10:49:15 +08:00
unsigned char GetValue() { return m_value; }
std::string GetValueStr() { return std::to_string(m_value); }
2024-04-12 15:51:41 +08:00
private:
2024-05-06 10:49:15 +08:00
unsigned char m_value;
2024-04-15 10:08:28 +08:00
};
class StrData : public BaseData {
public:
2024-05-06 10:49:15 +08:00
StrData(const std::string& code, const std::string& context = u8"", const std::string& val = "")
2024-04-16 17:36:27 +08:00
: BaseData(code, context), m_value(val) {
2024-04-15 10:08:28 +08:00
}
~StrData() {}
void SetValue(const std::string& str) { m_value = str; }
DATATYPE GetDataType() { return iSTRING; }
2024-05-06 10:49:15 +08:00
std::string GetValueStr() { return m_value; }
2024-04-15 10:08:28 +08:00
private:
2024-05-06 10:49:15 +08:00
std::string m_value;
2024-05-28 13:28:07 +08:00
};
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;
2024-05-30 11:18:10 +08:00
};
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;
2024-04-12 15:51:41 +08:00
};