Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5103 in orxonox.OLD


Ignore:
Timestamp:
Aug 22, 2005, 6:08:15 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: better algorithm to find the ClassName.
Now this is done via the ClassList

Location:
trunk/src
Files:
5 edited

Legend:

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

    r5102 r5103  
    4848{
    4949  delete this->objectList;
     50  if(ClassList::classList != NULL)
     51  {
     52    delete ClassList::classList;
     53    ClassList::classList = NULL;
     54  }
    5055  --ClassList::classCount;
    5156}
     
    5661//! the Count of classes
    5762unsigned int ClassList::classCount = 0;
     63
     64//! a List of all strings of all classes, that have registered so far.
     65tList<const char>* ClassList::classList = NULL;
    5866
    5967/**
     
    107115    tmp = tmp->next;
    108116  }
     117}
     118
     119/**
     120 * grabs the names of all Classes, and injects it into a List of const chars
     121 * @return the generated List
     122 *
     123 * This function first looks, if the List has been changed (by the ListSize)
     124 * befor it changes anything.
     125 */
     126const tList<const char>* ClassList::getClassList()
     127{
     128  if (unlikely(ClassList::classList != NULL && ClassList::classList->getSize() != ClassList::classCount))
     129  {
     130    delete ClassList::classList;
     131    ClassList::classList = NULL;
     132  }
     133  if (unlikely(ClassList::classList == NULL))
     134    ClassList::classList = new tList<const char>;
     135
     136  if(likely(ClassList::first != NULL))
     137  {
     138    ClassList* tmpCL = ClassList::first;
     139    while (likely(tmpCL != NULL))
     140    {
     141      ClassList::classList->add(tmpCL->className);
     142      tmpCL = tmpCL->next;
     143    }
     144  }
     145  return ClassList::classList;
    109146}
    110147
  • trunk/src/lib/lang/class_list.h

    r5102 r5103  
    3535
    3636    // STATIC FUNCTIONS
    37     static void               addToClassList(BaseObject* objectPointer, const long& classID, const char* className);
    38     static void               removeFromClassList(BaseObject* objectPointer);
     37    static void                     addToClassList(BaseObject* objectPointer, const long& classID, const char* className);
     38    static void                     removeFromClassList(BaseObject* objectPointer);
    3939
    40     static tList<BaseObject>* getList(long classID = CL_NULL);
    41     static tList<BaseObject>* getList(const char* className);
    42     static BaseObject*        getObject(const char* name, long classID = CL_NULL);
    43     static bool               exists(const BaseObject* object, long classID = CL_NULL);
     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);
    4445
    45     static void               whatIs(const BaseObject* object);
    46     static void debug(unsigned int debugLevel = 0, long classID = CL_NULL);
     46    static void                     whatIs(const BaseObject* object);
     47    static void                     debug(unsigned int debugLevel = 0, long classID = CL_NULL);
    4748
    4849  private:
    49     tList<BaseObject>*       objectList;             //!< A list of Objects belonging to this Class
     50    tList<BaseObject>*              objectList;             //!< A list of Objects belonging to this Class
    5051
    51     long                     classID;                //!< ClassID stored in this ClassList \see ClassID
    52     const char*              className;              //!< Name of the Class Stored here
     52    long                            classID;                //!< ClassID stored in this ClassList \see ClassID
     53    const char*                     className;              //!< Name of the Class Stored here
    5354
    54     ClassList*               next;                   //!< Pointer to the next class in the List
     55    ClassList*                      next;                   //!< Pointer to the next class in the List
    5556
    5657    // STATIC MEMBERS
    57     static ClassList*        first;                  //!< The first Class in the List
    58     static unsigned int      classCount;             //!< The Count of classes that have been registered (should match the lower description)
     58    static ClassList*               first;                  //!< The first Class in the List
     59    static tList<const char>*       classList;              //!< a List of all Names of all classes, that have registered so far.
     60    static unsigned int             classCount;             //!< The Count of classes that have been registered (should match the lower description)
    5961};
    6062
  • trunk/src/lib/util/list.h

    r5076 r5103  
    135135  void removeLast();
    136136  void flush();
    137   T* firstElement();
    138   T* lastElement();
    139   bool isEmpty();
    140   unsigned int getSize();
     137  T* firstElement() const;
     138  T* lastElement() const;
     139  bool isEmpty() const;
     140  unsigned int getSize() const;
    141141  bool inList(T* entity);
    142   tIterator<T>* getIterator();
     142  tIterator<T>* getIterator() const;
    143143  T* nextElement(T* toEntity);
    144144  T* toArray();
     
    303303*/
    304304template<class T>
    305 inline T* tList<T>::firstElement()
     305inline T* tList<T>::firstElement() const
    306306{
    307307  return this->first->curr;
     
    314314*/
    315315template<class T>
    316 inline T* tList<T>::lastElement()
     316inline T* tList<T>::lastElement() const
    317317{
    318318  return this->last->curr;
     
    325325*/
    326326template<class T>
    327 inline bool tList<T>::isEmpty()
     327inline bool tList<T>::isEmpty() const
    328328{
    329329  return (this->size==0)?true:false;
     
    359359*/
    360360template<class T>
    361 inline unsigned int tList<T>::getSize()
     361inline unsigned int tList<T>::getSize() const
    362362{
    363363  return this->size;
     
    372372*/
    373373template<class T>
    374 inline tIterator<T>* tList<T>::getIterator()
     374inline tIterator<T>* tList<T>::getIterator() const
    375375{
    376376  tIterator<T>* iterator = new tIterator<T>(this->first);
  • trunk/src/util/shell.cc

    r5102 r5103  
    2424
    2525#include "load_param.h"
     26#include "class_list.h"
    2627#include "debug.h"
    2728#include <stdarg.h>
     
    5960  this->inputLineText->setParent2D(this);
    6061
     62  this->completionList = NULL;
    6163
    6264  EventHandler* evh = EventHandler::getInstance();
     
    9193  }
    9294  delete charIterator;
     95
     96//  if (this->completionList != NULL)
     97    //delete this->completionList;
    9398
    9499  Shell::singletonRef = NULL;
     
    465470  this->classComplete(commandBegin);
    466471
    467    delete[] completionLine;
     472  delete[] completionLine;
    468473}
    469474
     
    477482  if (unlikely(classBegin == NULL))
    478483    return false;
    479   tList<const char>* classList = LoadClassDescription::searchClassWithShort(classBegin);
     484  const tList<const char>* classList = this->searchClassWithShort(classBegin);
    480485  if (classList->getSize() == 0)
    481486  {
    482     delete classList;
    483487     //PRINTF(0)("no completion found for %s\n", commandBegin);
    484488    return false;
     
    519523    delete[] adder;
    520524  }
    521   delete classList;
    522525}
    523526
     
    529532bool Shell::functionComplete(const char* functionBegin)
    530533{
     534}
     535
     536
     537/**
     538 * searches for classes, which beginn with classNameBegin
     539 * @param classNameBegin the beginning string of a Class
     540 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     541 * !! The strings MUST NOT be deleted !!
     542 */
     543const tList<const char>* Shell::searchClassWithShort(const char* classNameBegin)
     544{
     545  unsigned int searchLength = strlen(classNameBegin);
     546  if (this->completionList != NULL)
     547    delete this->completionList;
     548  this->completionList = new tList<const char>;
     549
     550//  tList<const char>* classList = ClassList::getClassList();
     551
     552  tIterator<const char>* iterator = ClassList::getClassList()->getIterator();
     553  const char* enumString = iterator->nextElement();
     554  while (enumString != NULL)
     555  {
     556    if (strlen(enumString)>searchLength+1 &&
     557        !strncasecmp(enumString, classNameBegin, searchLength))
     558    {
     559      this->completionList->add(enumString);
     560    }
     561    enumString = iterator->nextElement();
     562  }
     563  delete iterator;
     564
     565  return this->completionList;
    531566}
    532567
     
    540575  if (this->pressedKey != SDLK_FIRST)
    541576    printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
    542 
    543 }
     577}
  • trunk/src/util/shell.h

    r5102 r5103  
    7272
    7373
     74    const tList<const char>* searchClassWithShort(const char* classNameBegin);
     75
     76
    7477  private:
    7578    Shell();
     
    9396
    9497    char                   bufferArray[10000];     //!< a BUFFER for fast writing
     98
     99    // completion
     100    tList<const char>*    completionList;          //!< A list of completions, that are io.
    95101};
    96102
Note: See TracChangeset for help on using the changeset viewer.