Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/util/loading/factory.h


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/loading/factory.h

    r8148 r9869  
    2020
    2121
    22 #ifndef _FACTORY_H
    23 #define _FACTORY_H
     22#ifndef __FACTORY_H
     23#define __FACTORY_H
    2424
    2525class BaseObject;
     
    2727#include "parser/tinyxml/tinyxml.h"
    2828#include "base_object.h"
    29 #include <vector>
    30 #include <list>
     29#include <map>
    3130
    3231/**
     
    3433 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    3534 */
    36 #define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \
    37     tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
     35#define CREATE_FACTORY(CLASS_NAME) \
     36    tFactory<CLASS_NAME> global_##CLASS_NAME##_Factory = tFactory<CLASS_NAME>(CLASS_NAME::staticClassID())
    3837
    3938//! The Factory is a loadable object handler
    40 class Factory : public BaseObject {
    41 
    42  public:
     39class Factory : public BaseObject
     40{
     41  //! Declare the ObjectList at the BaseObject List
     42  ObjectListDeclaration(Factory);
     43public:
    4344  virtual ~Factory ();
    4445
    45   static void deleteFactories();
     46  static  BaseObject* fabricate(const std::string& className);
     47  static  BaseObject* fabricate(const ClassID& classID);
     48  static  BaseObject* fabricate(const TiXmlElement* root);
    4649
    47   static  BaseObject* fabricate(const std::string& className);
    48   static  BaseObject* fabricate(ClassID classID);
    49   static  BaseObject* fabricate(const TiXmlElement* root = NULL);
     50  bool operator==(int classID) const;
     51  bool operator==(const std::string& className) const;
     52  /** @param classID the ID to compare @returns true if the ID's match */
     53  bool operator==(const ClassID& classID) const { return _classID == classID; };
    5054
    5155
    52   bool operator==(ClassID classID) const;
    53   bool operator==(const char* className) const;
    54   bool operator==(const std::string& className) const;
     56  void debug() const;
     57  static void debugAll();
    5558
    56   protected:
    57     Factory (const std::string& factoryName, ClassID classID);
    58     virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
     59protected:
     60  Factory (const ClassID& id);
     61  /**
     62   * @brief The core function of the Factory. Creates objects of the Factories Type.
     63   * @param root The TiXmlElement of the Factory.
     64   * @returns the created Object in BaseType* format.
     65   */
     66  virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
    5967
    60   protected:
    61     const ClassID                 classID;              //!< The Class-Identifyer of the Factory.
    62     const std::string             className;            //!< The name of the Class.
    63     static std::list<Factory*>*   factoryList;          //!< List of Registered Factories
     68private:
     69  //! Copy Constructor is hidden.
     70  Factory (const Factory&) {};
     71
     72protected:
     73  /** The Type of the FactoryMap that is sorted by ID */
     74  typedef std::map<const ClassID, Factory*>  FactoryIDMap;
     75  /** The Type of the FactoryMap that is sorted by Name */
     76  typedef std::map<std::string, Factory*>    FactoryStringMap;
     77
     78  const ClassID                 _classID;              //!< The Class-Identifyer of the Factory.
     79  static FactoryIDMap           _factoryIDMap;         //!< List of Registered Factories
     80  static FactoryStringMap       _factoryStringMap;     //!< List of Registered Factories
    6481};
    6582
     
    7087template<class T> class tFactory : public Factory
    7188{
    72  public:
    73  /**
    74   * @brief creates a new type Factory to enable the loading of T
    75   * @param factoryName the Name of the Factory to load.
    76   * @param classID the ID of the Class to be created.
    77   */
    78   tFactory (const char* factoryName, ClassID classID)
    79    : Factory(factoryName, classID)
     89public:
     90  /**
     91   * @brief creates a new type Factory to enable the loading of T
     92   * @param classID the ID of the Class to be created.
     93   */
     94  tFactory (const ClassID& classID)
     95      : Factory(classID)
    8096  {  }
     97  /**
     98   * @brief copy constructor
     99   * @param factory the Factory to copy
     100   */
     101  tFactory (const tFactory& factory) : Factory(factory._classID) {};
    81102
    82   private:
    83    /**
    84     * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
    85     * @param root the TiXmlElement T should load parameters from.
    86     * @return the newly fabricated T.
    87     */
    88     virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const
    89     {
    90       return new T(root);
    91     }
     103  /**
     104   * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
     105   * @param root the TiXmlElement T should load parameters from.
     106   * @return the newly fabricated T.
     107   */
     108  virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const
     109  {
     110    return new T(root);
     111  }
    92112};
    93113
Note: See TracChangeset for help on using the changeset viewer.