From ab84dacf8f32cbf3edea0f2ace545d828d8768f3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 28 Jul 2013 00:26:24 +0800 Subject: [PATCH 1/2] issue #2430: CCBValue::Type is strong enum type now. --- extensions/CCBReader/CCBValue.cpp | 24 ++++++++++++------------ extensions/CCBReader/CCBValue.h | 14 +++++++------- extensions/CCDeprecated-ext.h | 12 ++++++------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/extensions/CCBReader/CCBValue.cpp b/extensions/CCBReader/CCBValue.cpp index 239dce8fc0..dac5004f3a 100644 --- a/extensions/CCBReader/CCBValue.cpp +++ b/extensions/CCBReader/CCBValue.cpp @@ -34,7 +34,7 @@ CCBValue* CCBValue::create(int nValue) if (ret) { ret->_value.intValue = nValue; - ret->_type = TYPE_INT; + ret->_type = Type::INT; ret->autorelease(); } @@ -47,7 +47,7 @@ CCBValue* CCBValue::create(float fValue) if (ret) { ret->_value.floatValue = fValue; - ret->_type = TYPE_FLOAT; + ret->_type = Type::FLOAT; ret->autorelease(); } @@ -60,7 +60,7 @@ CCBValue* CCBValue::create(bool vValue) if (ret) { ret->_value.intValue = vValue ? 1 : 0; - ret->_type = TYPE_BOOL; + ret->_type = Type::BOOL; ret->autorelease(); } @@ -73,7 +73,7 @@ CCBValue* CCBValue::create(unsigned char byte) if (ret) { ret->_value.intValue = byte; - ret->_type = TYPE_UNSIGNED_CHAR; + ret->_type = Type::UNSIGNED_CHAR; ret->autorelease(); } @@ -86,7 +86,7 @@ CCBValue* CCBValue::create(const char *pStringValue) if (ret) { ret->_strValue = pStringValue; - ret->_type = TYPE_STRING; + ret->_type = Type::STRING; ret->autorelease(); } @@ -100,7 +100,7 @@ CCBValue* CCBValue::create(Array *pArrValue) if (ret) { ret->_arrValue = pArrValue; - ret->_type = TYPE_ARRAY; + ret->_type = Type::ARRAY; ret->autorelease(); } @@ -110,35 +110,35 @@ CCBValue* CCBValue::create(Array *pArrValue) int CCBValue::getIntValue() { - CCASSERT(_type == TYPE_INT, "The type of CCBValue isn't integer."); + CCASSERT(_type == Type::INT, "The type of CCBValue isn't integer."); return _value.intValue; } float CCBValue::getFloatValue() { - CCASSERT(_type == TYPE_FLOAT, "The type of CCBValue isn't float."); + CCASSERT(_type == Type::FLOAT, "The type of CCBValue isn't float."); return _value.floatValue; } bool CCBValue::getBoolValue() { - CCASSERT(_type == TYPE_BOOL, "The type of CCBValue isn't boolean."); + CCASSERT(_type == Type::BOOL, "The type of CCBValue isn't boolean."); return _value.intValue == 1 ? true : false; } unsigned char CCBValue::getByteValue() { - CCASSERT(_type == TYPE_UNSIGNED_CHAR, "The type of CCBValue isn't unsigned char."); + CCASSERT(_type == Type::UNSIGNED_CHAR, "The type of CCBValue isn't unsigned char."); return (unsigned char)(_value.intValue); } Array* CCBValue::getArrayValue() { - CCASSERT(_type == TYPE_ARRAY, "The type of CCBValue isn't array."); + CCASSERT(_type == Type::ARRAY, "The type of CCBValue isn't array."); return _arrValue; } @@ -146,7 +146,7 @@ Array* CCBValue::getArrayValue() const char* CCBValue::getStringValue() { - CCASSERT(_type == TYPE_STRING, "The type of CCBValue isn't string."); + CCASSERT(_type == Type::STRING, "The type of CCBValue isn't string."); return _strValue.c_str(); } diff --git a/extensions/CCBReader/CCBValue.h b/extensions/CCBReader/CCBValue.h index 1af9278a4a..267ed5809a 100644 --- a/extensions/CCBReader/CCBValue.h +++ b/extensions/CCBReader/CCBValue.h @@ -27,14 +27,14 @@ class CCBValue : public Object { public: - enum Type + enum class Type { - TYPE_INT, - TYPE_FLOAT, - TYPE_BOOL, - TYPE_UNSIGNED_CHAR, - TYPE_STRING, - TYPE_ARRAY + INT, + FLOAT, + BOOL, + UNSIGNED_CHAR, + STRING, + ARRAY }; static CCBValue* create(int nValue); diff --git a/extensions/CCDeprecated-ext.h b/extensions/CCDeprecated-ext.h index 30334a0916..311ae4cbb9 100644 --- a/extensions/CCDeprecated-ext.h +++ b/extensions/CCDeprecated-ext.h @@ -185,12 +185,12 @@ CC_DEPRECATED_ATTRIBUTE typedef Control::Handler SEL_CCControlHandler; // For CCBReader -CC_DEPRECATED_ATTRIBUTE const int kIntValue = CCBValue::TYPE_INT; -CC_DEPRECATED_ATTRIBUTE const int kFloatValue = CCBValue::TYPE_FLOAT; -CC_DEPRECATED_ATTRIBUTE const int kBoolValue = CCBValue::TYPE_BOOL; -CC_DEPRECATED_ATTRIBUTE const int kUnsignedCharValue = CCBValue::TYPE_UNSIGNED_CHAR; -CC_DEPRECATED_ATTRIBUTE const int kStringValue = CCBValue::TYPE_STRING; -CC_DEPRECATED_ATTRIBUTE const int kArrayValue = CCBValue::TYPE_ARRAY; +CC_DEPRECATED_ATTRIBUTE const CCBValue::Type kIntValue = CCBValue::Type::INT; +CC_DEPRECATED_ATTRIBUTE const CCBValue::Type kFloatValue = CCBValue::Type::FLOAT; +CC_DEPRECATED_ATTRIBUTE const CCBValue::Type kBoolValue = CCBValue::Type::BOOL; +CC_DEPRECATED_ATTRIBUTE const CCBValue::Type kUnsignedCharValue = CCBValue::Type::UNSIGNED_CHAR; +CC_DEPRECATED_ATTRIBUTE const CCBValue::Type kStringValue = CCBValue::Type::STRING; +CC_DEPRECATED_ATTRIBUTE const CCBValue::Type kArrayValue = CCBValue::Type::ARRAY; CC_DEPRECATED_ATTRIBUTE const CCBReader::PropertyType kCCBPropTypePosition = CCBReader::PropertyType::POSITION; From d67ab3e4cc34e9920384881dc734d8c9f31a048a Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 28 Jul 2013 00:31:09 +0800 Subject: [PATCH 2/2] Untabify for CCBValue.cpp. --- extensions/CCBReader/CCBValue.cpp | 52 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/extensions/CCBReader/CCBValue.cpp b/extensions/CCBReader/CCBValue.cpp index dac5004f3a..051100383d 100644 --- a/extensions/CCBReader/CCBValue.cpp +++ b/extensions/CCBReader/CCBValue.cpp @@ -1,7 +1,5 @@ #include "CCBValue.h" -using namespace cocos2d; - NS_CC_EXT_BEGIN // Implementation of Color3BWapper @@ -14,10 +12,10 @@ Color3BWapper* Color3BWapper::create(const Color3B& color) ret->color.r = color.r; ret->color.g = color.g; ret->color.b = color.b; - + ret->autorelease(); } - + return ret; } @@ -34,10 +32,10 @@ CCBValue* CCBValue::create(int nValue) if (ret) { ret->_value.intValue = nValue; - ret->_type = Type::INT; + ret->_type = Type::INT; ret->autorelease(); } - + return ret; } @@ -47,10 +45,10 @@ CCBValue* CCBValue::create(float fValue) if (ret) { ret->_value.floatValue = fValue; - ret->_type = Type::FLOAT; + ret->_type = Type::FLOAT; ret->autorelease(); } - + return ret; } @@ -60,10 +58,10 @@ CCBValue* CCBValue::create(bool vValue) if (ret) { ret->_value.intValue = vValue ? 1 : 0; - ret->_type = Type::BOOL; + ret->_type = Type::BOOL; ret->autorelease(); } - + return ret; } @@ -73,10 +71,10 @@ CCBValue* CCBValue::create(unsigned char byte) if (ret) { ret->_value.intValue = byte; - ret->_type = Type::UNSIGNED_CHAR; + ret->_type = Type::UNSIGNED_CHAR; ret->autorelease(); } - + return ret; } @@ -86,10 +84,10 @@ CCBValue* CCBValue::create(const char *pStringValue) if (ret) { ret->_strValue = pStringValue; - ret->_type = Type::STRING; + ret->_type = Type::STRING; ret->autorelease(); } - + return ret; } @@ -103,51 +101,51 @@ CCBValue* CCBValue::create(Array *pArrValue) ret->_type = Type::ARRAY; ret->autorelease(); } - + return ret; } int CCBValue::getIntValue() { - CCASSERT(_type == Type::INT, "The type of CCBValue isn't integer."); - + CCASSERT(_type == Type::INT, "The type of CCBValue isn't integer."); + return _value.intValue; } float CCBValue::getFloatValue() { - CCASSERT(_type == Type::FLOAT, "The type of CCBValue isn't float."); - + CCASSERT(_type == Type::FLOAT, "The type of CCBValue isn't float."); + return _value.floatValue; } bool CCBValue::getBoolValue() { - CCASSERT(_type == Type::BOOL, "The type of CCBValue isn't boolean."); - + CCASSERT(_type == Type::BOOL, "The type of CCBValue isn't boolean."); + return _value.intValue == 1 ? true : false; } unsigned char CCBValue::getByteValue() { - CCASSERT(_type == Type::UNSIGNED_CHAR, "The type of CCBValue isn't unsigned char."); - + CCASSERT(_type == Type::UNSIGNED_CHAR, "The type of CCBValue isn't unsigned char."); + return (unsigned char)(_value.intValue); } Array* CCBValue::getArrayValue() { - CCASSERT(_type == Type::ARRAY, "The type of CCBValue isn't array."); - + CCASSERT(_type == Type::ARRAY, "The type of CCBValue isn't array."); + return _arrValue; } const char* CCBValue::getStringValue() { - CCASSERT(_type == Type::STRING, "The type of CCBValue isn't string."); - + CCASSERT(_type == Type::STRING, "The type of CCBValue isn't string."); + return _strValue.c_str(); }