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 )
36 void pushElement( const XMLElement& element ){
37 if ( strcmp( element.name(), "epair" ) == 0 ) {
38 m_entity.setKeyValue( element.attribute( "key" ), element.attribute( "value" ) );
41 void popElement( const char* name ){
43 std::size_t write( const char* data, std::size_t length ){
48 class entity_export : public XMLExporter
50 class ExportXMLVisitor : public Entity::Visitor
52 XMLImporter& m_importer;
54 ExportXMLVisitor( XMLImporter& importer ) : m_importer( importer ){
56 void visit( const char* key, const char* value ){
57 StaticElement element( "epair" );
58 element.insertAttribute( "key", key );
59 element.insertAttribute( "value", value );
60 m_importer.pushElement( element );
61 m_importer.popElement( element.name() );
65 const Entity& m_entity;
68 entity_export( const Entity& entity ) : m_entity( entity ){
70 void exportXML( XMLImporter& observer ){
71 ExportXMLVisitor visitor( observer );
73 m_entity.forEachKeyValue( visitor );
77 inline void entity_copy( Entity& entity, const Entity& other ){
78 entity_export exporter( other );
79 entity_import importer( entity );
80 exporter.exportXML( importer );
83 template<typename EntityType>
84 class EntityConstruction
87 typedef EntityClass* type;
88 static type get( const EntityType& entity ){
89 return &entity.getEntity().getEntityClass();
91 static void copy( EntityType& entity, const EntityType& other ){
92 entity_copy( entity.getEntity(), other.getEntity() );