Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4932 in orxonox.OLD for orxonox/trunk/src/util/object_manager.cc


Ignore:
Timestamp:
Jul 22, 2005, 12:08:51 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: factory optimisations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/object_manager.cc

    r4931 r4932  
    2424
    2525
     26
     27
     28/**
     29 *  constructor, sets everything to zero and define factoryName
     30 */
     31FastFactory::FastFactory (const char* fastFactoryName, ClassID classID)
     32{
     33  this->setClassID(CL_FAST_FACTORY, "FastFactory");
     34  this->setName(fastFactoryName);
     35
     36  this->storedClassID = classID;
     37  this->next = NULL;
     38
     39  FastFactory::registerFastFactory(this);
     40}
     41
     42/** a reference to the First FastFactory */
     43FastFactory* FastFactory::first = NULL;
     44
     45/**
     46 *  destructor
     47 *  clear the Q
     48 */
     49FastFactory::~FastFactory ()
     50{
     51  if (this == first)
     52    this->first = NULL;
     53
     54  if (this->next)
     55    delete this->next;
     56}
     57
     58/**
     59 * add a FastFactory to the FastFactory Queue
     60 * @param factory a FastFactory to be registered
     61 */
     62void FastFactory::registerFastFactory( FastFactory* factory)
     63{
     64  PRINTF(3)("Registered FastFactory for '%s'\n", factory->getName());
     65
     66  if( FastFactory::first == NULL)
     67    FastFactory::first = factory;
     68  else
     69  {
     70    FastFactory* tmpFac = FastFactory::first;
     71    while( tmpFac->next != NULL)
     72    {
     73      tmpFac = tmpFac->next;
     74    }
     75    tmpFac->setNext(factory);
     76  }
     77}
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
    2691/**
    2792 *  standard constructor
     
    3297  this->setName("ObjectManager");
    3398
    34   this->managedObjectList = new tList<BaseObject>*[CL_NUMBER];
    35   for(int i = 0; i < CL_NUMBER; ++i)
    36     {
    37       this->managedObjectList[i] = NULL;
    38     }
    3999}
    40100
     
    54114
    55115/**
    56  *  adds an element to the list of dead objects
    57  * @param index: The type of object to add
    58  * @param object: pointer to the object at hand
    59 */
    60 void ObjectManager::addToDeadList(int index, BaseObject* object)
    61 {
    62   if( likely(this->managedObjectList[index] != NULL))
    63     this->managedObjectList[index]->add(object);
    64   else
    65     PRINTF(0)(" Critical: unable to add object to the list nr. %i: no list initialized - ignoring\n", index);
    66 }
    67 
    68 /**
    69  *  resurects an object
    70  * @param index: the type of resource to load
    71  * @param number: how many of them
    72 
    73    @todo if it is unable to get an object from the deadList, it should create it
    74 */
    75 BaseObject* ObjectManager::getFromDeadList(int index, int number)
    76 {
    77   if( likely(this->managedObjectList[index] != NULL))
    78     {
    79       BaseObject* obj = this->managedObjectList[index]->firstElement();
    80       this->managedObjectList[index]->remove(obj);
    81       if( unlikely(obj == NULL))
    82         {
    83           PRINTF(0)("Critical: there was no object anymore in the dead list! This could result in Segfaults\n");
    84         }
    85       return obj;
    86     }
    87   else
    88     PRINTF(0)(" Critical: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index);
    89   return NULL;
    90 }
    91 
    92 /**
    93116 *  outputs some simple debug information about the ObjectManage
    94117*/
     
    96119{
    97120  PRINT(0)("\n==========================| ObjectManager::debug() |===\n");
    98   PRINT(0)("=  Number of registerable classes: %i\n", CL_NUMBER );
    99   PRINT(0)("=  Currently cached objects: \n");
    100   for(int i = 0; i < CL_NUMBER; ++i)
    101     {
     121/* PRINT(0)("=  Number of registerable classes: %i\n", CL_NUMBER );
     122 PRINT(0)("=  Currently cached objects: \n");
     123 for(int i = 0; i < CL_NUMBER; ++i)
     124   {
    102125      if( this->managedObjectList[i] != NULL)
    103126        PRINT(0)("=   o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize());
    104127      else
    105128        PRINT(0)("=   o Class Nr. %i has cached 0 object(s)\n", i);
    106     }
     129    }*/
    107130  PRINT(0)("=======================================================\n");
    108131}
    109132
    110133
    111 
    112 /**
    113  *  constructor
    114 
    115    set everything to zero and define factoryName
    116  */
    117 FastObject::FastObject (const char* fastObjectName, ClassID classID)
    118 {
    119   this->setClassID(CL_FACTORY, "FastObject");
    120   this->setName(fastObjectName);
    121 
    122   this->storedClassID = classID;
    123   this->next = NULL;
    124 
    125   FastObject::registerFastObject(this);
    126 }
    127 
    128 /** a reference to the First FastObject */
    129 FastObject* FastObject::first = NULL;
    130 
    131 /**
    132  *  destructor
    133 
    134    clear the Q
    135  */
    136 FastObject::~FastObject ()
    137 {
    138   //  printf("%s\n", this->factoryName);
    139   //  FastObject* tmpDel = this->next;
    140   //  this->next = NULL;
    141   if (this->next)
    142     delete this->next;
    143 }
    144 
    145 /**
    146  *  add a FastObject to the FastObject Queue
    147  * @param factory a FastObject to be registered
    148  */
    149 void FastObject::registerFastObject( FastObject* factory)
    150 {
    151   PRINTF(4)("Registered FastObject for '%s'\n", factory->getName());
    152 
    153   if( FastObject::first == NULL)
    154     FastObject::first = factory;
    155   else
    156   {
    157     FastObject* tmpFac = FastObject::first;
    158     while( tmpFac->next != NULL)
    159     {
    160       tmpFac = tmpFac->next;
    161     }
    162     tmpFac->setNext(factory);
    163   }
    164 }
Note: See TracChangeset for help on using the changeset viewer.