From 6565fa92cce7f7ccd3edb04a797ffc8233dc1c4e Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 14 Jan 2013 15:51:53 +0800 Subject: [PATCH] fixed #1649: Changed return type to const reference for member variable access. --- cocos2dx/base_nodes/CCAtlasNode.cpp | 2 +- cocos2dx/base_nodes/CCNode.cpp | 8 ++++---- cocos2dx/base_nodes/CCNode.h | 8 ++++---- cocos2dx/include/CCProtocols.h | 2 +- cocos2dx/label_nodes/CCLabelBMFont.cpp | 2 +- cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp | 8 ++++---- cocos2dx/menu_nodes/CCMenu.cpp | 2 +- cocos2dx/menu_nodes/CCMenuItem.cpp | 8 ++++---- cocos2dx/menu_nodes/CCMenuItem.h | 4 ++-- cocos2dx/misc_nodes/CCMotionStreak.cpp | 2 +- cocos2dx/misc_nodes/CCMotionStreak.h | 2 +- cocos2dx/misc_nodes/CCProgressTimer.cpp | 2 +- cocos2dx/misc_nodes/CCProgressTimer.h | 2 +- cocos2dx/particle_nodes/CCParticleSystem.cpp | 12 ++++++------ cocos2dx/platform/CCPlatformMacros.h | 4 ++-- cocos2dx/sprite_nodes/CCSprite.cpp | 2 +- cocos2dx/text_input_node/CCTextFieldTTF.cpp | 2 +- cocos2dx/text_input_node/CCTextFieldTTF.h | 2 +- extensions/GUI/CCControlExtension/CCControl.cpp | 2 +- extensions/GUI/CCControlExtension/CCScale9Sprite.cpp | 2 +- extensions/GUI/CCScrollView/CCScrollView.cpp | 2 +- extensions/GUI/CCScrollView/CCScrollView.h | 2 +- extensions/physics_nodes/CCPhysicsSprite.cpp | 10 ++++++---- extensions/physics_nodes/CCPhysicsSprite.h | 4 ++-- 24 files changed, 49 insertions(+), 47 deletions(-) diff --git a/cocos2dx/base_nodes/CCAtlasNode.cpp b/cocos2dx/base_nodes/CCAtlasNode.cpp index bac4db2835..5eb9a5f0af 100644 --- a/cocos2dx/base_nodes/CCAtlasNode.cpp +++ b/cocos2dx/base_nodes/CCAtlasNode.cpp @@ -142,7 +142,7 @@ void CCAtlasNode::draw(void) // CCAtlasNode - RGBA protocol -ccColor3B CCAtlasNode:: getColor() +const ccColor3B& CCAtlasNode:: getColor() { if(m_bIsOpacityModifyRGB) { diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index b85881d01f..daf63c184f 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -270,7 +270,7 @@ void CCNode::setScaleY(float newScaleY) } /// position getter -CCPoint CCNode::getPosition() +const CCPoint& CCNode::getPosition() { return m_obPosition; } @@ -368,13 +368,13 @@ void CCNode::setVisible(bool var) m_bVisible = var; } -CCPoint CCNode::getAnchorPointInPoints() +const CCPoint& CCNode::getAnchorPointInPoints() { return m_obAnchorPointInPoints; } /// anchorPoint getter -CCPoint CCNode::getAnchorPoint() +const CCPoint& CCNode::getAnchorPoint() { return m_obAnchorPoint; } @@ -390,7 +390,7 @@ void CCNode::setAnchorPoint(const CCPoint& point) } /// contentSize getter -CCSize CCNode::getContentSize() +const CCSize& CCNode::getContentSize() { return m_obContentSize; } diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index bbc8801467..ffdb6d4e5f 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -238,7 +238,7 @@ public: virtual void setScaleY(float fScaleY); /** Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner. */ - virtual CCPoint getPosition(); + virtual const CCPoint& getPosition(); virtual void setPosition(const CCPoint &position); /** The X skew angle of the node in degrees. @@ -320,20 +320,20 @@ public: The default anchorPoint is (0.5,0.5), so it starts in the center of the node. @since v0.8 */ - virtual CCPoint getAnchorPoint(); + virtual const CCPoint& getAnchorPoint(); virtual void setAnchorPoint(const CCPoint &anchorPoint); /** The anchorPoint in absolute pixels. Since v0.8 you can only read it. If you wish to modify it, use anchorPoint instead */ - virtual CCPoint getAnchorPointInPoints(); + virtual const CCPoint& getAnchorPointInPoints(); /** The untransformed size of the node. The contentSize remains the same no matter the node is scaled or rotated. All nodes has a size. Layer and Scene has the same size of the screen. @since v0.8 */ - virtual CCSize getContentSize(); + virtual const CCSize& getContentSize(); virtual void setContentSize(const CCSize &contentSize); virtual bool isVisible(); diff --git a/cocos2dx/include/CCProtocols.h b/cocos2dx/include/CCProtocols.h index e0903b6a43..febee5a16d 100644 --- a/cocos2dx/include/CCProtocols.h +++ b/cocos2dx/include/CCProtocols.h @@ -44,7 +44,7 @@ public: /** returns the color @since v0.8 */ - virtual ccColor3B getColor(void) = 0; + virtual const ccColor3B& getColor(void) = 0; // returns the opacity virtual GLubyte getOpacity(void) = 0; diff --git a/cocos2dx/label_nodes/CCLabelBMFont.cpp b/cocos2dx/label_nodes/CCLabelBMFont.cpp index 800054f751..474b63e378 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.cpp +++ b/cocos2dx/label_nodes/CCLabelBMFont.cpp @@ -1069,7 +1069,7 @@ void CCLabelBMFont::setColor(const ccColor3B& var) } } -ccColor3B CCLabelBMFont::getColor() +const ccColor3B& CCLabelBMFont::getColor() { return m_tColor; } diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index 5cc22057e2..f84f17278a 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -517,7 +517,7 @@ void CCLayerColor::setOpacity(GLubyte var) } /// color getter -ccColor3B CCLayerColor::getColor() +const ccColor3B& CCLayerColor::getColor() { return m_tColor; } @@ -807,7 +807,7 @@ void CCLayerGradient::updateColor() m_pSquareColors[3].a = E.a + (S.a - E.a) * ((c - u.x - u.y) / (2.0f * c)); } -ccColor3B CCLayerGradient::getStartColor() +const ccColor3B& CCLayerGradient::getStartColor() { return m_tColor; } @@ -823,7 +823,7 @@ void CCLayerGradient::setEndColor(const ccColor3B& color) updateColor(); } -ccColor3B CCLayerGradient::getEndColor() +const ccColor3B& CCLayerGradient::getEndColor() { return m_endColor; } @@ -856,7 +856,7 @@ void CCLayerGradient::setVector(const CCPoint& var) updateColor(); } -CCPoint CCLayerGradient::getVector() +const CCPoint& CCLayerGradient::getVector() { return m_AlongVector; } diff --git a/cocos2dx/menu_nodes/CCMenu.cpp b/cocos2dx/menu_nodes/CCMenu.cpp index 571eaf7081..b4c6c77cb3 100644 --- a/cocos2dx/menu_nodes/CCMenu.cpp +++ b/cocos2dx/menu_nodes/CCMenu.cpp @@ -630,7 +630,7 @@ void CCMenu::setColor(const ccColor3B& var) } } -ccColor3B CCMenu::getColor(void) +const ccColor3B& CCMenu::getColor(void) { return m_tColor; } diff --git a/cocos2dx/menu_nodes/CCMenuItem.cpp b/cocos2dx/menu_nodes/CCMenuItem.cpp index a2235d0607..da94562dec 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.cpp +++ b/cocos2dx/menu_nodes/CCMenuItem.cpp @@ -153,7 +153,7 @@ void CCMenuItem::setTarget(CCObject *rec, SEL_MenuHandler selector) //CCMenuItemLabel // -ccColor3B CCMenuItemLabel::getDisabledColor() +const ccColor3B& CCMenuItemLabel::getDisabledColor() { return m_tDisabledColor; } @@ -296,7 +296,7 @@ void CCMenuItemLabel::setColor(const ccColor3B& color) dynamic_cast(m_pLabel)->setColor(color); } -ccColor3B CCMenuItemLabel::getColor() +const ccColor3B& CCMenuItemLabel::getColor() { return dynamic_cast(m_pLabel)->getColor(); } @@ -538,7 +538,7 @@ GLubyte CCMenuItemSprite::getOpacity() return dynamic_cast(m_pNormalImage)->getOpacity(); } -ccColor3B CCMenuItemSprite::getColor() +const ccColor3B& CCMenuItemSprite::getColor() { return dynamic_cast(m_pNormalImage)->getColor(); } @@ -918,7 +918,7 @@ void CCMenuItemToggle::setOpacity(GLubyte opacity) } } -ccColor3B CCMenuItemToggle::getColor() +const ccColor3B& CCMenuItemToggle::getColor() { return m_tColor; } diff --git a/cocos2dx/menu_nodes/CCMenuItem.h b/cocos2dx/menu_nodes/CCMenuItem.h index 6f39fe5036..5fdf2b4c55 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.h +++ b/cocos2dx/menu_nodes/CCMenuItem.h @@ -143,7 +143,7 @@ public: virtual void setOpacity(GLubyte opacity); virtual GLubyte getOpacity(); virtual void setColor(const ccColor3B& color); - virtual ccColor3B getColor(); + virtual const ccColor3B& getColor(); virtual void setOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} virtual bool isOpacityModifyRGB(void) { return false;} @@ -255,7 +255,7 @@ public: bool initWithNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, CCObject* target, SEL_MenuHandler selector); // super methods virtual void setColor(const ccColor3B& color); - virtual ccColor3B getColor(); + virtual const ccColor3B& getColor(); virtual void setOpacity(GLubyte opacity); virtual GLubyte getOpacity(); diff --git a/cocos2dx/misc_nodes/CCMotionStreak.cpp b/cocos2dx/misc_nodes/CCMotionStreak.cpp index 7751c0f75a..1811b28da1 100644 --- a/cocos2dx/misc_nodes/CCMotionStreak.cpp +++ b/cocos2dx/misc_nodes/CCMotionStreak.cpp @@ -185,7 +185,7 @@ void CCMotionStreak::setColor(const ccColor3B& color) m_tColor = color; } -ccColor3B CCMotionStreak::getColor(void) +const ccColor3B& CCMotionStreak::getColor(void) { return m_tColor; } diff --git a/cocos2dx/misc_nodes/CCMotionStreak.h b/cocos2dx/misc_nodes/CCMotionStreak.h index 599f13e1ff..55384b6d4e 100644 --- a/cocos2dx/misc_nodes/CCMotionStreak.h +++ b/cocos2dx/misc_nodes/CCMotionStreak.h @@ -73,7 +73,7 @@ public: virtual void setBlendFunc(ccBlendFunc blendFunc); virtual ccBlendFunc getBlendFunc(void); virtual void setColor(const ccColor3B& color); - virtual ccColor3B getColor(void); + virtual const ccColor3B& getColor(void); virtual GLubyte getOpacity(void); virtual void setOpacity(GLubyte opacity); virtual void setOpacityModifyRGB(bool bValue); diff --git a/cocos2dx/misc_nodes/CCProgressTimer.cpp b/cocos2dx/misc_nodes/CCProgressTimer.cpp index 06f6c9b7cb..f1f373c55e 100644 --- a/cocos2dx/misc_nodes/CCProgressTimer.cpp +++ b/cocos2dx/misc_nodes/CCProgressTimer.cpp @@ -155,7 +155,7 @@ void CCProgressTimer::setColor(const ccColor3B& color) updateColor(); } -ccColor3B CCProgressTimer::getColor(void) +const ccColor3B& CCProgressTimer::getColor(void) { return m_pSprite->getColor(); } diff --git a/cocos2dx/misc_nodes/CCProgressTimer.h b/cocos2dx/misc_nodes/CCProgressTimer.h index e0a6822bad..3ad42649c7 100644 --- a/cocos2dx/misc_nodes/CCProgressTimer.h +++ b/cocos2dx/misc_nodes/CCProgressTimer.h @@ -77,7 +77,7 @@ public: void setAnchorPoint(CCPoint anchorPoint); virtual void setColor(const ccColor3B& color); - virtual ccColor3B getColor(void); + virtual const ccColor3B& getColor(void); virtual GLubyte getOpacity(void); virtual void setOpacity(GLubyte opacity); virtual void setOpacityModifyRGB(bool bValue); diff --git a/cocos2dx/particle_nodes/CCParticleSystem.cpp b/cocos2dx/particle_nodes/CCParticleSystem.cpp index fc41843fd7..c19ad50400 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystem.cpp @@ -1019,7 +1019,7 @@ void CCParticleSystem::setDuration(float var) m_fDuration = var; } -CCPoint CCParticleSystem::getSourcePosition() +const CCPoint& CCParticleSystem::getSourcePosition() { return m_tSourcePosition; } @@ -1029,7 +1029,7 @@ void CCParticleSystem::setSourcePosition(const CCPoint& var) m_tSourcePosition = var; } -CCPoint CCParticleSystem::getPosVar() +const CCPoint& CCParticleSystem::getPosVar() { return m_tPosVar; } @@ -1119,7 +1119,7 @@ void CCParticleSystem::setEndSizeVar(float var) m_fEndSizeVar = var; } -ccColor4F CCParticleSystem::getStartColor() +const ccColor4F& CCParticleSystem::getStartColor() { return m_tStartColor; } @@ -1129,7 +1129,7 @@ void CCParticleSystem::setStartColor(const ccColor4F& var) m_tStartColor = var; } -ccColor4F CCParticleSystem::getStartColorVar() +const ccColor4F& CCParticleSystem::getStartColorVar() { return m_tStartColorVar; } @@ -1139,7 +1139,7 @@ void CCParticleSystem::setStartColorVar(const ccColor4F& var) m_tStartColorVar = var; } -ccColor4F CCParticleSystem::getEndColor() +const ccColor4F& CCParticleSystem::getEndColor() { return m_tEndColor; } @@ -1149,7 +1149,7 @@ void CCParticleSystem::setEndColor(const ccColor4F& var) m_tEndColor = var; } -ccColor4F CCParticleSystem::getEndColorVar() +const ccColor4F& CCParticleSystem::getEndColorVar() { return m_tEndColorVar; } diff --git a/cocos2dx/platform/CCPlatformMacros.h b/cocos2dx/platform/CCPlatformMacros.h index bc31612a63..203526738d 100644 --- a/cocos2dx/platform/CCPlatformMacros.h +++ b/cocos2dx/platform/CCPlatformMacros.h @@ -142,7 +142,7 @@ public: virtual void set##funName(varType var); #define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\ protected: varType varName;\ -public: virtual varType get##funName(void);\ +public: virtual const varType& get##funName(void);\ public: virtual void set##funName(const varType& var); /** CC_SYNTHESIZE_READONLY is used to declare a protected variable. @@ -179,7 +179,7 @@ public: virtual void set##funName(varType var){ varName = var; } #define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\ protected: varType varName;\ -public: virtual varType get##funName(void) const { return varName; }\ +public: virtual const varType& get##funName(void) const { return varName; }\ public: virtual void set##funName(const varType& var){ varName = var; } #define CC_SYNTHESIZE_RETAIN(varType, varName, funName) \ diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 6c1d627402..49e4dbf169 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -931,7 +931,7 @@ void CCSprite::setOpacity(GLubyte opacity) updateColor(); } -ccColor3B CCSprite::getColor(void) +const ccColor3B& CCSprite::getColor(void) { if (m_bOpacityModifyRGB) { diff --git a/cocos2dx/text_input_node/CCTextFieldTTF.cpp b/cocos2dx/text_input_node/CCTextFieldTTF.cpp index b24a186b62..1da4b619e3 100644 --- a/cocos2dx/text_input_node/CCTextFieldTTF.cpp +++ b/cocos2dx/text_input_node/CCTextFieldTTF.cpp @@ -270,7 +270,7 @@ void CCTextFieldTTF::draw() setColor(color); } -ccColor3B CCTextFieldTTF::getColorSpaceHolder() +const ccColor3B& CCTextFieldTTF::getColorSpaceHolder() { return m_ColorSpaceHolder; } diff --git a/cocos2dx/text_input_node/CCTextFieldTTF.h b/cocos2dx/text_input_node/CCTextFieldTTF.h index bbff45fca4..bf06385dac 100644 --- a/cocos2dx/text_input_node/CCTextFieldTTF.h +++ b/cocos2dx/text_input_node/CCTextFieldTTF.h @@ -127,7 +127,7 @@ public: CC_SYNTHESIZE(CCTextFieldDelegate *, m_pDelegate, Delegate); CC_SYNTHESIZE_READONLY(int, m_nCharCount, CharCount); - virtual ccColor3B getColorSpaceHolder(); + virtual const ccColor3B& getColorSpaceHolder(); virtual void setColorSpaceHolder(const ccColor3B& color); // input text property diff --git a/extensions/GUI/CCControlExtension/CCControl.cpp b/extensions/GUI/CCControlExtension/CCControl.cpp index 24f589b4e7..5a81e73c20 100644 --- a/extensions/GUI/CCControlExtension/CCControl.cpp +++ b/extensions/GUI/CCControlExtension/CCControl.cpp @@ -239,7 +239,7 @@ void CCControl::setColor(const ccColor3B& color) } } -ccColor3B CCControl::getColor(void) +const ccColor3B& CCControl::getColor(void) { return m_tColor; } diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp index 2f54d9ca03..8611ba3e7c 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp @@ -618,7 +618,7 @@ void CCScale9Sprite::setColor(const ccColor3B& color3) } } -ccColor3B CCScale9Sprite::getColor(void) +const ccColor3B& CCScale9Sprite::getColor(void) { return m_tColor; } diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index 204c1d54c0..8902832610 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -432,7 +432,7 @@ void CCScrollView::performedAnimatedScroll(float dt) } -CCSize CCScrollView::getContentSize() +const CCSize& CCScrollView::getContentSize() { return m_pContainer->getContentSize(); } diff --git a/extensions/GUI/CCScrollView/CCScrollView.h b/extensions/GUI/CCScrollView/CCScrollView.h index 7a1784faf9..dc689b2f47 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.h +++ b/extensions/GUI/CCScrollView/CCScrollView.h @@ -187,7 +187,7 @@ public: virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent); virtual void setContentSize(const CCSize & size); - virtual CCSize getContentSize(); + virtual const CCSize& getContentSize(); void updateInset(); /** diff --git a/extensions/physics_nodes/CCPhysicsSprite.cpp b/extensions/physics_nodes/CCPhysicsSprite.cpp index 2e19d3048c..3fe2a3fc10 100644 --- a/extensions/physics_nodes/CCPhysicsSprite.cpp +++ b/extensions/physics_nodes/CCPhysicsSprite.cpp @@ -177,10 +177,11 @@ void CCPhysicsSprite::setCPBody(cpBody *pBody) } // Override the setters and getters to always reflect the body's properties. -CCPoint CCPhysicsSprite::getPosition() +const CCPoint& CCPhysicsSprite::getPosition() { cpVect cpPos = cpBodyGetPos(m_pCPBody); - return ccp(cpPos.x, cpPos.y); + m_obPosition = ccp(cpPos.x, cpPos.y); + return m_obPosition; } void CCPhysicsSprite::setPosition(const CCPoint &pos) @@ -245,13 +246,14 @@ void CCPhysicsSprite::setPTMRatio(float fRatio) } // Override the setters and getters to always reflect the body's properties. -CCPoint CCPhysicsSprite::getPosition() +const CCPoint& CCPhysicsSprite::getPosition() { b2Vec2 pos = m_pB2Body->GetPosition(); float x = pos.x * m_fPTMRatio; float y = pos.y * m_fPTMRatio; - return ccp(x,y); + m_obPosition = ccp(x,y); + return m_obPosition; } void CCPhysicsSprite::setPosition(const CCPoint &pos) diff --git a/extensions/physics_nodes/CCPhysicsSprite.h b/extensions/physics_nodes/CCPhysicsSprite.h index b485f58b74..30df1cdec9 100644 --- a/extensions/physics_nodes/CCPhysicsSprite.h +++ b/extensions/physics_nodes/CCPhysicsSprite.h @@ -102,7 +102,7 @@ public: #if CC_ENABLE_CHIPMUNK_INTEGRATION - virtual CCPoint getPosition(); + virtual const CCPoint& getPosition(); virtual void setPosition(const CCPoint &position); virtual float getRotation(); virtual void setRotation(float fRotation); @@ -114,7 +114,7 @@ public: #elif CC_ENABLE_BOX2D_INTEGRATION - virtual CCPoint getPosition(); + virtual const CCPoint& getPosition(); virtual void setPosition(const CCPoint &position); virtual float getRotation(); virtual void setRotation(float fRotation);