Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 17, 2005, 1:20:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/world_entities: Factory is now also able to fabricate by ClassID
for this the construction-MACRO changed from
CREATE_FACTORY(CLASS_NAME)
to
CREATE_FACTORY(CLASS_NAME, CLASS_ID)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/world_entities/src/util/loading/factory.h

    r5357 r5622  
    3333 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    3434*/
    35 #define CREATE_FACTORY(CLASS_NAME) \
    36     tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME)
     35#define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \
     36    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
    3737
    3838//! The Factory is a loadable object handler
     
    4040
    4141 public:
    42   Factory (const char* factoryName = NULL);
     42  Factory (const char* factoryName = NULL, ClassID classID = CL_NULL);
    4343  virtual ~Factory ();
    4444
    4545  void fabricate(const char* className, const char* entityName);
     46  virtual BaseObject* fabricate(ClassID classID) = NULL;
    4647  virtual BaseObject* fabricate(const TiXmlElement* root) = NULL;
    4748  virtual BaseObject* fabricateDirect() = NULL;
     
    5758    Factory* getNext() const { return this->next; };
    5859
     60
     61  protected:
     62    ClassID           classID;              //!< The CLass-Identifyer of the Factory.
     63
    5964  private:
    6065    Factory*          next;                 //!< pointer to the next factory.
     
    6469/**
    6570 *  a factory that is able to load any kind of Object
    66    (this is a Functor)
    67 */
     71 * (this is a Functor)
     72 */
    6873template<class T> class tFactory : public Factory
    6974{
    70  public:
    71   tFactory(const char* factoryName);
    72   virtual ~tFactory();
     75  public:
     76    tFactory(const char* factoryName, ClassID classID);
     77    virtual ~tFactory();
    7378
    7479  private:
    75   virtual BaseObject* fabricate(const TiXmlElement* root);
    76   virtual BaseObject* fabricateDirect();
     80    virtual BaseObject* fabricate(ClassID classID);
     81    virtual BaseObject* fabricate(const TiXmlElement* root);
     82    virtual BaseObject* fabricateDirect();
    7783};
    7884
     
    8288*/
    8389template<class T>
    84 tFactory<T>::tFactory(const char* factoryName) : Factory(factoryName)
     90    tFactory<T>::tFactory(const char* factoryName, ClassID classID) : Factory(factoryName, classID)
    8591{
    8692  PRINTF(4)("Class: %s loadable\n", this->getName());
    8793}
    8894
    89 
     95/**
     96 * destructs the type-Factory
     97 */
    9098template<class T>
    91 tFactory<T>::~tFactory()
     99    tFactory<T>::~tFactory()
    92100{}
    93101
     102/**
     103 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
     104 * @param root the TiXmlElement T should load parameters from.
     105 * @return the newly fabricated T, NULL otherwise.
     106 */
    94107template<class T>
    95 BaseObject* tFactory<T>::fabricate(const TiXmlElement* root)
     108    BaseObject* tFactory<T>::fabricate(const TiXmlElement* root)
    96109{
    97110  if (root == NULL)
     
    106119}
    107120
     121
     122/**
     123 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
     124 * @param classID the ClassID of T that should be created.
     125 * @return the newly fabricated T if fabricated NULL otherwise.
     126 */
     127template<class T>
     128    BaseObject* tFactory<T>::fabricate(ClassID classID)
     129{
     130  if(classID == this->classID)
     131    return this->fabricateDirect();
     132  else if( getNext() != NULL)
     133    return getNext()->fabricate( classID);
     134  else
     135    return NULL;
     136}
     137
     138/**
     139 * directly fabricate an Entity of this factory.
     140 */
    108141template<class T>
    109142    BaseObject* tFactory<T>::fabricateDirect()
Note: See TracChangeset for help on using the changeset viewer.