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