issue #6: implement NSSet

This commit is contained in:
Ming 2010-07-16 02:13:27 +00:00
parent 63b87af767
commit 92bf801870
2 changed files with 84 additions and 0 deletions

View File

@ -22,3 +22,60 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "NSSet.h"
using namespace std;
NSSet::NSSet(void)
{
}
NSSet::NSSet(const NSSet &rSetObject) : m_set(rSetObject.m_set)
{
}
NSSet::~NSSet(void)
{
}
NSSet* NSSet::copy(void)
{
NSSet *pSet = new NSSet(*this);
return pSet;
}
NSSet* NSSet::mutableCopy(void)
{
return copy();
}
int NSSet::count(void)
{
return (int)m_set.size();
}
void NSSet::addObject(NSObject *pObject)
{
m_set.insert(pObject);
}
void NSSet::removeObject(NSObject *pObject)
{
m_set.erase(pObject);
}
bool NSSet::containsObject(NSObject *pObject)
{
return m_set.find(pObject) != m_set.end();
}
NSSetIterator NSSet::begin(void)
{
return m_set.begin();
}
NSSetIterator NSSet::end(void)
{
return m_set.end();
}

View File

@ -25,5 +25,32 @@ THE SOFTWARE.
#ifndef __NS_SET_H__
#define __NS_SET_H__
#include <set>
#include "NSObject.h"
typedef std::set<NSObject *>::iterator NSSetIterator;
class NSSet : public NSObject
{
public:
NSSet(void);
NSSet(const NSSet &rSetObject);
virtual ~NSSet(void);
NSSet* copy();
NSSet* mutableCopy();
int count();
void addObject(NSObject *pObject);
void removeObject(NSObject *pObject);
bool containsObject(NSObject *pObject);
NSSetIterator begin();
NSSetIterator end();
private:
std::set<NSObject *> m_set;
};
typedef NSSet NSMutableSet;
#endif // __NS_SET_H__