Mercurial > fife-parpg
comparison engine/core/model/model.cpp @ 35:bf7f838e6684
Added methods for removing Objects from the Model.
author | jwt@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 12 Jul 2008 02:50:09 +0000 |
parents | 112fc4af772d |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
34:d66538926e78 | 35:bf7f838e6684 |
---|---|
30 #include "util/structures/purge.h" | 30 #include "util/structures/purge.h" |
31 #include "model/metamodel/abstractpather.h" | 31 #include "model/metamodel/abstractpather.h" |
32 #include "model/metamodel/object.h" | 32 #include "model/metamodel/object.h" |
33 #include "model/metamodel/grids/cellgrid.h" | 33 #include "model/metamodel/grids/cellgrid.h" |
34 #include "structures/map.h" | 34 #include "structures/map.h" |
35 #include "structures/layer.h" | |
36 #include "structures/instance.h" | |
35 #include "util/base/exception.h" | 37 #include "util/base/exception.h" |
36 | 38 |
37 #include "model.h" | 39 #include "model.h" |
38 | 40 |
39 namespace FIFE { | 41 namespace FIFE { |
157 Object* object = new Object(identifier, name_space, parent); | 159 Object* object = new Object(identifier, name_space, parent); |
158 nspace->second.push_back(object); | 160 nspace->second.push_back(object); |
159 return object; | 161 return object; |
160 } | 162 } |
161 | 163 |
164 bool Model::deleteObject(Object* object) { | |
165 std::list<Layer*>::const_iterator jt; | |
166 std::vector<Instance*>::const_iterator kt; | |
167 for(std::list<Map*>::iterator it = m_maps.begin(); it != m_maps.end(); ++it) { | |
168 for(jt = (*it)->getLayers().begin(); jt != (*it)->getLayers().end(); ++jt) { | |
169 for(kt = (*jt)->getInstances().begin(); kt != (*jt)->getInstances().end(); ++kt) { | |
170 Object* o = (*kt)->getObject(); | |
171 while(o != 0) { | |
172 if(o == object) | |
173 return false; | |
174 } | |
175 } | |
176 } | |
177 } | |
178 | |
179 std::string name_space = object->getNamespace(); | |
180 std::list<namespace_t>::iterator nspace = m_namespaces.begin(); | |
181 for(; nspace != m_namespaces.end(); ++nspace) { | |
182 if(nspace->first == name_space) break; | |
183 } | |
184 | |
185 if(nspace == m_namespaces.end()) | |
186 return true; | |
187 | |
188 std::list<Object*>::iterator it = nspace->second.begin(); | |
189 for(; it != nspace->second.end(); ++it) { | |
190 if(*it == object) { | |
191 delete *it; | |
192 nspace->second.erase(it); | |
193 return true; | |
194 } | |
195 } | |
196 | |
197 return true; | |
198 } | |
199 | |
200 bool Model::deleteObjects() { | |
201 std::list<Layer*>::const_iterator jt; | |
202 for(std::list<Map*>::iterator it = m_maps.begin(); it != m_maps.end(); ++it) { | |
203 for(jt = (*it)->getLayers().begin(); jt != (*it)->getLayers().end(); ++jt) { | |
204 if((*jt)->hasInstances()) | |
205 return false; | |
206 } | |
207 } | |
208 | |
209 std::list<namespace_t>::iterator nspace = m_namespaces.begin(); | |
210 while(nspace != m_namespaces.end()) { | |
211 std::list<Object*>::iterator it = nspace->second.begin(); | |
212 for(; it != nspace->second.end(); ++it) { | |
213 delete *it; | |
214 } | |
215 nspace = m_namespaces.erase(nspace); | |
216 } | |
217 return true; | |
218 } | |
219 | |
162 Object* Model::getObject(const std::string& id, const std::string& name_space) { | 220 Object* Model::getObject(const std::string& id, const std::string& name_space) { |
163 std::list<namespace_t>::iterator nspace = m_namespaces.begin(); | 221 std::list<namespace_t>::iterator nspace = m_namespaces.begin(); |
164 for(; nspace != m_namespaces.end(); ++nspace) { | 222 for(; nspace != m_namespaces.end(); ++nspace) { |
165 if(nspace->first == name_space) { | 223 if(nspace->first == name_space) { |
166 std::list<Object*>::iterator obj = nspace->second.begin(); | 224 std::list<Object*>::iterator obj = nspace->second.begin(); |