Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5102 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Aug 22, 2005, 5:26:29 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: class-autocompletion is nice now

Location:
trunk/src
Files:
8 edited

Legend:

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

    r4942 r5102  
    5252  //  delete []this->className;
    5353  if (this->objectName)
    54     delete []this->objectName;}
     54    delete[] this->objectName;}
    5555
    5656/**
     
    8484{
    8585  if (this->objectName)
    86     delete []this->objectName;
     86    delete[] this->objectName;
    8787  if (objectName)
    8888  {
  • trunk/src/lib/lang/base_object.h

    r5039 r5102  
    2727
    2828  void setName (const char* newName);
    29   /** \brief returns the Name of this Object */
     29  /** returns the Name of this Object */
    3030  inline const char* getName ()const { return this->objectName; };
    3131
  • trunk/src/lib/lang/class_list.cc

    r4874 r5102  
    109109}
    110110
     111/**
     112 * searches for classID and returns the list of Entities
     113 * @param classID the ID of the class to get the list from
     114 * @return the List accessed by classID, or NULL if not found
     115 */
    111116tList<BaseObject>* ClassList::getList(long classID)
    112117{
     
    119124    {
    120125      if (unlikely(tmpCL->classID == classID))
     126        return tmpCL->objectList;
     127      tmpCL = tmpCL->next;
     128    }
     129  }
     130  return NULL;
     131}
     132
     133/**
     134 * searches for className and returns the list of Entities
     135 * @param className the name of the class to get the list from
     136 * @return the List accessed by classID, or NULL if not found
     137 */tList<BaseObject>* ClassList::getList(const char* className)
     138{
     139  if(unlikely(ClassList::first == NULL))
     140    return NULL;
     141  else
     142  {
     143    ClassList* tmpCL = ClassList::first;
     144    while (likely(tmpCL != NULL))
     145    {
     146      if (unlikely(!strcmp(tmpCL->className, className)))
    121147        return tmpCL->objectList;
    122148      tmpCL = tmpCL->next;
     
    205231}
    206232
    207 
    208233/**
    209234 * prints out a string of all the types this Object matches
  • trunk/src/lib/lang/class_list.h

    r5039 r5102  
    3939
    4040    static tList<BaseObject>* getList(long classID = CL_NULL);
     41    static tList<BaseObject>* getList(const char* className);
    4142    static BaseObject*        getObject(const char* name, long classID = CL_NULL);
    4243    static bool               exists(const BaseObject* object, long classID = CL_NULL);
  • trunk/src/util/loading/load_param.cc

    r5100 r5102  
    1717
    1818#include "list.h"
    19 #include "array.h"
    2019#include "base_object.h"
    2120
     
    386385 * searches for classes, which beginn with classNameBegin
    387386 * @param classNameBegin the beginning string of a Class
    388  * @return a NEW char-array with ClassNames. The ARRAY should be deleted afterwards,
     387 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
    389388 * !! The strings MUST NOT be deleted !!
    390389 */
    391 Array<char*>* LoadClassDescription::searchClassWithShort(const char* classNameBegin)
     390tList<const char>* LoadClassDescription::searchClassWithShort(const char* classNameBegin)
    392391{
    393392  unsigned int searchLength = strlen(classNameBegin);
    394   Array<char*>* retVal = new Array<char*>;
     393  tList<const char>* retVal = new tList<const char>;
    395394
    396395  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
     
    401400        !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))
    402401    {
    403       retVal->addEntry(enumClassDesc->className);
     402      retVal->add(enumClassDesc->className);
    404403    }
    405404    enumClassDesc = iterator->nextElement();
     
    407406  delete iterator;
    408407
    409   retVal->finalizeArray();
    410408  return retVal;
    411409}
  • trunk/src/util/loading/load_param.h

    r5100 r5102  
    3131// Forward Declaration //
    3232template<class T> class tList;
    33 template<class T> class Array;
    3433
    3534//! macro that makes it even more easy to load a Parameter
     
    312311
    313312  static void printAll(const char* fileName = NULL);
    314   static Array<char*>* searchClassWithShort(const char* classNameBegin);
     313  static tList<const char>* searchClassWithShort(const char* classNameBegin);
    315314//  static const LoadParamDescription* getClass(const char* className);
    316315
  • trunk/src/util/shell.cc

    r5100 r5102  
    2020#include "text_engine.h"
    2121#include "list.h"
    22 #include "array.h"
    2322#include "graphics_engine.h"
    2423#include "event_handler.h"
     
    382381  {
    383382    if (this->pressedKey == event.type)
     383    {
    384384      this->pressedKey = SDLK_FIRST;
    385     this->delayed = 0.0;
     385      this->delayed = 0.0;
     386    }
    386387  }
    387388}
     
    462463  }
    463464
    464   printf("%s\n",commandBegin);
    465    Array<char*>* classArray = LoadClassDescription::searchClassWithShort(commandBegin);
    466    if (classArray->getCount() == 0)
    467    {
    468      delete[] completionLine;
    469      delete classArray;
     465  this->classComplete(commandBegin);
     466
     467   delete[] completionLine;
     468}
     469
     470/**
     471 * autocompletes a className
     472 * @param classBegin the Beginning of a String to autoComplete
     473 * @return true on success, false otherwise
     474 */
     475bool Shell::classComplete(const char* classBegin)
     476{
     477  if (unlikely(classBegin == NULL))
     478    return false;
     479  tList<const char>* classList = LoadClassDescription::searchClassWithShort(classBegin);
     480  if (classList->getSize() == 0)
     481  {
     482    delete classList;
    470483     //PRINTF(0)("no completion found for %s\n", commandBegin);
    471      return false;
    472    }
    473 
    474    for (unsigned int i = 0; i < classArray->getCount(); i++)
    475    {
    476      PRINTF(0)("%s\n", classArray->getEntry(i));
    477    }
    478    if (classArray->getCount() == 1)
    479    {
    480      this->removeCharacters(strlen(commandBegin));
    481      this->addCharacters(classArray->getEntry(0));
    482      this->addCharacter(' ');
    483    }
    484 
    485    delete[] completionLine;
    486    delete classArray;
    487 }
     484    return false;
     485  }
     486
     487  const char* addString = classList->firstElement();
     488  unsigned int addLength = 0;
     489  unsigned int inputLenght = strlen(classBegin);
     490
     491  if (addString != NULL)
     492    addLength = strlen(addString);
     493  tIterator<const char>* charIterator = classList->getIterator();
     494  const char* charElem = charIterator->nextElement();
     495  while (charElem != NULL)
     496  {
     497    PRINTF(0)("%s:: ", charElem);
     498    {
     499      for (unsigned int i = inputLenght; i < addLength; i++)
     500        if (addString[i] != charElem[i])
     501      {
     502        addLength = i;
     503        break;
     504      }
     505    }
     506
     507    charElem = charIterator->nextElement();
     508  }
     509  delete charIterator;
     510
     511  if (addLength >= inputLenght)
     512  {
     513    char* adder = new char[addLength+1];
     514    strncpy(adder, addString, addLength);
     515    adder[addLength] = '\0';
     516    this->removeCharacters(inputLenght);
     517    this->addCharacters(adder);
     518//    this->addCharacters("::");
     519    delete[] adder;
     520  }
     521  delete classList;
     522}
     523
     524bool Shell::objectComplete(const char* objectBegin, ClassID classID)
     525{
     526
     527}
     528
     529bool Shell::functionComplete(const char* functionBegin)
     530{
     531}
     532
     533
    488534
    489535/**
  • trunk/src/util/shell.h

    r5097 r5102  
    6767  private:
    6868    bool autoComplete();
     69    bool classComplete(const char* classBegin);
     70    bool objectComplete(const char* objectBegin, ClassID classID);
     71    bool functionComplete(const char* functionBegin);
    6972
    7073
Note: See TracChangeset for help on using the changeset viewer.