30 #include "util/structures/purge.h"
31 #include "util/log/logger.h"
32 #include "model/metamodel/ipather.h"
33 #include "model/metamodel/object.h"
34 #include "model/metamodel/grids/cellgrid.h"
35 #include "structures/map.h"
36 #include "structures/layer.h"
37 #include "structures/instance.h"
38 #include "util/base/exception.h"
39 #include "view/rendererbase.h"
40 #include "video/renderbackend.h"
45 static Logger _log(LM_MODEL);
49 m_last_namespace(NULL),
51 m_renderbackend(renderbackend),
52 m_renderers(renderers){
57 for(std::list<namespace_t>::iterator nspace = m_namespaces.begin(); nspace != m_namespaces.end(); ++nspace)
58 purge_map(nspace->second);
60 purge(m_created_grids);
61 purge(m_adopted_grids);
65 std::list<Map*>::const_iterator it = m_maps.begin();
66 for(; it != m_maps.end(); ++it) {
67 if(identifier == (*it)->getId()) {
68 throw NameClash(identifier);
72 Map* map =
new Map(identifier, m_renderbackend, m_renderers, &m_timeprovider);
73 m_maps.push_back(map);
78 m_pathers.push_back(pather);
82 std::vector<IPather*>::const_iterator it = m_pathers.begin();
83 for(; it != m_pathers.end(); ++it) {
84 if ((*it)->getName() == pathername) {
88 FL_WARN(_log,
"No pather of requested type \"" + pathername +
"\" found.");
93 m_adopted_grids.push_back(grid);
97 std::vector<CellGrid*>::const_iterator it = m_adopted_grids.begin();
98 for(; it != m_adopted_grids.end(); ++it) {
99 if ((*it)->getType() == gridtype) {
100 CellGrid* newcg = (*it)->clone();
101 m_created_grids.push_back(newcg);
105 FL_WARN(_log,
"No cellgrid of requested type \"" + gridtype +
"\" found.");
111 std::list<Map*>::const_iterator it = m_maps.begin();
112 for(; it != m_maps.end(); ++it) {
113 if((*it)->getId() == identifier)
117 throw NotFound(std::string(
"Tried to get non-existent map: ") + identifier +
".");
121 std::list<Map*>::iterator it = m_maps.begin();
122 for(; it != m_maps.end(); ++it) {
132 return m_maps.size();
141 std::list<std::string> namespace_list;
142 std::list<namespace_t>::const_iterator nspace = m_namespaces.begin();
143 for(; nspace != m_namespaces.end(); ++nspace) {
144 namespace_list.push_back(nspace->first);
146 return namespace_list;
151 namespace_t* nspace = selectNamespace(name_space);
153 m_namespaces.push_back(namespace_t(name_space,objectmap_t()));
154 nspace = selectNamespace(name_space);
158 objectmap_t::const_iterator it = nspace->second.find(identifier);
159 if( it != nspace->second.end() ) {
160 throw NameClash(identifier);
164 Object*
object =
new Object(identifier, name_space, parent);
165 nspace->second[identifier] = object;
173 std::list<Layer*>::const_iterator jt;
174 std::vector<Instance*>::const_iterator kt;
175 for(std::list<Map*>::iterator it = m_maps.begin(); it != m_maps.end(); ++it) {
176 for(jt = (*it)->getLayers().begin(); jt != (*it)->getLayers().end(); ++jt) {
177 for(kt = (*jt)->getInstances().begin(); kt != (*jt)->getInstances().end(); ++kt) {
178 Object* o = (*kt)->getObject();
187 namespace_t* nspace = selectNamespace(object->getNamespace());
192 objectmap_t::iterator it = nspace->second.find(object->getId());
193 if( it != nspace->second.end()) {
195 nspace->second.erase(it);
203 std::list<Layer*>::const_iterator jt;
204 for(std::list<Map*>::iterator it = m_maps.begin(); it != m_maps.end(); ++it) {
205 for(jt = (*it)->getLayers().begin(); jt != (*it)->getLayers().end(); ++jt) {
206 if((*jt)->hasInstances())
212 std::list<namespace_t>::iterator nspace = m_namespaces.begin();
213 while(nspace != m_namespaces.end()) {
214 objectmap_t::iterator it = nspace->second.begin();
215 for(; it != nspace->second.end(); ++it) {
218 nspace = m_namespaces.erase(nspace);
220 m_last_namespace = 0;
225 namespace_t* nspace = selectNamespace(name_space);
227 objectmap_t::iterator it = nspace->second.find(
id);
228 if( it != nspace->second.end() )
235 std::list<Object*> object_list;
236 const namespace_t* nspace = selectNamespace(name_space);
238 objectmap_t::const_iterator it = nspace->second.begin();
239 for(; it != nspace->second.end(); ++it )
240 object_list.push_back(it->second);
246 const Model::namespace_t* Model::selectNamespace(
const std::string& name_space)
const {
247 std::list<namespace_t>::const_iterator nspace = m_namespaces.begin();
248 for(; nspace != m_namespaces.end(); ++nspace) {
249 if( nspace->first == name_space ) {
257 Model::namespace_t* Model::selectNamespace(
const std::string& name_space) {
258 if( m_last_namespace && m_last_namespace->first == name_space )
259 return m_last_namespace;
260 std::list<namespace_t>::iterator nspace = m_namespaces.begin();
261 for(; nspace != m_namespaces.end(); ++nspace) {
262 if( nspace->first == name_space ) {
263 m_last_namespace = &(*nspace);
264 return m_last_namespace;
267 m_last_namespace = 0;
272 std::list<Map*>::iterator it = m_maps.begin();
273 for(; it != m_maps.end(); ++it) {
276 std::vector<IPather*>::iterator jt = m_pathers.begin();
277 for(; jt != m_pathers.end(); ++jt) {
std::list< std::string > getNamespaces() const
Map * getMap(const std::string &identifier) const
void adoptCellGrid(CellGrid *grid)
Object * createObject(const std::string &identifier, const std::string &name_space, Object *parent=0)
uint32_t getMapCount() const
CellGrid * getCellGrid(const std::string &gridtype)
Model(RenderBackend *renderbackend, const std::vector< RendererBase * > &renderers)
IPather * getPather(const std::string &pathername)
void adoptPather(IPather *pather)
Object * getObject(const std::string &id, const std::string &name_space)
bool deleteObject(Object *)
std::list< Object * > getObjects(const std::string &name_space) const
Map * createMap(const std::string &identifier)