168 lines
4.7 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 short us) {}
virtual void SetValue(short s) {}
virtual void SetValue(bool b) {}
virtual void SetValue(const string& str) {}
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, 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; }
virtual std::string GetValueStr() { return to_string(m_value); }
private:
float m_value;
};
class IntData : public BaseData {
public:
IntData(const std::string& code, const std::string& context, int val = 0)
: BaseData(code, context), m_value(val) {
//if (m_baseMp.find(code) != m_baseMp.end()) {
// printf("%s is repeated...", code.c_str());
//}
//else {
// m_baseMp.insert(make_pair(code, this));
//}
}
~IntData() {}
void SetValue(int i) { m_value = i; }
//void GetValue(DATATYPE& dataType,int& i) { dataType = iINT; i = m_value; }
DATATYPE GetDataTypeI() { return iINT; }
int GetValue() { return m_value; }
virtual std::string GetValueStr() { return to_string(m_value); }
private:
int m_value;
};
class ShortData : public BaseData {
public:
ShortData(const std::string& code, const std::string& context, short val = 0)
: BaseData(code, context), m_value(val) {
//if (m_baseMp.find(code) != m_baseMp.end()) {
// printf("%s is repeated...", code.c_str());
//}
//else {
// m_baseMp.insert(make_pair(code, this));
//}
}
~ShortData() {}
void SetValue(short s) { m_value = s; }
//void GetValue(DATATYPE& dataType, short& s) { dataType = iSHORT; s = m_value; }
DATATYPE GetDataType() { return iSHORT; }
short GetValue() { return m_value; }
virtual std::string GetValueStr() { return to_string(m_value); }
private:
short m_value;
};
class UShortData : public BaseData {
public:
UShortData(const std::string& code, const std::string& context, unsigned short val = 0)
: BaseData(code, context), m_value(val) {
//if (m_baseMp.find(code) != m_baseMp.end()) {
// printf("%s is repeated...", code.c_str());
//}
//else {
// m_baseMp.insert(make_pair(code, this));
//}
}
~UShortData() {}
void SetValue(unsigned short us) { m_value = us; }
//void GetValue(DATATYPE& dataType, unsigned short& us) { dataType = iUSHORT; us = m_value; }
DATATYPE GetDataType() { return iUSHORT; }
unsigned short GetValue() { return m_value; }
virtual std::string GetValueStr() { return to_string(m_value); }
private:
unsigned short m_value;
};
class BoolData : public BaseData {
public:
BoolData(const std::string& code, const std::string& context, bool val = false)
: BaseData(code, context), m_value(val) {
//if (m_baseMp.find(code) != m_baseMp.end()) {
// printf("%s is repeated...", code.c_str());
//}
//else {
// m_baseMp.insert(make_pair(code, this));
//}
}
~BoolData() {}
void SetValue(bool b) { m_value = b; }
//string GetValueStr() { return to_string(m_value); }
DATATYPE GetDataType() { return iBOOL; }
bool GetValue() { return m_value; }
virtual std::string GetValueStr() { return to_string(m_value); }
private:
bool m_value;
};
class UcharData : public BaseData {
public:
UcharData(const std::string& code, const std::string& context, UCHAR val = 0)
: BaseData(code, context), m_value(val) {
//if (m_baseMp.find(code) != m_baseMp.end()) {
// printf("%s is repeated...", code.c_str());
//}
//else {
// m_baseMp.insert(make_pair(code, this));
//}
}
~UcharData() {}
void SetValue(UCHAR uc) { m_value = uc; }
//void GetValue(DATATYPE& dataType, UCHAR& uc) { dataType = iUCHAR; uc = m_value; }
DATATYPE GetDataType() { return iUCHAR; }
UCHAR GetValue() { return m_value; }
virtual std::string GetValueStr() { return to_string(m_value); }
private:
UCHAR m_value;
};
class StrData : public BaseData {
public:
StrData(const std::string& code, const std::string& context,const string& val = "")
: BaseData(code, context), m_value(val) {
}
~StrData() {}
void SetValue(const std::string& str) { m_value = str; }
DATATYPE GetDataType() { return iSTRING; }
//std::string GetValue() { return m_value; }
virtual std::string GetValueStr() { return m_value; }
private:
string m_value;
};