Last change
on this file since 363 was
363,
checked in by landauf, 17 years ago
|
added NetworkID
small tutorial for oli and dumeni:
every Identifier generates its own NetworkID, but it can be changed:
→ (Identifier)→setNetworkID(unsigned int)
be careful: after changing the NetworkID, there are probably 2 Identifiers with the same ID, so always change ALL Identifiers before using ID(unsigned int).
get an Identifier with a specific NetworkID:
→ ID(unsigned int)
get the name:
→ ID(unsigned int)→getName()
create an object:
→ ID(unsigned int)→fabricate()
get an Identifier with a specific name:
→ ID(std::string&)
get the NetworkID:
→ ID(std::string&)→getNetworkID()
create an object:
→ ID(std::string&)→fabricate()
|
File size:
1.2 KB
|
Rev | Line | |
---|
[218] | 1 | #ifndef _Factory_H__ |
---|
| 2 | #define _Factory_H__ |
---|
| 3 | |
---|
| 4 | #include <map> |
---|
| 5 | #include <string> |
---|
| 6 | |
---|
| 7 | namespace orxonox |
---|
| 8 | { |
---|
[244] | 9 | class BaseObject; |
---|
[218] | 10 | class Identifier; |
---|
| 11 | |
---|
[244] | 12 | // ############################### |
---|
| 13 | // ### Factory ### |
---|
| 14 | // ############################### |
---|
| 15 | class Factory |
---|
[218] | 16 | { |
---|
| 17 | public: |
---|
[244] | 18 | static Identifier* getIdentifier(const std::string& name); |
---|
[363] | 19 | static Identifier* getIdentifier(const unsigned int id); |
---|
[218] | 20 | static void add(const std::string& name, Identifier* identifier); |
---|
[363] | 21 | static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID); |
---|
[218] | 22 | |
---|
| 23 | private: |
---|
[244] | 24 | Factory() {} |
---|
| 25 | Factory(const Factory& factory) {} |
---|
| 26 | ~Factory() {} |
---|
[218] | 27 | |
---|
[244] | 28 | static Factory* pointer_s; |
---|
[363] | 29 | std::map<std::string, Identifier*> identifierStringMap_; |
---|
| 30 | std::map<unsigned int, Identifier*> identifierNetworkIDMap_; |
---|
[218] | 31 | }; |
---|
[244] | 32 | |
---|
| 33 | // ############################### |
---|
| 34 | // ### BaseFactory ### |
---|
| 35 | // ############################### |
---|
| 36 | class BaseFactory |
---|
| 37 | { |
---|
| 38 | public: |
---|
| 39 | virtual BaseObject* fabricate() = 0; |
---|
| 40 | }; |
---|
[218] | 41 | } |
---|
| 42 | |
---|
| 43 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.