Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 22, 2005, 2:11:21 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: adapted the Factory algorithm to ObjectManager… still a logn way to go…

File:
1 edited

Legend:

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

    r4836 r4930  
    1010
    1111    TO ADD SUPPORT FOR A CLASS do the following steps:
    12     1. include the hader file : #include "class_header.h"
     12    1. include the hader file : #include "class_id.h"
    1313    2. add the class to the type enum classID {}; in class_id.h
    1414    3. define a function void mCache( ClassName ) in class ObjectManager
     
    2121
    2222#include "base_object.h"
    23 #include "projectile.h"
    24 #include "list.h"
    2523
     24template<class T> class tList;
    2625class GarbageCollector;
    27 
    28 
    29 //! This defines the "template" macro function for cache(...)
    30 #define mCache( Class ) \
    31  cache(ClassID index, int number, Class * copyObject)        \
    32 {                                                              \
    33   this->managedObjectList[index] = new tList<BaseObject>(); \
    34   for(int i = 0; i < number; ++i)\
    35     {\
    36       this->managedObjectList[index]->add(new Class (*copyObject));\
    37     }\
    38 }
    39 
    40 
    4126
    4227//! the object manager itself
     
    5136
    5237  /** a class handled by the objectManage */
    53   void mCache(Projectile);
    5438  void addToDeadList(int index, BaseObject* object);
    5539  BaseObject* getFromDeadList(int index, int number = 1);
     40
     41  BaseObject* resurect();
     42  void kill(BaseObject* object);
     43
    5644
    5745  void debug() const;
     
    6856
    6957
     58/**
     59 * Creates a factory to a Loadable Class.
     60 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
     61 */
     62#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \
     63    tObject<CLASS_NAME>* global_##CLASS_NAME##_Object = new tObject<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
     64
     65//! The Factory is a loadable object handler
     66class 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 factory */
     78    static FastObject* getFirst() { return FastObject::first; };
     79    /** @returns the next factory */
     80    FastObject* getNext() const { return this->next; };
     81
     82  private:
     83    FastObject*          next;                 //!< pointer to the next factory.
     84    static FastObject*   first;                //!< A pointer to the first factory.
     85    ClassID              storedClassID;        //!< The classID of the specified class.
     86};
     87
     88/**
     89 *  a factory that is able to load any kind of Object
     90   (this is a Functor)
     91 */
     92template<class T> class tFastObject : public FastObject
     93{
     94  public:
     95    tFastObject(const char* fastObjectName, ClassID fastObject);
     96
     97  private:
     98    virtual BaseObject* fabricate(ClassID fastObject);
     99};
     100
     101/**
     102 * construnts a factory with
     103 * @param factoryName the name of the factory
     104 */
     105template<class T>
     106tFastObject<T>::tFastObject(const char* fastObjectName, ClassID fastObject) : FastObject(fastObjectName, fastObject)
     107{
     108  PRINTF(5)("Class: %s loadable as a FastObject\n", this->getName());
     109}
     110
     111template<class T>
     112BaseObject* tFastObject<T>::fabricate(ClassID fastObject)
     113{
     114  if(this->classID == fastObject)
     115    return new T ( root);
     116  else if( getNext() != NULL)
     117    return getNext()->fabricate( root);
     118  else
     119    return NULL;
     120}
     121
    70122#endif /* _OBJECT_MANAGER_H */
Note: See TracChangeset for help on using the changeset viewer.