为数据结构添加setProperty和getProperty(三)

2014-11-24 10:39:57 · 作者: · 浏览: 2
sert(pos != _ptysList.end());
return pos->second->getValueType(this);
}

myMain.cpp
[cpp]
// 王智泉
#include "myPropertySet.h"
#include "myProperty.h"
#include

class myTest : public myPropertySet
{
public:

myTest();
int _intVal;
float _floatVal;
std::string _strVal;
bool _boolVal;
};

// 定义属性
myDEF_PROPERTY(myTest, "IntValue", _intVal, "这是整型");
myDEF_PROPERTY(myTest, "FloatValue", _floatVal, "这是浮点型");
myDEF_PROPERTY(myTest, "StringValue", _strVal, "这是字符串");
myDEF_PROPERTY(myTest, "BOOLValue", _boolVal, "这是布尔型");

myTest::myTest()
{
// 注册属性,一定人先调用myDEF_PROPERTY定义对应的属性
myRegisterProperty(myTest, _intVal);
myRegisterProperty(myTest, _floatVal);
myRegisterProperty(myTest, _strVal);
myRegisterProperty(myTest, _boolVal);
}

int main()
{
myTest test;
test.setProperty("IntValue", "10");
test.setProperty("FloatValue", "10");
test.setProperty("StringValue", "我叫王智泉,哈哈....");
test.setProperty("BOOLValue", "TRUE");
std::cout << "IntValue:" << test._intVal << "\nFloatValue:" << test._floatVal << "\nStringValue:" << test._strVal << "\nBOOLValue:" << test._boolVal << std::endl;

test._intVal = 100;
test._floatVal = 100.0f;
test._strVal = "Are you a programming monkey ";
test._boolVal = false;
std::cout << "\nIntValue:" << test.getProperty("IntValue") << "\nFloatValue:" << test.getProperty("FloatValue") << "\nStringValue:" << test.getProperty("StringValue") << "\nBOOLValue:" << test.getProperty("BOOLValue") << std::endl;
return 0;
}

输出结果:

IntValue:10
FloatValue:10
StringValue:我叫王智泉,哈哈....
BOOLValue:1


IntValue:100
FloatValue:100.00
StringValue:Are you a programming monkey
BOOLValue:FALSE