2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined(INCLUDED_ENTITYXML_H)
23 #define INCLUDED_ENTITYXML_H
27 #include "xml/xmlelement.h"
29 class entity_import : public XMLImporter
33 entity_import(Entity& entity)
37 void pushElement(const XMLElement& element)
39 if(strcmp(element.name(), "epair") == 0)
40 m_entity.setKeyValue(element.attribute("key"), element.attribute("value"));
42 void popElement(const char* name)
45 std::size_t write(const char* data, std::size_t length)
51 class entity_export : public XMLExporter
53 class ExportXMLVisitor : public Entity::Visitor
55 XMLImporter& m_importer;
57 ExportXMLVisitor(XMLImporter& importer) : m_importer(importer)
60 void visit(const char* key, const char* value)
62 StaticElement element("epair");
63 element.insertAttribute("key", key);
64 element.insertAttribute("value", value);
65 m_importer.pushElement(element);
66 m_importer.popElement(element.name());
70 const Entity& m_entity;
73 entity_export(const Entity& entity) : m_entity(entity)
76 void exportXML(XMLImporter& observer)
78 ExportXMLVisitor visitor(observer);
80 m_entity.forEachKeyValue(visitor);
84 inline void entity_copy(Entity& entity, const Entity& other)
86 entity_export exporter(other);
87 entity_import importer(entity);
88 exporter.exportXML(importer);
91 template<typename EntityType>
92 class EntityConstruction
95 typedef EntityClass* type;
96 static type get(const EntityType& entity)
98 return &entity.getEntity().getEntityClass();
100 static void copy(EntityType& entity, const EntityType& other)
102 entity_copy(entity.getEntity(), other.getEntity());