[384] | 1 | /*! |
---|
| 2 | @file Factory.h |
---|
| 3 | @brief Definition of the Factory and the BaseFactory class. |
---|
| 4 | |
---|
[496] | 5 | The Factory is a singleton, containing two maps to map either the name or the network ID |
---|
[384] | 6 | of a class with the corresponding Identifier. |
---|
| 7 | |
---|
| 8 | Usage: |
---|
| 9 | ID(classname) or ID(networkID) returns the corresponding Identifier. |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | BaseObject is the parent of ClassFactory which is defined in ClassFactory.h. |
---|
| 13 | It can't be defined in ClassFactory.h, because of circular dependencies. |
---|
| 14 | */ |
---|
| 15 | |
---|
[218] | 16 | #ifndef _Factory_H__ |
---|
| 17 | #define _Factory_H__ |
---|
| 18 | |
---|
| 19 | #include <map> |
---|
| 20 | #include <string> |
---|
| 21 | |
---|
| 22 | namespace orxonox |
---|
| 23 | { |
---|
[384] | 24 | class BaseObject; // Forward declaration |
---|
| 25 | class Identifier; // Forward declaration |
---|
[218] | 26 | |
---|
[244] | 27 | // ############################### |
---|
| 28 | // ### Factory ### |
---|
| 29 | // ############################### |
---|
[496] | 30 | //! The Factory is used to map the name or the network ID of a class with its Identifier. |
---|
[244] | 31 | class Factory |
---|
[218] | 32 | { |
---|
| 33 | public: |
---|
[244] | 34 | static Identifier* getIdentifier(const std::string& name); |
---|
[363] | 35 | static Identifier* getIdentifier(const unsigned int id); |
---|
[218] | 36 | static void add(const std::string& name, Identifier* identifier); |
---|
[363] | 37 | static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID); |
---|
[496] | 38 | static void createClassHierarchy(); |
---|
[218] | 39 | |
---|
| 40 | private: |
---|
[551] | 41 | Factory() {} // don't create |
---|
| 42 | Factory(const Factory& factory) {} // don't copy |
---|
| 43 | ~Factory() {} // don't delete |
---|
| 44 | static void checkPointer(); |
---|
[218] | 45 | |
---|
[551] | 46 | static Factory* pointer1_s; //!< The 1st pointer to the singleton |
---|
| 47 | static Factory* pointer2_s; //!< The 2nd pointer to the singleton |
---|
| 48 | static Factory* pointer3_s; //!< The 3rd pointer to the singleton |
---|
| 49 | static Factory* pointer4_s; //!< The 4th pointer to the singleton |
---|
| 50 | static Factory* pointer5_s; //!< The 5th pointer to the singleton |
---|
[496] | 51 | std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier |
---|
| 52 | std::map<unsigned int, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier |
---|
[218] | 53 | }; |
---|
[244] | 54 | |
---|
| 55 | // ############################### |
---|
| 56 | // ### BaseFactory ### |
---|
| 57 | // ############################### |
---|
[384] | 58 | //! Base-class of ClassFactory. Has to be defined separate because of circular dependencies. |
---|
[244] | 59 | class BaseFactory |
---|
| 60 | { |
---|
| 61 | public: |
---|
| 62 | virtual BaseObject* fabricate() = 0; |
---|
[384] | 63 | virtual ~BaseFactory() {}; |
---|
[244] | 64 | }; |
---|
[218] | 65 | } |
---|
| 66 | |
---|
| 67 | #endif |
---|