1 | /*! |
---|
2 | @file Factory.cc |
---|
3 | @brief Implementation of the Factory class. |
---|
4 | */ |
---|
5 | |
---|
6 | #include "Factory.h" |
---|
7 | #include "Identifier.h" |
---|
8 | |
---|
9 | namespace orxonox |
---|
10 | { |
---|
11 | Factory* Factory::pointer_s = NULL; // Set the static member variable pointer_s to zero |
---|
12 | |
---|
13 | /** |
---|
14 | @returns the Identifier with a given name. |
---|
15 | @param name The name of the wanted Identifier |
---|
16 | */ |
---|
17 | Identifier* Factory::getIdentifier(const std::string& name) |
---|
18 | { |
---|
19 | if (!pointer_s) |
---|
20 | pointer_s = new Factory; |
---|
21 | |
---|
22 | return pointer_s->identifierStringMap_[name]; |
---|
23 | } |
---|
24 | |
---|
25 | /** |
---|
26 | @returns the Identifier with a given networkID. |
---|
27 | @param id The networkID of the wanted Identifier |
---|
28 | */ |
---|
29 | Identifier* Factory::getIdentifier(const unsigned int id) |
---|
30 | { |
---|
31 | if (!pointer_s) |
---|
32 | pointer_s = new Factory; |
---|
33 | |
---|
34 | return pointer_s->identifierNetworkIDMap_[id]; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | @brief Adds a new Identifier to both maps. |
---|
39 | @param name The name of the identifier |
---|
40 | @param identifier The identifier to add |
---|
41 | */ |
---|
42 | void Factory::add(const std::string& name, Identifier* identifier) |
---|
43 | { |
---|
44 | if (!pointer_s) |
---|
45 | pointer_s = new Factory; |
---|
46 | |
---|
47 | pointer_s->identifierStringMap_[name] = identifier; |
---|
48 | pointer_s->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier; |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | @brief Removes the entry with the old networkID and adds a new one. |
---|
53 | @param identifier The identifier to change |
---|
54 | @param oldID The old networkID |
---|
55 | @param newID The new networkID |
---|
56 | */ |
---|
57 | void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID) |
---|
58 | { |
---|
59 | pointer_s->identifierNetworkIDMap_.erase(oldID); |
---|
60 | pointer_s->identifierNetworkIDMap_[newID] = identifier; |
---|
61 | } |
---|
62 | } |
---|