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 | |
---|
37 | /** |
---|
38 | * copyconstructor |
---|
39 | * @param bo instance to copy |
---|
40 | */ |
---|
41 | BaseObject::BaseObject( const BaseObject& bo ) |
---|
42 | { |
---|
43 | this->className = "BaseObject"; |
---|
44 | this->objectName = bo.objectName; |
---|
45 | this->xmlElem = (bo.xmlElem)? bo.xmlElem->Clone() : NULL; |
---|
46 | this->registerObject( this, BaseObject::_objectList); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | * @brief standard deconstructor |
---|
52 | */ |
---|
53 | BaseObject::~BaseObject () |
---|
54 | { |
---|
55 | /// Remove from the ObjectLists |
---|
56 | ClassEntries::iterator it; |
---|
57 | PRINTF(5)("Deleting Object of type %s::%s\n", this->getClassCName(), getCName()); |
---|
58 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
59 | { |
---|
60 | //if (ORX_DEBUG >= 5) |
---|
61 | assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this)); |
---|
62 | (*it)._objectList->unregisterObject((*it)._iterator); |
---|
63 | delete (*it)._iterator; |
---|
64 | } |
---|
65 | |
---|
66 | if (this->xmlElem != NULL) |
---|
67 | delete this->xmlElem; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * @brief loads parameters |
---|
72 | * @param root the element to load from |
---|
73 | */ |
---|
74 | void BaseObject::loadParams(const TiXmlElement* root) |
---|
75 | { |
---|
76 | // all loadParams should arrive here, and be tested for (root != NULL) |
---|
77 | assert (root != NULL); |
---|
78 | |
---|
79 | // copy the xml-element for to know how it was loaded. |
---|
80 | if (this->xmlElem != NULL) |
---|
81 | delete this->xmlElem; |
---|
82 | this->xmlElem = root->Clone(); |
---|
83 | |
---|
84 | // name setup |
---|
85 | LoadParam(root, "name", this, BaseObject, setName) |
---|
86 | .describe("the Name of the Object."); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * @brief set the name of the Object |
---|
91 | * @param objectName The new name of the Object. |
---|
92 | */ |
---|
93 | void BaseObject::setName (const std::string& objectName) |
---|
94 | { |
---|
95 | this->objectName = objectName; |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
101 | * @param objectList The ObjectList this should be a member of (by Pointer-comparison). |
---|
102 | * @return True if found, false if not. |
---|
103 | */ |
---|
104 | bool BaseObject::isA(const ObjectListBase& objectList) const |
---|
105 | { |
---|
106 | ClassEntries::const_iterator it; |
---|
107 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
108 | if ((*it)._objectList == &objectList) |
---|
109 | return true; |
---|
110 | return false; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | /** |
---|
115 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
116 | * @param classID The ClassID this should be a member of (by Pointer-comparison). |
---|
117 | * @return True if found, false if not. |
---|
118 | */ |
---|
119 | bool BaseObject::isA(const ClassID& classID) const |
---|
120 | { |
---|
121 | ClassEntries::const_iterator it; |
---|
122 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
123 | if (*(*it)._objectList == classID) |
---|
124 | return true; |
---|
125 | return false; |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
130 | * @param classID The ClassID of the class this should be a member of. |
---|
131 | * @return True if found, false if not. |
---|
132 | */ |
---|
133 | bool BaseObject::isA(int classID) const |
---|
134 | { |
---|
135 | ClassEntries::const_iterator it; |
---|
136 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
137 | if (*(*it)._objectList == classID) |
---|
138 | |
---|
139 | return true; |
---|
140 | return false; |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
145 | * @param className The ClassName of the class this should be a member of. |
---|
146 | * @return True if found, false if not. |
---|
147 | */ |
---|
148 | bool BaseObject::isA(const std::string& className) const |
---|
149 | { |
---|
150 | ClassEntries::const_iterator it; |
---|
151 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
152 | if (*(*it)._objectList == className) |
---|
153 | return true; |
---|
154 | return false; |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | /** |
---|
159 | * @brief This is for debug purposes, to see the Inheritances of this Object and its classes. |
---|
160 | * |
---|
161 | * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency. |
---|
162 | */ |
---|
163 | void BaseObject::listInheritance() const |
---|
164 | { |
---|
165 | PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName()); |
---|
166 | ClassEntries::const_iterator it; |
---|
167 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
168 | PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id()); |
---|
169 | PRINT(0)("\n"); |
---|
170 | |
---|
171 | } |
---|