More std::for_each —> for(const auto& …)

This commit is contained in:
James Chen 2013-12-20 09:54:50 +08:00
parent 72e02e3046
commit 34382b4a8a
5 changed files with 34 additions and 29 deletions

View File

@ -38,7 +38,7 @@ THE SOFTWARE.
NS_CC_BEGIN
static void addValueToDict(id nsKey, id nsValue, ValueMap& dict);
static void addObjectToNSDict(const std::string& key, Value& value, NSMutableDictionary *dict);
static void addObjectToNSDict(const std::string& key, const Value& value, NSMutableDictionary *dict);
static void addItemToArray(id item, ValueVector& array)
{
@ -83,7 +83,7 @@ static void addItemToArray(id item, ValueVector& array)
}
}
static void addObjectToNSArray(Value& value, NSMutableArray *array)
static void addObjectToNSArray(const Value& value, NSMutableArray *array)
{
// add string into array
if (value.getType() == Value::Type::STRING)
@ -100,9 +100,10 @@ static void addObjectToNSArray(Value& value, NSMutableArray *array)
ValueVector valueArray = value.asValueVector();
std::for_each(valueArray.begin(), valueArray.end(), [=](Value& e){
for (const auto &e : valueArray)
{
addObjectToNSArray(e, element);
});
}
[array addObject:element];
return;
@ -171,7 +172,7 @@ static void addValueToDict(id nsKey, id nsValue, ValueMap& dict)
}
}
static void addObjectToNSDict(const std::string& key, Value& value, NSMutableDictionary *dict)
static void addObjectToNSDict(const std::string& key, const Value& value, NSMutableDictionary *dict)
{
NSString *NSkey = [NSString stringWithCString:key.c_str() encoding:NSUTF8StringEncoding];
@ -204,9 +205,10 @@ static void addObjectToNSDict(const std::string& key, Value& value, NSMutableDic
ValueVector array = value.asValueVector();
std::for_each(array.begin(), array.end(), [=](Value& v){
for(const auto& v : array)
{
addObjectToNSArray(v, arrElement);
});
}
[dict setObject:arrElement forKey:NSkey];
return;

View File

@ -296,7 +296,10 @@ void Renderer::render()
//TODO give command back to command pool
for (size_t j = 0 ; j < _renderGroups.size(); j++)
{
for_each(_renderGroups[j].begin(), _renderGroups[j].end(), [](RenderCommand* cmd){ cmd->releaseToCommandPool(); });
for (const auto &cmd : _renderGroups[j])
{
cmd->releaseToCommandPool();
}
_renderGroups[j].clear();
}

View File

@ -472,7 +472,7 @@ Rect Armature::getBoundingBox() const
Rect boundingBox = Rect(0, 0, 0, 0);
for_each(_children.begin(), _children.end(), [&minx, &miny, &maxx, &maxy, &first, &boundingBox](Node *object)
for (const auto& object : _children)
{
if (Bone *bone = dynamic_cast<Bone *>(object))
{
@ -498,7 +498,7 @@ Rect Armature::getBoundingBox() const
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
}
});
}
return RectApplyTransform(boundingBox, getNodeToParentTransform());
}
@ -642,15 +642,15 @@ void Armature::setBody(cpBody *body)
_body = body;
_body->data = this;
for (auto& object : _children)
for (const auto& object : _children)
{
if (Bone *bone = dynamic_cast<Bone *>(object))
{
auto displayList = bone->getDisplayManager()->getDecorativeDisplayList();
for_each(displayList.begin(), displayList.end(), [&body](DecorativeDisplay* displayObject)
for (const auto& displayObject : displayList)
{
ColliderDetector *detector = displayObject->getColliderDetector();
auto detector = displayObject->getColliderDetector();
if (detector != nullptr)
{
detector->setBody(body);

View File

@ -97,28 +97,28 @@ bool ArmatureAnimation::init(Armature *armature)
void ArmatureAnimation::pause()
{
for_each(_tweenList.begin(), _tweenList.end(), [](Tween *tween)
for (const auto& tween : _tweenList)
{
tween->pause();
});
}
ProcessBase::pause();
}
void ArmatureAnimation::resume()
{
for_each(_tweenList.begin(), _tweenList.end(), [](Tween *tween)
for (const auto& tween : _tweenList)
{
tween->resume();
});
}
ProcessBase::resume();
}
void ArmatureAnimation::stop()
{
for_each(_tweenList.begin(), _tweenList.end(), [](Tween *tween)
for (const auto& tween : _tweenList)
{
tween->stop();
});
}
_tweenList.clear();
ProcessBase::stop();
}
@ -308,10 +308,10 @@ void ArmatureAnimation::gotoAndPlay(int frameIndex)
_currentFrame = _nextFrameIndex * _currentPercent;
for_each(_tweenList.begin(), _tweenList.end(), [&frameIndex](Tween* tween)
for (const auto &tween : _tweenList)
{
tween->gotoAndPlay(frameIndex);
});
}
_armature->update(0);
@ -333,10 +333,10 @@ void ArmatureAnimation::update(float dt)
{
ProcessBase::update(dt);
for_each(_tweenList.begin(), _tweenList.end(), [&dt](Tween* tween)
for (const auto &tween : _tweenList)
{
tween->update(dt);
});
}
while (_frameEventQueue.size() > 0)
{

View File

@ -202,28 +202,28 @@ void ColliderDetector::addContourData(ContourData *contourData)
void ColliderDetector::addContourDataList(cocos2d::Vector<ContourData*> &contourDataList)
{
for_each(contourDataList.begin(), contourDataList.end(), [this](ContourData *contourData)
for (const auto &contourData : contourDataList)
{
this->addContourData(contourData);
});
}
}
void ColliderDetector::removeContourData(ContourData *contourData)
{
std::vector<ColliderBody*> eraseList;
for_each(_colliderBodyList.begin(), _colliderBodyList.end(), [&contourData, this, &eraseList](ColliderBody *body)
for (const auto &body : _colliderBodyList)
{
if (body && body->getContourData() == contourData)
{
eraseList.push_back(body);
}
});
}
for_each(eraseList.begin(), eraseList.end(), [this](ColliderBody *body)
for (const auto &body : eraseList)
{
this->_colliderBodyList.eraseObject(body);
});
}
}
void ColliderDetector::removeAll()