Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7221 in orxonox.OLD for trunk/src/lib/lang


Ignore:
Timestamp:
Mar 15, 2006, 3:10:45 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

Location:
trunk/src/lib/lang
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/base_object.cc

    r7193 r7221  
    3434BaseObject::BaseObject()
    3535{
     36  this->classID = CL_BASE_OBJECT;
    3637  this->className = "BaseObject";
    37   this->classID = CL_BASE_OBJECT;
    38 
    39   this->objectName = NULL;
     38
     39  this->objectName = "";
    4040  this->classList = NULL;
    4141  this->xmlElem = NULL;
     
    5252
    5353  //  delete []this->className;
    54   if (this->objectName)
    55     delete[] this->objectName;
    5654  if (this->xmlElem != NULL)
    5755    delete this->xmlElem;
     
    8078 * @param className the class name
    8179*/
    82 void BaseObject::setClassID(ClassID classID, const char* className)
     80void BaseObject::setClassID(ClassID classID, const std::string& className)
    8381{
    8482  //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
     
    9593 * @brief set the name of the Object
    9694 */
    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;
     95void BaseObject::setName (const std::string& objectName)
     96{
     97  this->objectName = objectName;
    10898}
    10999
     
    160150 * @returns true if it is, false otherwise
    161151 */
    162 bool BaseObject::isA (const char* className) const
     152bool BaseObject::isA (const std::string& className) const
    163153{
    164154  ClassID classID = ClassList::StringToID(className);
     
    173163 * @returns true on match, false otherwise.
    174164 */
    175 bool BaseObject::operator==(const char* objectName)
    176 {
    177   if (likely(this->objectName != NULL && objectName != NULL))
    178     return (strcmp(this->objectName, objectName)) ? false : true;
     165bool BaseObject::operator==(const std::string& objectName)
     166{
     167  return (this->objectName == objectName);
    179168}
    180169
     
    197186int BaseObject::writeState( const byte * data, int length, int sender )
    198187{
    199   SYNCHELP_READ_BEGIN();
    200 
    201   if ( objectName )
     188  /// FIXME STD
     189
     190  /*  SYNCHELP_READ_BEGIN();
     191
     192  if ( !objectName.empty() )
    202193  {
    203194    delete[] objectName;
     
    211202  }
    212203
    213   return SYNCHELP_READ_N;
     204  return SYNCHELP_READ_N;*/
    214205}
    215206
     
    222213int BaseObject::readState( byte * data, int maxLength )
    223214{
    224   SYNCHELP_WRITE_BEGIN();
     215///FIXME STD
     216  /*  SYNCHELP_WRITE_BEGIN();
    225217
    226218  //PRINTF(0)("objectname = %s\n", this->objectName);
    227219  SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME );
    228220
    229   return SYNCHELP_WRITE_N;
    230 }
     221  return SYNCHELP_WRITE_N;*/
     222}
  • trunk/src/lib/lang/base_object.h

    r6587 r7221  
    1616#endif
    1717
     18#include <string>
    1819#include "stdincl.h"
    1920
     
    3031
    3132  virtual void loadParams(const TiXmlElement* root);
    32   void setName (const char* newName);
     33  void setName (const std::string& newName);
    3334  /** 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(); };
    3536  /** @returns the XML-Element with whicht this Object was loaded */
    3637  inline TiXmlNode* getXmlElem() const { return this->xmlElem; };
    3738
    3839  /** @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(); };
    4041  /** @returns the classID of the corresponding Object */
    4142  inline int getClassID() const { return this->classID; };
     
    4344
    4445  bool isA (ClassID classID) const;
    45   bool isA (const char* className) const;
     46  bool isA (const std::string& className) const;
    4647  void whatIs() const;
    4748
    48   bool operator==(const char* objectName);
     49  bool operator==(const std::string& objectName);
    4950  /** @param classID comparer for a ClassID @returns true on match, false otherwise */
    5051  bool operator==(ClassID classID) { return this->isA(classID); };
     
    5455
    5556 protected:
    56   void setClassID(ClassID classID, const char* className);
     57   void setClassID(ClassID classID, const std::string& className);
    5758
    5859 private:
    59     const char*        className;        //!< the name of the class
     60    std::string        className;        //!< the name of the class
    6061    long               classID;          //!< this is the id from the class_id.h enumeration
    61     char*              objectName;       //!< The name of this object
     62    std::string        objectName;       //!< The name of this object
    6263
    6364    ClassList*         classList;        //!< Pointer to the ClassList this Object is inside of
  • trunk/src/lib/lang/class_list.cc

    r7199 r7221  
    3737 *  Creates a new ClassList
    3838*/
    39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const char* className)
    40 {
    41   this->className = className;
     39ClassList::ClassList(ClassID classID, unsigned long classIDFull, const std::string& className)
     40  : className(className)
     41{
    4242  this->classID = classID;
    4343  this->classIDFull = classIDFull;
     
    5656
    5757//! a List of all strings of all classes, that have registered so far.
    58 std::list<const char*> ClassList::classNames;
     58std::list<std::string> ClassList::classNames;
    5959
    6060/**
     
    6767 * !! Before unsing the ClassList, as it creates the ClassLits
    6868 */
    69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className)
     69ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className)
    7070{
    7171  if (unlikely(classList == NULL))
    7272    ClassList::classList = new list<ClassList>();
    7373
    74   PRINTF(5)("subscribe a '%s'\n", className );
     74  PRINTF(5)("subscribe a '%s'\n", className.c_str() );
    7575
    7676  ClassList* regClass = ClassList::getClassList(classID);
     
    113113 * befor it changes anything.
    114114 */
    115 const std::list<const char*>* ClassList::getClassNames()
     115const std::list<std::string>* ClassList::getClassNames()
    116116{
    117117  if (ClassList::classNames.size() != ClassList::classList->size())
     
    155155 * @return the List accessed by classID, or NULL if not found
    156156 */
    157 const std::list<BaseObject*>* ClassList::getList(const char* className)
     157const std::list<BaseObject*>* ClassList::getList(const std::string& className)
    158158{
    159159  ClassList* fl;
     
    191191 * @returns the ClassList with className as specifyer, or NULL if not
    192192 */
    193 ClassList* ClassList::getClassList(const char* className)
    194 {
    195   if (className == NULL)
     193ClassList* ClassList::getClassList(const std::string& className)
     194{
     195  if (className.empty())
    196196    return NULL;
    197197  std::list<ClassList>::iterator classIT = find (classList->begin(), classList->end(), className);
     
    207207 * @todo: speed this up!!
    208208 */
    209 BaseObject* ClassList::getObject(const char* objectName, ClassID classID)
     209BaseObject* ClassList::getObject(const std::string& objectName, ClassID classID)
    210210{
    211211  if (classID != CL_NULL)
     
    216216      std::list<BaseObject*>::iterator bo;
    217217      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())
    219219          return (*bo);
    220220    }
     
    227227      std::list<BaseObject*>::iterator bo;
    228228      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())
    230230          return (*bo);
    231231    }
     
    276276    if (object->isA((*cl).classID))
    277277  {
    278     PRINT(0)("=%s::0x%.8X=-", (*cl).className, (*cl).classID);
     278    PRINT(0)("=%s::0x%.8X=-", (*cl).className.c_str(), (*cl).classID);
    279279  }
    280280}
     
    285285 * @return a String containing the name of the Class, NULL if the Class was not found
    286286 */
    287 const char* ClassList::IDToString(ClassID classID)
    288 {
     287const std::string& ClassList::IDToString(ClassID classID)
     288{
     289  static const std::string empty("");
     290
    289291  ClassList* cl = ClassList::getClassList(classID);
    290   return (cl != NULL) ? cl->className : NULL;
     292  return (cl != NULL) ? cl->className : empty;
    291293}
    292294
     
    296298 * @return the ClassID. CL_NULL, if the class was not found.
    297299 */
    298 ClassID ClassList::StringToID(const char* className)
     300ClassID ClassList::StringToID(const std::string& className)
    299301{
    300302  ClassList* cl = ClassList::getClassList(className);
     
    307309 * @returns true on match, false otherwise
    308310 */
    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;
     311bool ClassList::operator==(const std::string& className)
     312{
     313  return (this->className == className);
    315314}
    316315
     
    342341      while (pow(10, lenCount) <= (*cl).objectList.size())
    343342        ++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++)
    345344        (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());
    349348
    350349      if (debugLevel >=2 && (*cl).objectList.size() > 0)
     
    371370 * @see ClassList::debug
    372371 */
    373 void ClassList::debugS(const char* className, unsigned int debugLevel)
     372void ClassList::debugS(const std::string& className, unsigned int debugLevel)
    374373{
    375374  ClassList::debug(debugLevel, ClassList::StringToID(className));
  • trunk/src/lib/lang/class_list.h

    r7165 r7221  
    1010#include "class_id.h"
    1111#include <list>
     12#include <string>
    1213#ifndef NULL
    1314#define NULL     0    //!< NULL
     
    3233class ClassList {
    3334  public:
    34     ClassList(ClassID classID, unsigned long classIDFull, const char* className);
     35    ClassList(ClassID classID, unsigned long classIDFull, const std::string& className);
    3536    virtual ~ClassList();
    3637
    3738    /* 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);
    3940    static void                           removeFromClassList(BaseObject* objectPointer);
    4041
     
    4243
    4344    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);
    4748    static bool                           exists(const BaseObject* object, ClassID classID = CL_NULL);
    4849
     
    5152    static void                           whatIs(const BaseObject* object);
    5253
    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);
    5556    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);
    5758
    5859    inline bool                           operator==(ClassID classID) { return (this->classID == classID); };
    59     bool                                  operator==(const char* className);
     60    bool                                  operator==(const std::string& className);
    6061    inline ClassID                        getLeafClassID() const { return this->classID; };
    6162
    6263  private:
    6364    static ClassList*                     getClassList(ClassID classID);
    64     static ClassList*                     getClassList(const char* className);
     65    static ClassList*                     getClassList(const std::string& className);
    6566
    6667  private:
    67     ClassID                         classID;                //!< ClassID stored in this ClassList
    68     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.
    6970
    70     const char*                     className;              //!< Name of the Class Stored here
     71    const std::string                     className;              //!< Name of the Class Stored here
    7172
    72     std::list<BaseObject*>          objectList;             //!< A list of Objects belonging to this Class
     73    std::list<BaseObject*>                objectList;             //!< A list of Objects belonging to this Class
    7374
    7475    // STATIC MEMBERS
    75     static std::list<ClassList>*    classList;              //!< The first Class in the List
    76     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.
    7778};
    7879
Note: See TracChangeset for help on using the changeset viewer.