Merge pull request #3057 from DarraghCoy/ccset_bug_fixes

Bugfixes to the Set class.
This commit is contained in:
minggo 2013-07-02 19:41:29 -07:00
commit 1519f9dd2f
1 changed files with 13 additions and 8 deletions

View File

@ -92,27 +92,32 @@ int Set::count(void)
void Set::addObject(Object *pObject)
{
CC_SAFE_RETAIN(pObject);
_set->insert(pObject);
if (_set->count(pObject) == 0)
{
CC_SAFE_RETAIN(pObject);
_set->insert(pObject);
}
}
void Set::removeObject(Object *pObject)
{
_set->erase(pObject);
CC_SAFE_RELEASE(pObject);
if (_set->erase(pObject) > 0)
{
CC_SAFE_RELEASE(pObject);
}
}
void Set::removeAllObjects()
{
SetIterator it;
for (it = _set->begin(); it != _set->end(); ++it)
for (SetIterator it = _set->begin(); it != _set->end(); )
{
if (! (*it))
if (!(*it))
{
break;
}
(*it)->release();
_set->erase(it++);
}
}