Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5226 in orxonox.OLD for trunk/src/util/loading


Ignore:
Timestamp:
Sep 23, 2005, 10:25:52 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: memory-leak-prevention

Location:
trunk/src/util/loading
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/loading/load_param.cc

    r5218 r5226  
    213213 *  A list, that holds all the classes that are loadable (classes not objects!!)
    214214*/
    215 tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>;
     215tList<LoadClassDescription>* LoadClassDescription::classList = NULL;
    216216
    217217/**
     
    228228  strcpy(this->className, className);
    229229
    230   classList->add(this);
     230  if (LoadClassDescription::classList == NULL)
     231    LoadClassDescription::classList = new tList<LoadClassDescription>;
     232
     233  LoadClassDescription::classList->add(this);
    231234
    232235  this->paramList = new tList<LoadParamDescription>;
     
    238241LoadClassDescription::~LoadClassDescription()
    239242{
    240   delete []this->className;
    241 
    242243  tIterator<LoadParamDescription>* iterator = this->paramList->getIterator();
    243244  LoadParamDescription* enumParamDesc = iterator->firstElement();
     
    248249    }
    249250  delete iterator;
    250 }
     251
     252  delete[] this->className;
     253}
     254
     255void LoadClassDescription::deleteAllDescriptions()
     256{
     257  if (LoadClassDescription::classList != NULL)
     258  {
     259    tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
     260    LoadClassDescription* delElem = iterator->firstElement();
     261    while (delElem != NULL)
     262    {
     263      delete delElem;
     264      delElem = iterator->nextElement();
     265    }
     266    delete iterator;
     267    delete LoadClassDescription::classList;
     268  }
     269  LoadClassDescription::classList = NULL;
     270}
     271
    251272
    252273/**
     
    259280LoadClassDescription* LoadClassDescription::addClass(const char* className)
    260281{
    261   tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
    262   LoadClassDescription* enumClassDesc = iterator->firstElement();
    263   while (enumClassDesc)
    264     {
    265       if (!strcmp(enumClassDesc->className, className))
    266         {
    267           delete iterator;
    268           return enumClassDesc;
    269         }
    270       enumClassDesc = iterator->nextElement();
    271     }
    272   delete iterator;
    273 
     282  if (LoadClassDescription::classList != NULL)
     283  {
     284    tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
     285   LoadClassDescription* enumClassDesc = iterator->firstElement();
     286   while (enumClassDesc)
     287     {
     288       if (!strcmp(enumClassDesc->className, className))
     289         {
     290           delete iterator;
     291           return enumClassDesc;
     292         }
     293       enumClassDesc = iterator->nextElement();
     294     }
     295   delete iterator;
     296  }
    274297  return new LoadClassDescription(className);
    275298}
     
    307330  PRINT(3)("===============================================================\n");
    308331  PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");
    309   tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator();
    310   LoadClassDescription* enumClassDesc = classIT->firstElement();
    311   while (enumClassDesc)
    312     {
    313       PRINT(3)("<%s>\n", enumClassDesc->className);
    314       tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator();
    315       LoadParamDescription* enumParamDesc = paramIT->firstElement();
    316       while (enumParamDesc)
    317         {
    318           enumParamDesc->print();
    319           enumParamDesc = paramIT->nextElement();
    320         }
    321       delete paramIT;
    322 
    323       PRINT(3)("</%s>\n\n", enumClassDesc->className);
    324       enumClassDesc = classIT->nextElement();
    325     }
    326   delete classIT;
     332  if (LoadClassDescription::classList != NULL)
     333  {
     334    tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator();
     335    LoadClassDescription* enumClassDesc = classIT->firstElement();
     336    while (enumClassDesc)
     337     {
     338       PRINT(3)("<%s>\n", enumClassDesc->className);
     339       tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator();
     340       LoadParamDescription* enumParamDesc = paramIT->firstElement();
     341       while (enumParamDesc)
     342         {
     343           enumParamDesc->print();
     344           enumParamDesc = paramIT->nextElement();
     345         }
     346       delete paramIT;
     347
     348       PRINT(3)("</%s>\n\n", enumClassDesc->className);
     349       enumClassDesc = classIT->nextElement();
     350     }
     351    delete classIT;
     352  }
     353  else
     354    PRINT(3)("no Classes defined so far\n");
    327355  PRINT(3)("===============================================================\n");
    328356}
  • trunk/src/util/loading/load_param.h

    r5141 r5226  
    254254  LoadParamDescription* addParam(const char* paramName);
    255255
     256  static void deleteAllDescriptions();
     257
    256258  static void printAll(const char* fileName = NULL);
    257259  static tList<const char>* searchClassWithShort(const char* classNameBegin);
Note: See TracChangeset for help on using the changeset viewer.