blob: ceccbdcc0073af2369b975ec8bde099b4298433c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#include "MCSet.h"
#include "MCHashMap.h"
#include "MCString.h"
#include "MCUtils.h"
#include "MCArray.h"
#include "MCLog.h"
using namespace mailcore;
void Set::init()
{
mHash = new HashMap();
}
Set::Set()
{
init();
}
Set::Set(Set * o)
{
init();
MC_SAFE_REPLACE_COPY(HashMap, mHash, o->mHash);
}
Set::~Set()
{
delete mHash;
}
Set * Set::set()
{
Set * result = new Set();
return (Set *) result->autorelease();
}
Set * Set::setWithArray(Array * objects)
{
Set * result = new Set();
result->addObjectsFromArray(objects);
return (Set *) result->autorelease();
}
String * Set::description()
{
String * result = String::string();
result->appendUTF8Format("<%s:%p ", MCUTF8(className()), this);
result->appendString(mHash->allKeys()->description());
result->appendUTF8Characters(">");
return result;
}
Object * Set::copy()
{
return new Set(this);
}
unsigned int Set::count()
{
return mHash->count();
}
void Set::addObject(Object * obj)
{
mHash->setObjectForKey(obj, obj);
}
void Set::removeObject(Object * obj)
{
mHash->removeObjectForKey(obj);
}
Object * Set::member(Object * obj)
{
return mHash->objectForKey(obj);
}
bool Set::containsObject(Object * obj)
{
return (mHash->objectForKey(obj) != NULL);
}
Array * Set::allObjects()
{
return mHash->allKeys();
}
void Set::removeAllObjects()
{
mHash->removeAllObjects();
}
void Set::addObjectsFromArray(Array * objects)
{
if (objects == NULL)
return;
for(unsigned int i= 0 ; i < objects->count() ; i ++) {
addObject(objects->objectAtIndex(i));
}
}
HashMap * Set::serializable()
{
HashMap * result = Object::serializable();
result->setObjectForKey(MCSTR("items"), allObjects()->serializable());
return result;
}
void Set::importSerializable(HashMap * serializable)
{
Array * array = (Array *) Object::objectWithSerializable((HashMap *) serializable->objectForKey(MCSTR("items")));
addObjectsFromArray(array);
}
static void * createObject()
{
return new Set();
}
__attribute__((constructor))
static void initialize()
{
Object::registerObjectConstructor("mailcore::Set", &createObject);
}
|