2010-07-06 15:46:45 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
2010-07-06 20:55:05 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
2010-07-06 15:46:45 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCSet.h"
|
2010-07-16 10:13:27 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSet::CCSet(void)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_pSet = new set<CCObject *>;
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSet::CCSet(const CCSet &rSetObject)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_pSet = new set<CCObject *>(*rSetObject.m_pSet);
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSet::~CCSet(void)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2010-10-01 14:34:47 +08:00
|
|
|
if (m_pSet)
|
|
|
|
{
|
|
|
|
delete m_pSet;
|
|
|
|
m_pSet = NULL;
|
|
|
|
}
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSet* CCSet::copy(void)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSet *pSet = new CCSet(*this);
|
2010-07-16 10:13:27 +08:00
|
|
|
|
|
|
|
return pSet;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSet* CCSet::mutableCopy(void)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
|
|
|
return copy();
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
int CCSet::count(void)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2010-10-01 14:34:47 +08:00
|
|
|
return (int)m_pSet->size();
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void CCSet::addObject(CCObject *pObject)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2010-10-01 14:34:47 +08:00
|
|
|
m_pSet->insert(pObject);
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void CCSet::removeObject(CCObject *pObject)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2010-10-01 14:34:47 +08:00
|
|
|
m_pSet->erase(pObject);
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
bool CCSet::containsObject(CCObject *pObject)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2010-10-01 14:34:47 +08:00
|
|
|
return m_pSet->find(pObject) != m_pSet->end();
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSetIterator CCSet::begin(void)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2010-10-01 14:34:47 +08:00
|
|
|
return m_pSet->begin();
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSetIterator CCSet::end(void)
|
2010-07-16 10:13:27 +08:00
|
|
|
{
|
2010-10-01 14:34:47 +08:00
|
|
|
return m_pSet->end();
|
2010-07-16 10:13:27 +08:00
|
|
|
}
|
2010-10-01 23:05:05 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject* CCSet::anyObject()
|
2010-10-01 23:05:05 +08:00
|
|
|
{
|
|
|
|
if (!m_pSet || m_pSet->empty())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSetIterator it;
|
2010-10-01 23:05:05 +08:00
|
|
|
|
|
|
|
for( it = m_pSet->begin(); it != m_pSet->end(); it++)
|
|
|
|
{
|
|
|
|
if (*it)
|
|
|
|
{
|
|
|
|
return (*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|