2013-10-12 15:25:45 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "deprecated/CCSet.h"
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__Set::__Set(void)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
_set = new (std::nothrow) set<Ref *>;
|
2013-10-12 15:25:45 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
__Set::__Set(const __Set &other)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
_set = new (std::nothrow) set<Ref *>(*other._set);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
// call retain of members
|
2013-12-06 18:16:58 +08:00
|
|
|
__SetIterator iter;
|
2013-10-12 15:25:45 +08:00
|
|
|
for (iter = _set->begin(); iter != _set->end(); ++iter)
|
|
|
|
{
|
|
|
|
if (! (*iter))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*iter)->retain();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__Set::~__Set(void)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
removeAllObjects();
|
|
|
|
CC_SAFE_DELETE(_set);
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
void __Set::acceptVisitor(DataVisitor &visitor)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
visitor.visit(this);
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__Set * __Set::create()
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
__Set * pRet = new (std::nothrow) __Set();
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
if (pRet != nullptr)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__Set* __Set::copy(void)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
__Set *p__Set = new (std::nothrow) __Set(*this);
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
return p__Set;
|
2013-10-12 15:25:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__Set* __Set::mutableCopy(void)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
return copy();
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
int __Set::count(void)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
return (int)_set->size();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void __Set::addObject(Ref *pObject)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
if (_set->count(pObject) == 0)
|
|
|
|
{
|
|
|
|
CC_SAFE_RETAIN(pObject);
|
|
|
|
_set->insert(pObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void __Set::removeObject(Ref *pObject)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
if (_set->erase(pObject) > 0)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(pObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
void __Set::removeAllObjects()
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
2013-12-06 18:16:58 +08:00
|
|
|
__SetIterator it = _set->begin();
|
|
|
|
__SetIterator tmp;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
while (it != _set->end())
|
|
|
|
{
|
|
|
|
if (!(*it))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = it;
|
|
|
|
++tmp;
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref * obj = *it;
|
2013-10-12 15:25:45 +08:00
|
|
|
_set->erase(it);
|
|
|
|
CC_SAFE_RELEASE(obj);
|
|
|
|
it = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
bool __Set::containsObject(Ref *pObject)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
return _set->find(pObject) != _set->end();
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__SetIterator __Set::begin(void)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
return _set->begin();
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__SetIterator __Set::end(void)
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
return _set->end();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* __Set::anyObject()
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
if (!_set || _set->empty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:16:58 +08:00
|
|
|
__SetIterator it;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
for( it = _set->begin(); it != _set->end(); ++it)
|
|
|
|
{
|
|
|
|
if (*it)
|
|
|
|
{
|
|
|
|
return (*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|