Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 19, 2006, 5:00:10 PM (18 years ago)
Author:
bensch
Message:

new_class_id: much faster and nicer self-cleaning Factory

File:
1 edited

Legend:

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

    r9757 r9762  
    2727#include "parser/tinyxml/tinyxml.h"
    2828#include "base_object.h"
    29 #include <list>
     29#include <map>
    3030
    3131/**
     
    3434 */
    3535#define CREATE_FACTORY(CLASS_NAME) \
    36     tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(CLASS_NAME::staticClassID())
     36    tFactory<CLASS_NAME> global_##CLASS_NAME##_Factory = tFactory<CLASS_NAME>(CLASS_NAME::staticClassID())
    3737
    3838//! The Factory is a loadable object handler
    3939class Factory : public BaseObject
    4040{
     41  //! Declare the ObjectList at the BaseObject List
    4142  ObjectListDeclaration(Factory);
    4243public:
    4344  virtual ~Factory ();
    44 
    45   static void deleteFactories();
    4645
    4746  static  BaseObject* fabricate(const std::string& className);
     
    4948  static  BaseObject* fabricate(const TiXmlElement* root);
    5049
    51 
    5250  bool operator==(int classID) const;
    5351  bool operator==(const std::string& className) const;
     52  /** @param classID the ID to compare @returns true if the ID's match */
    5453  bool operator==(const ClassID& classID) const { return _classID == classID; };
     54
     55
     56  void debug() const;
     57  static void debugAll();
    5558
    5659protected:
    5760  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   */
    5866  virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
    5967
    6068private:
     69  //! Copy Constructor is hidden.
    6170  Factory (const Factory&) {};
    6271
    6372protected:
    64   const ClassID              _classID;              //!< The Class-Identifyer of the Factory.
    65   static std::list<Factory*>*   _factoryList;          //!< List of Registered Factories
     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
    6681};
    6782
     
    7590  /**
    7691   * @brief creates a new type Factory to enable the loading of T
    77    * @param factoryName the Name of the Factory to load.
    7892   * @param classID the ID of the Class to be created.
    7993   */
     
    8195      : Factory(classID)
    8296  {  }
     97  /**
     98   * @brief copy constructor
     99   * @param factory the Factory to copy
     100   */
     101  tFactory (const tFactory& factory) : Factory(factory._classID) {};
    83102
    84 private:
    85   tFactory (const tFactory&) {};
    86103  /**
    87104   * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
Note: See TracChangeset for help on using the changeset viewer.