axmol/cocos/editor-support/cocosbuilder/CCBValue.cpp

160 lines
2.8 KiB
C++
Raw Normal View History

#include "CCBValue.h"
using namespace cocos2d;
namespace cocosbuilder {
// Implementation of Color3BWapper
Color3BWapper* Color3BWapper::create(const Color3B& color)
{
Color3BWapper *ret = new Color3BWapper();
if (ret)
{
ret->color.r = color.r;
ret->color.g = color.g;
ret->color.b = color.b;
2013-07-28 00:31:09 +08:00
ret->autorelease();
}
2013-07-28 00:31:09 +08:00
return ret;
}
const Color3B& Color3BWapper::getColor() const
{
return color;
}
// Implementation of CCBValue
CCBValue* CCBValue::create(int nValue)
{
CCBValue *ret = new CCBValue();
if (ret)
{
ret->_value.intValue = nValue;
2013-07-28 00:31:09 +08:00
ret->_type = Type::INT;
ret->autorelease();
}
2013-07-28 00:31:09 +08:00
return ret;
}
CCBValue* CCBValue::create(float fValue)
{
CCBValue *ret = new CCBValue();
if (ret)
{
ret->_value.floatValue = fValue;
2013-07-28 00:31:09 +08:00
ret->_type = Type::FLOAT;
ret->autorelease();
}
2013-07-28 00:31:09 +08:00
return ret;
}
CCBValue* CCBValue::create(bool vValue)
{
CCBValue *ret = new CCBValue();
if (ret)
{
ret->_value.intValue = vValue ? 1 : 0;
2013-07-28 00:31:09 +08:00
ret->_type = Type::BOOL;
ret->autorelease();
}
2013-07-28 00:31:09 +08:00
return ret;
}
CCBValue* CCBValue::create(unsigned char byte)
{
CCBValue *ret = new CCBValue();
if (ret)
{
ret->_value.intValue = byte;
2013-07-28 00:31:09 +08:00
ret->_type = Type::UNSIGNED_CHAR;
ret->autorelease();
}
2013-07-28 00:31:09 +08:00
return ret;
}
CCBValue* CCBValue::create(const char *pStringValue)
{
CCBValue *ret = new CCBValue();
if (ret)
{
ret->_strValue = pStringValue;
2013-07-28 00:31:09 +08:00
ret->_type = Type::STRING;
ret->autorelease();
}
2013-07-28 00:31:09 +08:00
return ret;
}
CCBValue* CCBValue::create(Array *pArrValue)
{
CCBValue *ret = new CCBValue();
if (ret)
{
ret->_arrValue = pArrValue;
ret->_type = Type::ARRAY;
ret->autorelease();
}
2013-07-28 00:31:09 +08:00
return ret;
}
int CCBValue::getIntValue()
{
2013-07-28 00:31:09 +08:00
CCASSERT(_type == Type::INT, "The type of CCBValue isn't integer.");
return _value.intValue;
}
float CCBValue::getFloatValue()
{
2013-07-28 00:31:09 +08:00
CCASSERT(_type == Type::FLOAT, "The type of CCBValue isn't float.");
return _value.floatValue;
}
bool CCBValue::getBoolValue()
{
2013-07-28 00:31:09 +08:00
CCASSERT(_type == Type::BOOL, "The type of CCBValue isn't boolean.");
return _value.intValue == 1 ? true : false;
}
unsigned char CCBValue::getByteValue()
{
2013-07-28 00:31:09 +08:00
CCASSERT(_type == Type::UNSIGNED_CHAR, "The type of CCBValue isn't unsigned char.");
return (unsigned char)(_value.intValue);
}
Array* CCBValue::getArrayValue()
{
2013-07-28 00:31:09 +08:00
CCASSERT(_type == Type::ARRAY, "The type of CCBValue isn't array.");
return _arrValue;
}
const char* CCBValue::getStringValue()
{
2013-07-28 00:31:09 +08:00
CCASSERT(_type == Type::STRING, "The type of CCBValue isn't string.");
return _strValue.c_str();
}
CCBValue::Type CCBValue::getType()
{
return _type;
}
}