Changeset 7221 in orxonox.OLD for trunk/src/lib/lang
- Timestamp:
- Mar 15, 2006, 3:10:45 PM (19 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/base_object.cc
r7193 r7221 34 34 BaseObject::BaseObject() 35 35 { 36 this->classID = CL_BASE_OBJECT; 36 37 this->className = "BaseObject"; 37 this->classID = CL_BASE_OBJECT; 38 39 this->objectName = NULL; 38 39 this->objectName = ""; 40 40 this->classList = NULL; 41 41 this->xmlElem = NULL; … … 52 52 53 53 // delete []this->className; 54 if (this->objectName)55 delete[] this->objectName;56 54 if (this->xmlElem != NULL) 57 55 delete this->xmlElem; … … 80 78 * @param className the class name 81 79 */ 82 void BaseObject::setClassID(ClassID classID, const char*className)80 void BaseObject::setClassID(ClassID classID, const std::string& className) 83 81 { 84 82 //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID); … … 95 93 * @brief set the name of the Object 96 94 */ 97 void BaseObject::setName (const char* objectName) 98 { 99 if (this->objectName) 100 delete[] this->objectName; 101 if (objectName != NULL) 102 { 103 this->objectName = new char[strlen(objectName)+1]; 104 strcpy(this->objectName, objectName); 105 } 106 else 107 this->objectName = NULL; 95 void BaseObject::setName (const std::string& objectName) 96 { 97 this->objectName = objectName; 108 98 } 109 99 … … 160 150 * @returns true if it is, false otherwise 161 151 */ 162 bool BaseObject::isA (const char*className) const152 bool BaseObject::isA (const std::string& className) const 163 153 { 164 154 ClassID classID = ClassList::StringToID(className); … … 173 163 * @returns true on match, false otherwise. 174 164 */ 175 bool BaseObject::operator==(const char* objectName) 176 { 177 if (likely(this->objectName != NULL && objectName != NULL)) 178 return (strcmp(this->objectName, objectName)) ? false : true; 165 bool BaseObject::operator==(const std::string& objectName) 166 { 167 return (this->objectName == objectName); 179 168 } 180 169 … … 197 186 int BaseObject::writeState( const byte * data, int length, int sender ) 198 187 { 199 SYNCHELP_READ_BEGIN(); 200 201 if ( objectName ) 188 /// FIXME STD 189 190 /* SYNCHELP_READ_BEGIN(); 191 192 if ( !objectName.empty() ) 202 193 { 203 194 delete[] objectName; … … 211 202 } 212 203 213 return SYNCHELP_READ_N; 204 return SYNCHELP_READ_N;*/ 214 205 } 215 206 … … 222 213 int BaseObject::readState( byte * data, int maxLength ) 223 214 { 224 SYNCHELP_WRITE_BEGIN(); 215 ///FIXME STD 216 /* SYNCHELP_WRITE_BEGIN(); 225 217 226 218 //PRINTF(0)("objectname = %s\n", this->objectName); 227 219 SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME ); 228 220 229 return SYNCHELP_WRITE_N; 230 } 221 return SYNCHELP_WRITE_N;*/ 222 } -
trunk/src/lib/lang/base_object.h
r6587 r7221 16 16 #endif 17 17 18 #include <string> 18 19 #include "stdincl.h" 19 20 … … 30 31 31 32 virtual void loadParams(const TiXmlElement* root); 32 void setName (const char*newName);33 void setName (const std::string& newName); 33 34 /** returns the Name of this Object */ 34 inline const char* getName ()const { return this->objectName ; };35 inline const char* getName ()const { return this->objectName.c_str(); }; 35 36 /** @returns the XML-Element with whicht this Object was loaded */ 36 37 inline TiXmlNode* getXmlElem() const { return this->xmlElem; }; 37 38 38 39 /** @returns the className of the corresponding Object */ 39 inline const char* getClassName() const { return this->className ; };40 inline const char* getClassName() const { return this->className.c_str(); }; 40 41 /** @returns the classID of the corresponding Object */ 41 42 inline int getClassID() const { return this->classID; }; … … 43 44 44 45 bool isA (ClassID classID) const; 45 bool isA (const char*className) const;46 bool isA (const std::string& className) const; 46 47 void whatIs() const; 47 48 48 bool operator==(const char*objectName);49 bool operator==(const std::string& objectName); 49 50 /** @param classID comparer for a ClassID @returns true on match, false otherwise */ 50 51 bool operator==(ClassID classID) { return this->isA(classID); }; … … 54 55 55 56 protected: 56 void setClassID(ClassID classID, const char*className);57 void setClassID(ClassID classID, const std::string& className); 57 58 58 59 private: 59 const char*className; //!< the name of the class60 std::string className; //!< the name of the class 60 61 long classID; //!< this is the id from the class_id.h enumeration 61 char*objectName; //!< The name of this object62 std::string objectName; //!< The name of this object 62 63 63 64 ClassList* classList; //!< Pointer to the ClassList this Object is inside of -
trunk/src/lib/lang/class_list.cc
r7199 r7221 37 37 * Creates a new ClassList 38 38 */ 39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const char*className)40 { 41 this->className = className; 39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const std::string& className) 40 : className(className) 41 { 42 42 this->classID = classID; 43 43 this->classIDFull = classIDFull; … … 56 56 57 57 //! a List of all strings of all classes, that have registered so far. 58 std::list< const char*> ClassList::classNames;58 std::list<std::string> ClassList::classNames; 59 59 60 60 /** … … 67 67 * !! Before unsing the ClassList, as it creates the ClassLits 68 68 */ 69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char*className)69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className) 70 70 { 71 71 if (unlikely(classList == NULL)) 72 72 ClassList::classList = new list<ClassList>(); 73 73 74 PRINTF(5)("subscribe a '%s'\n", className );74 PRINTF(5)("subscribe a '%s'\n", className.c_str() ); 75 75 76 76 ClassList* regClass = ClassList::getClassList(classID); … … 113 113 * befor it changes anything. 114 114 */ 115 const std::list< const char*>* ClassList::getClassNames()115 const std::list<std::string>* ClassList::getClassNames() 116 116 { 117 117 if (ClassList::classNames.size() != ClassList::classList->size()) … … 155 155 * @return the List accessed by classID, or NULL if not found 156 156 */ 157 const std::list<BaseObject*>* ClassList::getList(const char*className)157 const std::list<BaseObject*>* ClassList::getList(const std::string& className) 158 158 { 159 159 ClassList* fl; … … 191 191 * @returns the ClassList with className as specifyer, or NULL if not 192 192 */ 193 ClassList* ClassList::getClassList(const char*className)194 { 195 if (className == NULL)193 ClassList* ClassList::getClassList(const std::string& className) 194 { 195 if (className.empty()) 196 196 return NULL; 197 197 std::list<ClassList>::iterator classIT = find (classList->begin(), classList->end(), className); … … 207 207 * @todo: speed this up!! 208 208 */ 209 BaseObject* ClassList::getObject(const char*objectName, ClassID classID)209 BaseObject* ClassList::getObject(const std::string& objectName, ClassID classID) 210 210 { 211 211 if (classID != CL_NULL) … … 216 216 std::list<BaseObject*>::iterator bo; 217 217 for (bo = cl->objectList.begin(); bo != cl->objectList.end(); bo++) 218 if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))218 if ((*bo)->getName() != NULL && objectName == (*bo)->getName()) 219 219 return (*bo); 220 220 } … … 227 227 std::list<BaseObject*>::iterator bo; 228 228 for (bo = (*cl).objectList.begin(); bo != (*cl).objectList.end(); bo++) 229 if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))229 if ((*bo)->getName() != NULL && objectName == (*bo)->getName()) 230 230 return (*bo); 231 231 } … … 276 276 if (object->isA((*cl).classID)) 277 277 { 278 PRINT(0)("=%s::0x%.8X=-", (*cl).className , (*cl).classID);278 PRINT(0)("=%s::0x%.8X=-", (*cl).className.c_str(), (*cl).classID); 279 279 } 280 280 } … … 285 285 * @return a String containing the name of the Class, NULL if the Class was not found 286 286 */ 287 const char* ClassList::IDToString(ClassID classID) 288 { 287 const std::string& ClassList::IDToString(ClassID classID) 288 { 289 static const std::string empty(""); 290 289 291 ClassList* cl = ClassList::getClassList(classID); 290 return (cl != NULL) ? cl->className : NULL;292 return (cl != NULL) ? cl->className : empty; 291 293 } 292 294 … … 296 298 * @return the ClassID. CL_NULL, if the class was not found. 297 299 */ 298 ClassID ClassList::StringToID(const char*className)300 ClassID ClassList::StringToID(const std::string& className) 299 301 { 300 302 ClassList* cl = ClassList::getClassList(className); … … 307 309 * @returns true on match, false otherwise 308 310 */ 309 bool ClassList::operator==(const char* className) 310 { 311 if (likely( className != NULL && this->className != NULL)) 312 return (!strcmp(this->className, className)); 313 else 314 return false; 311 bool ClassList::operator==(const std::string& className) 312 { 313 return (this->className == className); 315 314 } 316 315 … … 342 341 while (pow(10, lenCount) <= (*cl).objectList.size()) 343 342 ++lenCount; 344 for (int i=0; i < 30- strlen((*cl).className) - lenCount; i++)343 for (int i=0; i < 30-(*cl).className.size() - lenCount; i++) 345 344 (niceString[i]) = ' '; 346 niceString[30- strlen((*cl).className) - lenCount] = '\0';347 348 PRINT(0)("| CLASS %s::%s %d\n", (*cl).className , niceString, (*cl).objectList.size());345 niceString[30-(*cl).className.size() - lenCount] = '\0'; 346 347 PRINT(0)("| CLASS %s::%s %d\n", (*cl).className.c_str(), niceString, (*cl).objectList.size()); 349 348 350 349 if (debugLevel >=2 && (*cl).objectList.size() > 0) … … 371 370 * @see ClassList::debug 372 371 */ 373 void ClassList::debugS(const char*className, unsigned int debugLevel)372 void ClassList::debugS(const std::string& className, unsigned int debugLevel) 374 373 { 375 374 ClassList::debug(debugLevel, ClassList::StringToID(className)); -
trunk/src/lib/lang/class_list.h
r7165 r7221 10 10 #include "class_id.h" 11 11 #include <list> 12 #include <string> 12 13 #ifndef NULL 13 14 #define NULL 0 //!< NULL … … 32 33 class ClassList { 33 34 public: 34 ClassList(ClassID classID, unsigned long classIDFull, const char*className);35 ClassList(ClassID classID, unsigned long classIDFull, const std::string& className); 35 36 virtual ~ClassList(); 36 37 37 38 /* MAINTENANCE FUNCTIONS THESE ARE !!ONLY FOR BASEOBJECT !! */ 38 static ClassList* addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char*className);39 static ClassList* addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className); 39 40 static void removeFromClassList(BaseObject* objectPointer); 40 41 … … 42 43 43 44 static const std::list<BaseObject*>* getList(ClassID classID = CL_NULL);// { return (ClassList* fl = ClassList::getClassList(classID) != NULL)? &(fl->objectList) : NULL; }; 44 static const std::list<BaseObject*>* getList(const char*className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL; };45 static const std::list< const char*>* getClassNames();46 static BaseObject* getObject(const char*name, ClassID classID = CL_NULL);45 static const std::list<BaseObject*>* getList(const std::string& className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL; }; 46 static const std::list<std::string>* getClassNames(); 47 static BaseObject* getObject(const std::string& name, ClassID classID = CL_NULL); 47 48 static bool exists(const BaseObject* object, ClassID classID = CL_NULL); 48 49 … … 51 52 static void whatIs(const BaseObject* object); 52 53 53 static const char*IDToString(ClassID classID = CL_NULL);54 static ClassID StringToID(const char*className);54 static const std::string& IDToString(ClassID classID = CL_NULL); 55 static ClassID StringToID(const std::string& className); 55 56 static void debug(unsigned int debugLevel = 0, ClassID classID = CL_NULL); 56 static void debugS(const char* className = NULL, unsigned int debugLevel = 0);57 static void debugS(const std::string& className = "", unsigned int debugLevel = 0); 57 58 58 59 inline bool operator==(ClassID classID) { return (this->classID == classID); }; 59 bool operator==(const char*className);60 bool operator==(const std::string& className); 60 61 inline ClassID getLeafClassID() const { return this->classID; }; 61 62 62 63 private: 63 64 static ClassList* getClassList(ClassID classID); 64 static ClassList* getClassList(const char*className);65 static ClassList* getClassList(const std::string& className); 65 66 66 67 private: 67 ClassID classID; //!< ClassID stored in this ClassList68 unsigned long classIDFull; //!< The Full ClassID of this Class.68 ClassID classID; //!< ClassID stored in this ClassList 69 unsigned long classIDFull; //!< The Full ClassID of this Class. 69 70 70 const char*className; //!< Name of the Class Stored here71 const std::string className; //!< Name of the Class Stored here 71 72 72 std::list<BaseObject*> objectList; //!< A list of Objects belonging to this Class73 std::list<BaseObject*> objectList; //!< A list of Objects belonging to this Class 73 74 74 75 // STATIC MEMBERS 75 static std::list<ClassList>* classList; //!< The first Class in the List76 static std::list< const char*>classNames; //!< a List of all Names of all classes, that have registered so far.76 static std::list<ClassList>* classList; //!< The first Class in the List 77 static std::list<std::string> classNames; //!< a List of all Names of all classes, that have registered so far. 77 78 }; 78 79
Note: See TracChangeset
for help on using the changeset viewer.