00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "ObjectCollection.h"
00026
00027 namespace cmlabs {
00028
00029
00030
00031
00032
00033 ObjectCollection::ObjectCollection()
00034 {
00035 objectTable.type = "objectcollection";
00036 }
00037
00038 ObjectCollection::ObjectCollection(const JString& xml) : CollectionBase(xml) {
00039 objectTable.type = "objectcollection";
00040 }
00041
00042 ObjectCollection::ObjectCollection(XMLNode *node) : CollectionBase(node) {
00043 objectTable.type = "objectcollection";
00044 }
00045
00046 ObjectCollection::~ObjectCollection()
00047 {
00048 }
00049
00050 ObjectCollection::ObjectCollection(const ObjectCollection &c) {
00051 objectTable.addAll(c.objectTable);
00052 objectTable.deleteOnDestroy = c.objectTable.deleteOnDestroy;
00053 objectTable.type = c.objectTable.type;
00054 objectTable.sorting = c.objectTable.sorting;
00055 }
00056
00057 const ObjectCollection& ObjectCollection::operator = (const ObjectCollection& c) {
00058 objectTable.removeAll();
00059 objectTable.addAll(c.objectTable);
00060 objectTable.deleteOnDestroy = c.objectTable.deleteOnDestroy;
00061 objectTable.type = c.objectTable.type;
00062 objectTable.sorting = c.objectTable.sorting;
00063 return *this;
00064 }
00065
00066
00067 bool ObjectCollection::contains(Object* obj) const {
00068 return objectTable.contains(obj);
00069 }
00070
00071 int ObjectCollection::getPos(Object* obj) const {
00072 return objectTable.getPos(obj);
00073 }
00074
00075
00076 Object* ObjectCollection::getFirst() {
00077 return objectTable.getFirst();
00078 }
00079
00080 Object* ObjectCollection::getLast() {
00081 return objectTable.getLast();
00082 }
00083
00084 Object* ObjectCollection::getNext() {
00085 return objectTable.getNext();
00086 }
00087
00088 Object* ObjectCollection::getPrevious() {
00089 return objectTable.getPrevious();
00090 }
00091
00092 Object* ObjectCollection::get(int pos) {
00093 return objectTable.get(pos);
00094 }
00095
00096 Object* ObjectCollection::get(int pos) const {
00097 return objectTable.get(pos);
00098 }
00099
00100 Object* ObjectCollection::take(int pos) {
00101 return objectTable.take(pos);
00102 }
00103
00104 Object* ObjectCollection::operator [](int pos) const {
00105 return get(pos);
00106 }
00107
00108 bool ObjectCollection::add(Object* obj) {
00109 return objectTable.add(NULL, obj);
00110 }
00111
00112 bool ObjectCollection::addFirst(Object* obj) {
00113 return objectTable.addFirst(NULL, obj);
00114 }
00115
00116 bool ObjectCollection::addLast(Object* obj) {
00117 return objectTable.addLast(NULL, obj);
00118 }
00119
00120 bool ObjectCollection::addAfter(int pos, Object* obj) {
00121 return objectTable.addAfter(pos, NULL, obj);
00122 }
00123
00124 bool ObjectCollection::addBefore(int pos, Object* obj) {
00125 return objectTable.addBefore(pos, NULL, obj);
00126 }
00127
00128 bool ObjectCollection::replace(int pos, Object* obj) {
00129 return objectTable.replace(pos, NULL, obj);
00130 }
00131
00132 int ObjectCollection::replace(Object* oldobj, Object* obj) {
00133 return objectTable.replace(oldobj, NULL, obj);
00134 }
00135
00136 int ObjectCollection::removeEntries(Object* obj) {
00137 return objectTable.remove(obj, true);
00138 }
00139
00140 bool ObjectCollection::remove(Object* obj) {
00141 return (objectTable.remove(obj, false) > 0);
00142 }
00143
00144 bool ObjectCollection::remove(int pos) {
00145 return objectTable.remove(pos);
00146 }
00147
00148 bool ObjectCollection::removeNoDelete(int pos) {
00149 return objectTable.removeNoDelete(pos);
00150 }
00151
00152 int ObjectCollection::removeNoDelete(Object* obj) {
00153 return objectTable.removeNoDelete(obj, false);
00154 }
00155
00156
00157
00158
00159
00160
00161 bool ObjectCollection::unitTest() {
00162
00163 ObjectCollection* oc = new ObjectCollection();
00164
00165 oc->add(new JString("Test1"));
00166 oc->add(new JString("Test2"));
00167 oc->add(new JString("Test3"));
00168 oc->add(new JString("Test4"));
00169 oc->add(new JString("Test5"));
00170 oc->add(new JString("Test6"));
00171
00172 Object* obj;
00173 if ( (obj = oc->getFirst()) == NULL)
00174 return false;
00175 if (!((JString*)obj)->equals("Test1") )
00176 return false;
00177 if ( (obj = oc->getNext()) == NULL)
00178 return false;
00179 if (!((JString*)obj)->equals("Test2") )
00180 return false;
00181 if ( (obj = oc->getNext()) == NULL)
00182 return false;
00183 if (!((JString*)obj)->equals("Test3") )
00184 return false;
00185 if ( (obj = oc->getNext()) == NULL)
00186 return false;
00187 if (!((JString*)obj)->equals("Test4") )
00188 return false;
00189 if ( (obj = oc->getNext()) == NULL)
00190 return false;
00191 if (!((JString*)obj)->equals("Test5") )
00192 return false;
00193 if ( (obj = oc->getNext()) == NULL)
00194 return false;
00195 if (!((JString*)obj)->equals("Test6") )
00196 return false;
00197
00198 ObjectCollection oc2;
00199
00200 oc2 = *oc;
00201 oc2.noDelete();
00202
00203 if ( (obj = oc2.getFirst()) == NULL)
00204 return false;
00205 if (!((JString*)obj)->equals("Test1") )
00206 return false;
00207 if ( (obj = oc2.getNext()) == NULL)
00208 return false;
00209 if (!((JString*)obj)->equals("Test2") )
00210 return false;
00211 if ( (obj = oc2.getNext()) == NULL)
00212 return false;
00213 if (!((JString*)obj)->equals("Test3") )
00214 return false;
00215 if ( (obj = oc2.getNext()) == NULL)
00216 return false;
00217 if (!((JString*)obj)->equals("Test4") )
00218 return false;
00219 if ( (obj = oc2.getNext()) == NULL)
00220 return false;
00221 if (!((JString*)obj)->equals("Test5") )
00222 return false;
00223 if ( (obj = oc2.getNext()) == NULL)
00224 return false;
00225 if (!((JString*)obj)->equals("Test6") )
00226 return false;
00227
00228 oc->removeAll();
00229 oc2.removeAll();
00230
00231 if (oc->getCount() != 0)
00232 return false;
00233 if (oc2.getCount() != 0)
00234 return false;
00235
00236 delete(oc);
00237 return true;
00238 }
00239
00240
00241
00242
00243 }