[513] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * ... |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[384] | 28 | /*! |
---|
| 29 | @file Factory.cc |
---|
| 30 | @brief Implementation of the Factory class. |
---|
| 31 | */ |
---|
| 32 | |
---|
[513] | 33 | #include "Factory.h" |
---|
[496] | 34 | #include "Identifier.h" |
---|
| 35 | #include "Debug.h" |
---|
[513] | 36 | #include "../objects/BaseObject.h" |
---|
[384] | 37 | |
---|
[513] | 38 | namespace orxonox |
---|
| 39 | { |
---|
| 40 | Factory* Factory::pointer_s = NULL; // Set the static member variable pointer_s to zero |
---|
| 41 | |
---|
[384] | 42 | /** |
---|
| 43 | @returns the Identifier with a given name. |
---|
| 44 | @param name The name of the wanted Identifier |
---|
[513] | 45 | */ |
---|
| 46 | Identifier* Factory::getIdentifier(const std::string& name) |
---|
| 47 | { |
---|
[363] | 48 | if (!pointer_s) |
---|
| 49 | pointer_s = new Factory; |
---|
| 50 | |
---|
| 51 | return pointer_s->identifierStringMap_[name]; |
---|
| 52 | } |
---|
| 53 | |
---|
[384] | 54 | /** |
---|
[496] | 55 | @returns the Identifier with a given network ID. |
---|
| 56 | @param id The network ID of the wanted Identifier |
---|
[384] | 57 | */ |
---|
[363] | 58 | Identifier* Factory::getIdentifier(const unsigned int id) |
---|
| 59 | { |
---|
| 60 | if (!pointer_s) |
---|
| 61 | pointer_s = new Factory; |
---|
| 62 | |
---|
| 63 | return pointer_s->identifierNetworkIDMap_[id]; |
---|
[513] | 64 | } |
---|
[384] | 65 | |
---|
| 66 | /** |
---|
| 67 | @brief Adds a new Identifier to both maps. |
---|
| 68 | @param name The name of the identifier |
---|
| 69 | @param identifier The identifier to add |
---|
[513] | 70 | */ |
---|
| 71 | void Factory::add(const std::string& name, Identifier* identifier) |
---|
| 72 | { |
---|
| 73 | if (!pointer_s) |
---|
| 74 | pointer_s = new Factory; |
---|
| 75 | |
---|
[363] | 76 | pointer_s->identifierStringMap_[name] = identifier; |
---|
| 77 | pointer_s->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier; |
---|
| 78 | } |
---|
| 79 | |
---|
[384] | 80 | /** |
---|
[496] | 81 | @brief Removes the entry with the old network ID and adds a new one. |
---|
[384] | 82 | @param identifier The identifier to change |
---|
| 83 | @param oldID The old networkID |
---|
| 84 | @param newID The new networkID |
---|
| 85 | */ |
---|
[363] | 86 | void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID) |
---|
| 87 | { |
---|
| 88 | pointer_s->identifierNetworkIDMap_.erase(oldID); |
---|
| 89 | pointer_s->identifierNetworkIDMap_[newID] = identifier; |
---|
[496] | 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | @brief Creates the class-hierarchy by creating and destroying one object of each type. |
---|
| 94 | */ |
---|
| 95 | void Factory::createClassHierarchy() |
---|
| 96 | { |
---|
| 97 | if (!pointer_s) |
---|
| 98 | pointer_s = new Factory; |
---|
| 99 | |
---|
| 100 | COUT(4) << "*** Factory -> Create class-hierarchy\n"; |
---|
| 101 | std::map<std::string, Identifier*>::iterator it; |
---|
| 102 | it = pointer_s->identifierStringMap_.begin(); |
---|
| 103 | (*pointer_s->identifierStringMap_.begin()).second->startCreatingHierarchy(); |
---|
| 104 | for (it = pointer_s->identifierStringMap_.begin(); it != pointer_s->identifierStringMap_.end(); ++it) |
---|
| 105 | { |
---|
| 106 | // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards. |
---|
| 107 | BaseObject* temp = (*it).second->fabricate(); |
---|
| 108 | delete temp; |
---|
| 109 | } |
---|
| 110 | (*pointer_s->identifierStringMap_.begin()).second->stopCreatingHierarchy(); |
---|
| 111 | COUT(4) << "*** Factory -> Finished class-hierarchy creation\n"; |
---|
| 112 | } |
---|
[513] | 113 | } |
---|