Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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.h

    r4931 r4932  
    2626class GarbageCollector;
    2727
     28
     29/**
     30 * Creates a FastFactory to a Loadable FastFactory.
     31 */
     32#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \
     33    tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = new tFastFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
     34
     35//! A struct, that holds Lists of Objects of a certain type.
     36typedef struct FastObjectMember
     37{
     38  BaseObject*          objectPointer;
     39
     40  FastObjectMember*    next;
     41};
     42
     43//! The FastFactory is a fast loadable object creator, and Dynamic List of dead object handler.
     44class FastFactory : public BaseObject {
     45
     46  public:
     47    FastFactory (const char* fastFactoryName, ClassID classID);
     48    virtual ~FastFactory ();
     49
     50
     51    BaseObject* resurect(ClassID classID);
     52    void kill(ClassID classID, BaseObject* object);
     53
     54    virtual BaseObject* fabricate(ClassID classID) = NULL;
     55
     56    static void registerFastFactory(FastFactory* fastFactory);
     57    static void registerFastFactory(const char* fastFactoryName, ClassID classID);
     58
     59    /** @returns the first FastFactory */
     60    static FastFactory* getFirst() { return FastFactory::first; };
     61
     62  protected:
     63    /** sets the Next factory in the list @param nextFactory the next factory */
     64    inline void setNext( FastFactory* nextFastFactory) { this->next = nextFastFactory; };
     65    /** @returns the next FastFactory */
     66    FastFactory* getNext() const { return this->next; };
     67
     68  protected:
     69    ClassID               storedClassID;        //!< The classID of the specified class.
     70
     71  private:
     72    static FastFactory*   first;                //!< A pointer to the first FastFactory.
     73
     74    FastFactory*          next;                 //!< pointer to the next FastFactory.
     75};
     76
     77/**
     78 *  a FastFactory that is able to load any kind of Object from a ClassID
     79 * (this is a Functor)
     80 */
     81template<class T> class tFastFactory : public FastFactory
     82{
     83  public:
     84    tFastFactory(const char* fastFactoryName, ClassID fastFactory);
     85
     86  private:
     87    virtual BaseObject* fabricate(ClassID classID);
     88};
     89
     90/**
     91 * construnts a FastFactory with
     92 * @param fastFactoryName the name of the FastFactory
     93 * @param fastFactory the ID of the class
     94 */
     95template<class T>
     96    tFastFactory<T>::tFastFactory(const char* fastFactoryName, ClassID fastFactory) : FastFactory(fastFactoryName, fastFactory)
     97{
     98  PRINTF(5)("Class: %s loadable as a FastFactory\n", this->getName());
     99}
     100
     101template<class T>
     102BaseObject* tFastFactory<T>::fabricate(ClassID classID)
     103{
     104  if (this->storedClassID == classID)
     105    return new T ();
     106  else if( getNext() != NULL)
     107    return getNext()->fabricate(classID);
     108  else
     109    return NULL;
     110}
     111
     112
     113
     114
     115////////////////////
     116// OBJECT MANAGER //
     117////////////////////
     118
    28119//! the object manager itself
    29120class ObjectManager : public BaseObject {
     
    35126
    36127  void registerClass(ClassID classID);
    37 
    38   /** a class handled by the objectManage */
    39   void addToDeadList(int index, BaseObject* object);
    40   BaseObject* getFromDeadList(int index, int number = 1);
    41128
    42129  BaseObject* resurect();
     
    52139  static ObjectManager*      singletonRef;          //!< The singleton reference to the only reference of this class
    53140
    54   tList<BaseObject>**        managedObjectList;     //!< A list of managed objects (handles different types and lists of them)
    55141};
    56142
    57143
    58144
    59 /**
    60  * Creates a factory to a Loadable FastObject.
    61  */
    62 #define CREATE_FAST_OBJECT(CLASS_NAME, CLASS_ID) \
    63     tFastObject<CLASS_NAME>* global_##CLASS_NAME##_FastObject = new tFastObject<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
    64 
    65 //! The FastObject is a loadable object handler
    66 class FastObject : public BaseObject {
    67 
    68   public:
    69     FastObject (const char* fastObjectName = NULL, ClassID classID = CL_NULL);
    70     virtual ~FastObject ();
    71 
    72     virtual BaseObject* fabricate(ClassID classID) = NULL;
    73 
    74     static void registerFastObject(FastObject* fastObject);
    75     /** sets the Next factory in the list @param nextFactory the next factory */
    76     inline void setNext( FastObject* nextFastObject) { this->next = nextFastObject; };
    77     /** @returns the first FastObject */
    78     static FastObject* getFirst() { return FastObject::first; };
    79     /** @returns the next FastObject */
    80     FastObject* getNext() const { return this->next; };
    81 
    82   protected:
    83     ClassID              storedClassID;        //!< The classID of the specified class.
    84 
    85   private:
    86     FastObject*          next;                 //!< pointer to the next FastObject.
    87     static FastObject*   first;                //!< A pointer to the first FastObject.
    88 };
    89 
    90 /**
    91  *  a FastObject that is able to load any kind of Object
    92  * (this is a Functor)
    93  */
    94 template<class T> class tFastObject : public FastObject
    95 {
    96   public:
    97     tFastObject(const char* fastObjectName, ClassID fastObject);
    98 
    99   private:
    100     virtual BaseObject* fabricate(ClassID fastObject);
    101 };
    102 
    103 /**
    104  * construnts a FastObject with
    105  * @param fastObjectName the name of the FastObject
    106  * @param fastObject the ID of the class
    107  */
    108 template<class T>
    109 tFastObject<T>::tFastObject(const char* fastObjectName, ClassID fastObject) : FastObject(fastObjectName, fastObject)
    110 {
    111   PRINTF(5)("Class: %s loadable as a FastObject\n", this->getName());
    112 }
    113 
    114 template<class T>
    115 BaseObject* tFastObject<T>::fabricate(ClassID fastObject)
    116 {
    117 //  if(this->classID == fastObject)
    118     //return new T ();
    119   //else if( getNext() != NULL)
    120 //    return getNext()->fabricate();
    121 //  else
    122     return NULL;
    123 }
    124 
    125145#endif /* _OBJECT_MANAGER_H */
Note: See TracChangeset for help on using the changeset viewer.