Changeset 5779 in orxonox.OLD for trunk/src/lib/lang
- Timestamp:
- Nov 26, 2005, 2:20:58 PM (19 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/class_list.cc
r5770 r5779 40 40 this->className = className; 41 41 this->classID = classID; 42 this->objectList = new tList<BaseObject>;43 42 44 43 ++ClassList::classCount; … … 50 49 ClassList::~ClassList () 51 50 { 52 delete this->objectList;53 if(ClassList::classList != NULL)54 {55 delete ClassList::classList;56 ClassList::classList = NULL;57 }51 /// FIXME 52 // if(ClassList::classList != NULL) 53 // { 54 // delete ClassList::classList; 55 // ClassList::classList = NULL; 56 // } 58 57 --ClassList::classCount; 59 58 } … … 66 65 67 66 //! a List of all strings of all classes, that have registered so far. 68 tList<const char>* ClassList::classList = NULL;67 std::list<const char*> ClassList::classList; 69 68 70 69 /** … … 100 99 } 101 100 } 102 regClass->objectList ->add(objectPointer);101 regClass->objectList.push_back(objectPointer); 103 102 } 104 103 … … 114 113 if (objectPointer->isA(tmp->classID)) 115 114 { 116 tmp->objectList ->remove(objectPointer);115 tmp->objectList.remove(objectPointer); 117 116 } 118 117 tmp = tmp->next; … … 127 126 * befor it changes anything. 128 127 */ 129 const tList<const char>* ClassList::getClassList() 130 { 131 if (unlikely(ClassList::classList != NULL && ClassList::classList->getSize() != ClassList::classCount)) 132 { 133 delete ClassList::classList; 134 ClassList::classList = NULL; 135 } 136 if (unlikely(ClassList::classList == NULL)) 137 ClassList::classList = new tList<const char>; 128 const std::list<const char*>* ClassList::getClassList() 129 { 130 if (ClassList::classList.size() != ClassList::classCount) 131 ClassList::classList.erase(ClassList::classList.begin(), ClassList::classList.end()); 138 132 139 133 if(likely(ClassList::first != NULL)) … … 142 136 while (likely(tmpCL != NULL)) 143 137 { 144 ClassList::classList ->add(tmpCL->className);145 tmpCL = tmpCL->next; 146 } 147 } 148 return ClassList::classList;138 ClassList::classList.push_back(tmpCL->className); 139 tmpCL = tmpCL->next; 140 } 141 } 142 return &ClassList::classList; 149 143 } 150 144 … … 154 148 * @return the List accessed by classID, or NULL if not found 155 149 */ 156 tList<BaseObject>* ClassList::getList(long classID)150 std::list<BaseObject*>* ClassList::getList(long classID) 157 151 { 158 152 if(unlikely(ClassList::first == NULL)) … … 164 158 { 165 159 if (unlikely(tmpCL->classID == classID)) 166 return tmpCL->objectList;160 return &tmpCL->objectList; 167 161 tmpCL = tmpCL->next; 168 162 } … … 175 169 * @param className the name of the class to get the list from 176 170 * @return the List accessed by classID, or NULL if not found 177 */tList<BaseObject>* ClassList::getList(const char* className) 171 */ 172 std::list<BaseObject*>* ClassList::getList(const char* className) 178 173 { 179 174 if(unlikely(ClassList::first == NULL)) … … 185 180 { 186 181 if (unlikely(!strcmp(tmpCL->className, className))) 187 return tmpCL->objectList;182 return &tmpCL->objectList; 188 183 tmpCL = tmpCL->next; 189 184 } … … 210 205 if (tmp->classID == classID || classID == CL_NULL) 211 206 { 212 tIterator<BaseObject>* iterator = tmp->objectList->getIterator(); 213 BaseObject* enumBO = iterator->firstElement(); 214 const char* tmpName; 215 while (enumBO != NULL) 216 { 217 tmpName = enumBO->getName(); 218 if (tmpName && !strcmp(tmpName, name)) 219 { 220 delete iterator; 221 return enumBO; 222 } 223 enumBO = iterator->nextElement(); 224 } 225 delete iterator; 207 list<BaseObject*>::iterator bo; 208 for (bo = tmp->objectList.begin(); bo != tmp->objectList.end(); bo++) 209 if ((*bo)->getName() && !strcmp((*bo)->getName(), name)) 210 return (*bo); 226 211 break; 227 212 } … … 251 236 if (tmp->classID == classID || classID == CL_NULL) 252 237 { 253 tIterator<BaseObject>* iterator = tmp->objectList->getIterator(); 254 const BaseObject* enumBO = iterator->firstElement(); 255 while (enumBO != NULL) 256 { 257 if (enumBO == object) 258 { 259 delete iterator; 238 list<BaseObject*>::iterator bo; 239 for (bo = tmp->objectList.begin(); bo != tmp->objectList.end(); bo++) 240 if ((*bo) == object) 260 241 return true; 261 }262 enumBO = iterator->nextElement();263 }264 242 if (likely(tmp->classID == classID)) 265 {266 delete iterator;267 243 break; 268 }269 244 } 270 245 tmp = tmp->next; … … 354 329 while (likely(tmp != NULL)) 355 330 { 356 if ((debugLevel >= 1 || tmp->objectList ->getSize() > 0 ) &&331 if ((debugLevel >= 1 || tmp->objectList.size() > 0 ) && 357 332 (classID == CL_NULL || unlikely (classID == tmp->classID))) 358 333 { 359 334 lenCount = 1; 360 while (pow(10, lenCount) <= tmp->objectList->getSize())335 while (pow(10, lenCount) <= tmp->objectList.size()) 361 336 ++lenCount; 362 337 for (int i=0; i < 30-strlen(tmp->className) - lenCount; i++) … … 364 339 niceString[30-strlen(tmp->className) - lenCount] = '\0'; 365 340 366 PRINT(0)("| CLASS %s:%s %d\n", tmp->className, niceString, tmp->objectList ->getSize());367 368 if (debugLevel >=2 && tmp->objectList ->getSize() > 0)341 PRINT(0)("| CLASS %s:%s %d\n", tmp->className, niceString, tmp->objectList.size()); 342 343 if (debugLevel >=2 && tmp->objectList.size() > 0) 369 344 { 370 345 PRINT(0)("| Listing Instances:\n"); 371 tIterator<BaseObject>* iterator = tmp->objectList->getIterator(); 372 BaseObject* enumBO = iterator->firstElement(); 373 while (enumBO) 346 list<BaseObject*>::const_iterator bo; 347 for (bo = tmp->objectList.begin(); bo != tmp->objectList.end(); bo++) 374 348 { 375 PRINT(0)("| (class %s): NAME(%s)->%p ", enumBO->getClassName(), enumBO->getName(), enumBO);349 PRINT(0)("| (class %s): NAME(%s)->%p ", (*bo)->getClassName(), (*bo)->getName(), (*bo)); 376 350 if (debugLevel == 3) 377 ClassList::whatIs( enumBO);351 ClassList::whatIs(*bo); 378 352 PRINT(0)("\n"); 379 enumBO = iterator->nextElement();380 353 } 381 delete iterator;382 354 } 383 355 } -
trunk/src/lib/lang/class_list.h
r5405 r5779 9 9 10 10 #include "class_id.h" 11 #include <list> 11 12 12 13 // FORWARD DECLARATION 13 14 class BaseObject; 14 template<class T> class tList;15 16 15 17 16 //! A class that handles Pointers to Objects of all type. … … 35 34 36 35 // STATIC FUNCTIONS 37 static void addToClassList(BaseObject* objectPointer, const long& classID, const char* className);38 static void removeFromClassList(BaseObject* objectPointer);36 static void addToClassList(BaseObject* objectPointer, const long& classID, const char* className); 37 static void removeFromClassList(BaseObject* objectPointer); 39 38 40 static tList<BaseObject>* getList(long classID = CL_NULL);41 static tList<BaseObject>* getList(const char* className);42 static const tList<const char>* getClassList();43 static BaseObject* getObject(const char* name, long classID = CL_NULL);44 static bool exists(const BaseObject* object, long classID = CL_NULL);39 static std::list<BaseObject*>* getList(long classID = CL_NULL); 40 static std::list<BaseObject*>* getList(const char* className); 41 static const std::list<const char*>* getClassList(); 42 static BaseObject* getObject(const char* name, long classID = CL_NULL); 43 static bool exists(const BaseObject* object, long classID = CL_NULL); 45 44 46 static void whatIs(const BaseObject* object);45 static void whatIs(const BaseObject* object); 47 46 48 static const char* IDToString(long classID = CL_NULL); 49 static long StringToID(const char* className); 50 static void debug(unsigned int debugLevel = 0, long classID = CL_NULL); 51 static void debugS(const char* className = 0x0, unsigned int debugLevel = 0); 47 static const char* IDToString(long classID = CL_NULL); 48 static long StringToID(const char* className); 49 static void debug(unsigned int debugLevel = 0, long classID = CL_NULL); 50 static void debugS(const char* className = 0x0, unsigned int debugLevel = 0); 51 52 52 53 53 54 54 private: 55 tList<BaseObject>*objectList; //!< A list of Objects belonging to this Class55 std::list<BaseObject*> objectList; //!< A list of Objects belonging to this Class 56 56 57 57 long classID; //!< ClassID stored in this ClassList \see ClassID … … 62 62 // STATIC MEMBERS 63 63 static ClassList* first; //!< The first Class in the List 64 static tList<const char>*classList; //!< a List of all Names of all classes, that have registered so far.64 static std::list<const char*> classList; //!< a List of all Names of all classes, that have registered so far. 65 65 static unsigned int classCount; //!< The Count of classes that have been registered (should match the lower description) 66 66 };
Note: See TracChangeset
for help on using the changeset viewer.