1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Patrick Boenzli |
---|
13 | co-programmer: Benjamin Grauer |
---|
14 | */ |
---|
15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE |
---|
16 | |
---|
17 | #include "base_object.h" |
---|
18 | |
---|
19 | #include "util/debug.h" |
---|
20 | #include "util/loading/load_param.h" |
---|
21 | |
---|
22 | ObjectListDefinition(BaseObject); |
---|
23 | |
---|
24 | /** |
---|
25 | * @brief sets the name from a LoadXML-Element |
---|
26 | * @param objectName: The name of the Object. |
---|
27 | */ |
---|
28 | BaseObject::BaseObject(const std::string& objectName) |
---|
29 | { |
---|
30 | this->className = "BaseObject"; |
---|
31 | |
---|
32 | this->objectName = objectName; |
---|
33 | this->xmlElem = NULL; |
---|
34 | this->registerObject(this, BaseObject::_objectList); |
---|
35 | |
---|
36 | srand(time(0)); //initialize Random Nomber Generator |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * copyconstructor |
---|
41 | * @param bo instance to copy |
---|
42 | */ |
---|
43 | BaseObject::BaseObject( const BaseObject& bo ) |
---|
44 | { |
---|
45 | this->className = "BaseObject"; |
---|
46 | this->objectName = bo.objectName; |
---|
47 | this->xmlElem = (bo.xmlElem)? bo.xmlElem->Clone() : NULL; |
---|
48 | this->registerObject( this, BaseObject::_objectList); |
---|
49 | |
---|
50 | srand(time(0)); //initialize Random Nomber Generator |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | /** |
---|
55 | * @brief standard deconstructor |
---|
56 | */ |
---|
57 | BaseObject::~BaseObject () |
---|
58 | { |
---|
59 | /// Remove from the ObjectLists |
---|
60 | ClassEntries::iterator it; |
---|
61 | PRINTF(5)("Deleting Object of type %s::%s\n", this->getClassCName(), getCName()); |
---|
62 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
63 | { |
---|
64 | //if (ORX_DEBUG >= 5) |
---|
65 | assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this)); |
---|
66 | (*it)._objectList->unregisterObject((*it)._iterator); |
---|
67 | delete (*it)._iterator; |
---|
68 | } |
---|
69 | |
---|
70 | if (this->xmlElem != NULL) |
---|
71 | delete this->xmlElem; |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief loads parameters |
---|
76 | * @param root the element to load from |
---|
77 | */ |
---|
78 | void BaseObject::loadParams(const TiXmlElement* root) |
---|
79 | { |
---|
80 | // all loadParams should arrive here, and be tested for (root != NULL) |
---|
81 | assert (root != NULL); |
---|
82 | |
---|
83 | // copy the xml-element for to know how it was loaded. |
---|
84 | if (this->xmlElem != NULL) |
---|
85 | delete this->xmlElem; |
---|
86 | this->xmlElem = root->Clone(); |
---|
87 | |
---|
88 | // name setup |
---|
89 | LoadParam(root, "name", this, BaseObject, setName) |
---|
90 | .describe("the Name of the Object."); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief set the name of the Object |
---|
95 | * @param objectName The new name of the Object. |
---|
96 | */ |
---|
97 | void BaseObject::setName (const std::string& objectName) |
---|
98 | { |
---|
99 | this->objectName = objectName; |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | /** |
---|
104 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
105 | * @param objectList The ObjectList this should be a member of (by Pointer-comparison). |
---|
106 | * @return True if found, false if not. |
---|
107 | */ |
---|
108 | bool BaseObject::isA(const ObjectListBase& objectList) const |
---|
109 | { |
---|
110 | ClassEntries::const_iterator it; |
---|
111 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
112 | if ((*it)._objectList == &objectList) |
---|
113 | return true; |
---|
114 | return false; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | /** |
---|
119 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
120 | * @param classID The ClassID this should be a member of (by Pointer-comparison). |
---|
121 | * @return True if found, false if not. |
---|
122 | */ |
---|
123 | bool BaseObject::isA(const ClassID& classID) const |
---|
124 | { |
---|
125 | ClassEntries::const_iterator it; |
---|
126 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
127 | if (*(*it)._objectList == classID) |
---|
128 | return true; |
---|
129 | return false; |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
134 | * @param classID The ClassID of the class this should be a member of. |
---|
135 | * @return True if found, false if not. |
---|
136 | */ |
---|
137 | bool BaseObject::isA(int classID) const |
---|
138 | { |
---|
139 | ClassEntries::const_iterator it; |
---|
140 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
141 | if (*(*it)._objectList == classID) |
---|
142 | |
---|
143 | return true; |
---|
144 | return false; |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
149 | * @param className The ClassName of the class this should be a member of. |
---|
150 | * @return True if found, false if not. |
---|
151 | */ |
---|
152 | bool BaseObject::isA(const std::string& className) const |
---|
153 | { |
---|
154 | ClassEntries::const_iterator it; |
---|
155 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
156 | if (*(*it)._objectList == className) |
---|
157 | return true; |
---|
158 | return false; |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | /** |
---|
163 | * @brief This is for debug purposes, to see the Inheritances of this Object and its classes. |
---|
164 | * |
---|
165 | * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency. |
---|
166 | */ |
---|
167 | void BaseObject::listInheritance() const |
---|
168 | { |
---|
169 | PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName()); |
---|
170 | ClassEntries::const_iterator it; |
---|
171 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
172 | PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id()); |
---|
173 | PRINT(0)("\n"); |
---|
174 | |
---|
175 | } |
---|