From 19d75cee011ad96a7042aeeb19d88fa449d50693 Mon Sep 17 00:00:00 2001 From: chengstory Date: Thu, 26 Dec 2013 02:18:28 +0800 Subject: [PATCH] fixed #3647 fixes ComAttribute warning. --- .../cocostudio/CCComAttribute.cpp | 47 +++++++++---------- .../cocostudio/CCComAttribute.h | 18 +++---- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCComAttribute.cpp b/cocos/editor-support/cocostudio/CCComAttribute.cpp index c3f4aa6c10..2187ebd290 100644 --- a/cocos/editor-support/cocostudio/CCComAttribute.cpp +++ b/cocos/editor-support/cocostudio/CCComAttribute.cpp @@ -35,78 +35,75 @@ ComAttribute::ComAttribute(void) ComAttribute::~ComAttribute(void) { - CC_SAFE_RELEASE(_dict); + _dict.clear(); } bool ComAttribute::init() { - _dict = CCDictionary::create(); - _dict->retain(); return true; } -void ComAttribute::setInt(const char *key, int value) +void ComAttribute::setInt(const std::string& key, int value) { - _dict->setObject(CCInteger::create(value), key); + _dict.insert(key, __Integer::create(value)); } -void ComAttribute::setFloat(const char *key, float value) +void ComAttribute::setFloat(const std::string& key, float value) { - _dict->setObject(CCFloat::create(value), key); + _dict.insert(key, __Float::create(value)); } -void ComAttribute::setBool(const char *key, bool value) +void ComAttribute::setBool(const std::string& key, bool value) { - _dict->setObject(CCBool::create(value), key); + _dict.insert(key, __Bool::create(value)); } -void ComAttribute::setCString(const char *key, const char *value) +void ComAttribute::setCString(const std::string& key, const std::string& value) { - _dict->setObject(CCString::create(value), key); + _dict.insert(key, __String::create(value)); } - -int ComAttribute::getInt(const char *key, int def) const +int ComAttribute::getInt(const std::string& key, int def) const { - CCObject *ret = _dict->objectForKey(key); + Object *ret = _dict.at(key); if(ret) { - if( CCInteger *obj=dynamic_cast(ret) ) + if(__Integer *obj=dynamic_cast<__Integer*>(ret) ) return obj->getValue(); } return def; } -float ComAttribute::getFloat(const char *key, float def) const +float ComAttribute::getFloat(const std::string& key, float def) const { - CCObject *ret = _dict->objectForKey(key); - if(ret) + Object *ret = _dict.at(key); + if(ret) { - if( CCFloat *obj=dynamic_cast(ret) ) + if( __Float *obj=dynamic_cast<__Float*>(ret) ) return obj->getValue(); } return def; } -bool ComAttribute::getBool(const char *key, bool def) const +bool ComAttribute::getBool(const std::string& key, bool def) const { - CCObject *ret = _dict->objectForKey(key); + Object *ret = _dict.at(key); if(ret) { - if( CCBool *obj = dynamic_cast(ret) ) + if(__Bool *obj = dynamic_cast<__Bool*>(ret) ) return obj->getValue(); } return def; } -const char* ComAttribute::getCString(const char *key, const char *def) const +std::string ComAttribute::getCString(const std::string& key, const std::string& def) const { - CCObject *ret = _dict->objectForKey(key); + Object *ret = _dict.at(key); if(ret) { - if( CCString *obj = dynamic_cast(ret) ) + if( __String *obj = dynamic_cast<__String*>(ret) ) return obj->getCString(); } return def; diff --git a/cocos/editor-support/cocostudio/CCComAttribute.h b/cocos/editor-support/cocostudio/CCComAttribute.h index e4d7c2f8b1..62d46791b7 100644 --- a/cocos/editor-support/cocostudio/CCComAttribute.h +++ b/cocos/editor-support/cocostudio/CCComAttribute.h @@ -48,17 +48,17 @@ public: virtual bool init(); static ComAttribute* create(void); - void setInt(const char *key, int value); - void setFloat(const char *key, float value); - void setBool(const char *key, bool value); - void setCString(const char *key, const char *value); + void setInt(const std::string& key, int value); + void setFloat(const std::string& key, float value); + void setBool(const std::string& key, bool value); + void setCString(const std::string& key, const std::string& value); - int getInt(const char *key, int def = 0) const; - float getFloat(const char *key, float def = 0.0f) const; - bool getBool(const char *key, bool def = false) const; - const char* getCString(const char *key, const char *def = NULL) const; + int getInt(const std::string& key, int def = 0) const; + float getFloat(const std::string& key, float def = 0.0f) const; + bool getBool(const std::string& key, bool def = false) const; + std::string getCString(const std::string& key, const std::string& def = "") const; private: - cocos2d::CCDictionary *_dict; + cocos2d::Map _dict; }; }