add constness to some function

This commit is contained in:
andyque 2014-06-23 10:12:54 +08:00
parent 8a463e7964
commit 87455b0ecb
13 changed files with 68 additions and 68 deletions

View File

@ -332,7 +332,7 @@ Frame* ActionTimelineCache::loadTextureFrame(const rapidjson::Value& json)
const char* texture = DICTOOL->getStringValue_json(json, Value);
if(texture != NULL)
if(texture != nullptr)
{
std::string path = texture;
@ -354,7 +354,7 @@ Frame* ActionTimelineCache::loadEventFrame(const rapidjson::Value& json)
const char* evnt = DICTOOL->getStringValue_json(json, Value);
if(evnt != NULL)
if(evnt != nullptr)
frame->setEvent(evnt);
return frame;

View File

@ -84,7 +84,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
cocos2d::Vector<ActionObject*> actionList;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
stExpCocoNode *actionNode = NULL;
stExpCocoNode *actionNode = nullptr;
for (int i=0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
if (key == "actionlist") {
@ -92,7 +92,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
break;
}
}
if (NULL != actionNode)
if (nullptr != actionNode)
{
int actionCount = actionNode->GetChildNum();
for (int i = 0; i < actionCount; ++i) {

View File

@ -169,11 +169,11 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
initActionNodeFromRoot(root);
}
int ActionNode::valueToInt(std::string& value)
int ActionNode::valueToInt(const std::string& value)
{
return atoi(value.c_str());
}
bool ActionNode::valueToBool(std::string& value)
bool ActionNode::valueToBool(const std::string& value)
{
int intValue = valueToInt(value);
if (1 == intValue) {
@ -182,7 +182,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
return false;
}
}
float ActionNode::valueToFloat(std::string& value)
float ActionNode::valueToFloat(const std::string& value)
{
return atof(value.c_str());
}
@ -196,7 +196,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
int actionNodeCount = stChildNode->GetChildNum();
stChildNode = stChildNode[0].GetChildArray();
stExpCocoNode *frameListNode = NULL;
stExpCocoNode *frameListNode = nullptr;
for (int i = 0; i < actionNodeCount; ++i) {
std::string key = stChildNode[i].GetName(cocoLoader);
std::string value = stChildNode[i].GetValue();

View File

@ -160,9 +160,9 @@ public:
*/
virtual bool isActionDoneOnce();
protected:
int valueToInt(std::string& value);
bool valueToBool(std::string& value);
float valueToFloat(std::string& value);
int valueToInt(const std::string& value);
bool valueToBool(const std::string& value);
float valueToFloat(const std::string& value);
int _currentFrameIndex;
int _destFrameIndex;

View File

@ -133,7 +133,7 @@ void ActionObject::initWithBinary(CocoLoader *cocoLoader,
cocos2d::Ref *root)
{
stExpCocoNode *stChildNode = cocoNode->GetChildArray();
stExpCocoNode *actionNodeList = NULL;
stExpCocoNode *actionNodeList = nullptr;
int count = cocoNode->GetChildNum();
for (int i = 0; i < count; ++i) {
std::string key = stChildNode[i].GetName(cocoLoader);
@ -149,7 +149,7 @@ void ActionObject::initWithBinary(CocoLoader *cocoLoader,
}
}
if(NULL != actionNodeList)
if(nullptr != actionNodeList)
{
int actionNodeCount = actionNodeList->GetChildNum();
stExpCocoNode *actionNodeArray = actionNodeList->GetChildArray();
@ -174,11 +174,11 @@ void ActionObject::initWithBinary(CocoLoader *cocoLoader,
}
}
int ActionObject::valueToInt(std::string& value)
int ActionObject::valueToInt(const std::string& value)
{
return atoi(value.c_str());
}
bool ActionObject::valueToBool(std::string& value)
bool ActionObject::valueToBool(const std::string& value)
{
int intValue = valueToInt(value);
if (1 == intValue) {
@ -187,7 +187,7 @@ bool ActionObject::valueToBool(std::string& value)
return false;
}
}
float ActionObject::valueToFloat(std::string& value)
float ActionObject::valueToFloat(const std::string& value)
{
return atof(value.c_str());
}

View File

@ -170,9 +170,9 @@ public:
/*scheduler update function*/
void simulationActionUpdate(float dt);
protected:
int valueToInt(std::string& value);
bool valueToBool(std::string& value);
float valueToFloat(std::string& value);
int valueToInt(const std::string& value);
bool valueToBool(const std::string& value);
float valueToFloat(const std::string& value);
cocos2d::Vector<ActionNode*> _actionNodeList;
std::string _name;

View File

@ -1405,7 +1405,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(const rapidjson::Value& json, D
displayData = new SpriteDisplayData();
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
if(name != NULL)
if(name != nullptr)
{
((SpriteDisplayData *)displayData)->displayName = name;
}
@ -1823,7 +1823,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
}
}
// Auto losprite file
bool autoLoad = dataInfo->asyncStruct == NULL ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile;
bool autoLoad = dataInfo->asyncStruct == nullptr ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile;
if (autoLoad)
{
for (int i = 0; i < nCount; ++i)
@ -1838,7 +1838,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
for (int ii = 0; ii < length; ii++)
{
const char *path = pConfigFilePath[ii].GetValue();
if (path == NULL)
if (path == nullptr)
{
CCLOG("load CONFIG_FILE_PATH error.");
return;
@ -1871,7 +1871,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
armatureData->init();
stExpCocoNode *pAramtureDataArray = cocoNode->GetChildArray();
const char *name = pAramtureDataArray[2].GetValue(); //DICTOOL->getStringValue_json(json, A_NAME);
if(name != NULL)
if(name != nullptr)
{
armatureData->name = name;
}
@ -1904,7 +1904,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
int length = cocoNode->GetChildNum();
stExpCocoNode *pBoneChildren = cocoNode->GetChildArray();
stExpCocoNode* child;
const char *str = NULL;
const char *str = nullptr;
std::string key;
for (int i = 0; i < length; ++i)
{
@ -1914,7 +1914,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
if (key.compare(A_NAME) == 0)
{
//DICTOOL->getStringValue_json(json, A_NAME);
if(str != NULL)
if(str != nullptr)
{
boneData->name = str;
}
@ -1922,7 +1922,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_PARENT) == 0)
{
//DICTOOL->getStringValue_json(json, A_PARENT);
if(str != NULL)
if(str != nullptr)
{
boneData->parentName = str;
}
@ -1934,7 +1934,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
for (int ii = 0; ii < count; ++ii)
{
DisplayData *displayData = decodeBoneDisplay(cocoLoader, &pDisplayData[ii], dataInfo);
if(displayData == NULL)
if(displayData == nullptr)
continue;
boneData->addDisplayData(displayData);
displayData->release();
@ -1949,11 +1949,11 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
stExpCocoNode* children = cocoNode->GetChildArray();
stExpCocoNode* child = &children[1];
const char *str = NULL;
const char *str = nullptr;
std::string key = child->GetName(cocoLoader);
str = child->GetValue();
DisplayData *displayData = NULL;
DisplayData *displayData = nullptr;
if (key.compare(A_DISPLAY_TYPE) == 0)
{
str = child->GetValue();
@ -1967,15 +1967,15 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
displayData = new SpriteDisplayData();
const char *name = children[0].GetValue();
if(name != NULL)
if(name != nullptr)
{
((SpriteDisplayData *)displayData)->displayName = name;
}
stExpCocoNode *pSkinDataArray = children[2].GetChildArray();
if (pSkinDataArray != NULL)
if (pSkinDataArray != nullptr)
{
stExpCocoNode *pSkinData = &pSkinDataArray[0];
if (pSkinData != NULL)
if (pSkinData != nullptr)
{
SpriteDisplayData *sdd = (SpriteDisplayData *)displayData;
length = pSkinData->GetChildNum();
@ -2022,7 +2022,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
displayData = new ArmatureDisplayData();
const char *name = cocoNode[0].GetValue();
if(name != NULL)
if(name != nullptr)
{
((ArmatureDisplayData *)displayData)->displayName = name;
}
@ -2040,7 +2040,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
if (key.compare(A_PLIST) == 0)
{
const char *plist = str;
if(plist != NULL)
if(plist != nullptr)
{
if (dataInfo->asyncStruct)
{
@ -2071,7 +2071,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
int length = cocoNode->GetChildNum();
stExpCocoNode *pAnimationData = cocoNode->GetChildArray();
const char *str = NULL;
const char *str = nullptr;
std::string key;
stExpCocoNode* child;
MovementData *movementData;
@ -2082,7 +2082,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
str = child->GetValue();
if (key.compare(A_NAME) == 0)
{
if(str != NULL)
if(str != nullptr)
{
aniData->name = str;
}
@ -2110,7 +2110,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
int length = cocoNode->GetChildNum();
stExpCocoNode *pMoveDataArray = cocoNode->GetChildArray();
const char *str = NULL;
const char *str = nullptr;
std::string key;
stExpCocoNode* child;
for (int i = 0; i < length; ++i)
@ -2120,7 +2120,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
str = child->GetValue();
if (key.compare(A_NAME) == 0)
{
if(str != NULL)
if(str != nullptr)
{
movementData->name = str;
}
@ -2128,7 +2128,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_LOOP) == 0)
{
movementData->loop = true;
if(str != NULL)
if(str != nullptr)
{
if (strcmp("1", str) != 0)
{
@ -2139,7 +2139,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_DURATION_TWEEN) == 0)
{
movementData->durationTween = 0;
if(str != NULL)
if(str != nullptr)
{
movementData->durationTween = atoi(str);
}
@ -2147,7 +2147,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_DURATION_TO) == 0)
{
movementData->durationTo = 0;
if(str != NULL)
if(str != nullptr)
{
movementData->durationTo = atoi(str);
}
@ -2155,7 +2155,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_DURATION) == 0)
{
movementData->duration = 0;
if(str != NULL)
if(str != nullptr)
{
movementData->duration = atoi(str);
}
@ -2163,7 +2163,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_MOVEMENT_SCALE) == 0)
{
movementData->scale = 1.0;
if(str != NULL)
if(str != nullptr)
{
movementData->scale = atof(str);
}
@ -2171,7 +2171,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_TWEEN_EASING) == 0)
{
movementData->tweenEasing = cocos2d::tweenfunc::Linear;
if(str != NULL)
if(str != nullptr)
{
movementData->tweenEasing = (TweenType)(atoi(str));
}
@ -2200,7 +2200,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
int length = cocoNode->GetChildNum();
stExpCocoNode *pMovementBoneDataArray = cocoNode->GetChildArray();
stExpCocoNode* movebonechild;
const char *str = NULL;
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
movebonechild = &pMovementBoneDataArray[i];
@ -2208,14 +2208,14 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
str = movebonechild->GetValue();
if (key.compare(A_NAME) == 0)
{
if(str != NULL)
if(str != nullptr)
{
movementBoneData->name = str;
}
}
else if (key.compare(A_MOVEMENT_DELAY) == 0)
{
if(str != NULL)
if(str != nullptr)
{
movementBoneData->delay = atof(str);
}
@ -2294,7 +2294,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
int length = cocoNode->GetChildNum();
stExpCocoNode *pFrameDataArray = cocoNode->GetChildArray();
const char *str = NULL;
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
std::string key = pFrameDataArray[i].GetName(cocoLoader);
@ -2302,28 +2302,28 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
if (key.compare(A_TWEEN_EASING) == 0)
{
frameData->tweenEasing = cocos2d::tweenfunc::Linear;
if(str != NULL)
if(str != nullptr)
{
frameData->tweenEasing = (TweenType)(atoi(str));
}
}
else if (key.compare(A_DISPLAY_INDEX) == 0)
{
if(str != NULL)
if(str != nullptr)
{
frameData->displayIndex = atoi(str);
}
}
else if (key.compare(A_BLEND_SRC) == 0)
{
if(str != NULL)
if(str != nullptr)
{
frameData->blendFunc.src = (GLenum)(atoi(str));
}
}
else if (key.compare(A_BLEND_DST) == 0)
{
if(str != NULL)
if(str != nullptr)
{
frameData->blendFunc.dst = (GLenum)(atoi(str));
}
@ -2331,7 +2331,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(A_TWEEN_FRAME) == 0)
{
frameData->isTween = true;
if(str != NULL)
if(str != nullptr)
{
if (strcmp("1", str) != 0)
{
@ -2341,7 +2341,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
}
else if (key.compare(A_EVENT) == 0)
{
if(str != NULL)
if(str != nullptr)
{
frameData->strEvent = str;
}
@ -2351,7 +2351,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
{
frameData->duration = 1;
if(str != NULL)
if(str != nullptr)
{
frameData->duration = atoi(str);
}
@ -2361,7 +2361,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
if (dataInfo->cocoStudioVersion >= VERSION_COMBINED)
{
if(str != NULL)
if(str != nullptr)
{
frameData->frameID = atoi(str);
}
@ -2377,7 +2377,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
for (int ii = 0; ii < count; ++ii)
{
str = pFrameData[ii].GetValue();
if (str != NULL)
if (str != nullptr)
{
frameData->easingParams[ii] = atof(str);
}
@ -2491,7 +2491,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
int length = cocoNode->GetChildNum();
stExpCocoNode *NodeArray = cocoNode->GetChildArray();
const char *str = NULL;
const char *str = nullptr;
bool isVersionL = dataInfo->cocoStudioVersion < VERSION_COLOR_READING;
stExpCocoNode* child;

View File

@ -179,7 +179,7 @@ public:
// for binary decode
public:
static void addDataFromBinaryCache(const char *fileContent, DataInfo *dataInfo = NULL);
static void addDataFromBinaryCache(const char *fileContent, DataInfo *dataInfo = nullptr);
static ArmatureData *decodeArmature(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static BoneData *decodeBone(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);
static DisplayData *decodeBoneDisplay(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo);

View File

@ -29,7 +29,7 @@ namespace cocostudio
static ButtonReader* instanceButtonReader = NULL;
static ButtonReader* instanceButtonReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ButtonReader)

View File

@ -10,7 +10,7 @@ using namespace ui;
namespace cocostudio
{
static PageViewReader* instancePageViewReader = NULL;
static PageViewReader* instancePageViewReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(PageViewReader)

View File

@ -14,7 +14,7 @@ namespace cocostudio
static const char* P_Direction = "direction";
static const char* P_BounceEnable = "bounceEnable";
static ScrollViewReader* instanceScrollViewReader = NULL;
static ScrollViewReader* instanceScrollViewReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader)

View File

@ -73,11 +73,11 @@ namespace cocostudio
_positionPercentY(0.0f),
_opacity(255)
{
valueToInt = [=](std::string str) -> int{
valueToInt = [=](const std::string& str) -> int{
return atoi(str.c_str());
};
valueToBool = [=](std::string str) -> bool{
valueToBool = [=](const std::string& str) -> bool{
int intValue = valueToInt(str);
if (1 == intValue) {
return true;
@ -86,7 +86,7 @@ namespace cocostudio
}
};
valueToFloat = [=](std::string str) -> float{
valueToFloat = [=](const std::string& str) -> float{
return atof(str.c_str());
};
}

View File

@ -69,9 +69,9 @@ namespace cocostudio
void endSetBasicProperties(cocos2d::ui::Widget *widget);
std::function<int(std::string)> valueToInt;
std::function<bool(std::string)> valueToBool;
std::function<float(std::string)> valueToFloat;
std::function<int(const std::string&)> valueToInt;
std::function<bool(const std::string&)> valueToBool;
std::function<float(const std::string&)> valueToFloat;
float _sizePercentX;
float _sizePercentY;