X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fentityxml.h;h=89a9406fb902b20bcb4afda1f14c0795e678bc5e;hb=32dc1da26645b97a5823ff22175000542225c6dd;hp=50df739bb605d44f86d9537713649603bef7a7b4;hpb=bfc8a12a6b315ae261101a34db8ba1b682c67bb7;p=xonotic%2Fnetradiant.git diff --git a/libs/entityxml.h b/libs/entityxml.h index 50df739b..89a9406f 100644 --- a/libs/entityxml.h +++ b/libs/entityxml.h @@ -1,25 +1,25 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ -#if !defined(INCLUDED_ENTITYXML_H) +#if !defined( INCLUDED_ENTITYXML_H ) #define INCLUDED_ENTITYXML_H #include "ientity.h" @@ -28,79 +28,69 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA class entity_import : public XMLImporter { - Entity& m_entity; +Entity& m_entity; public: - entity_import(Entity& entity) - : m_entity(entity) - { - } - void pushElement(const XMLElement& element) - { - if(strcmp(element.name(), "epair") == 0) - m_entity.setKeyValue(element.attribute("key"), element.attribute("value")); - } - void popElement(const char* name) - { - } - std::size_t write(const char* data, std::size_t length) - { - return length; - } +entity_import( Entity& entity ) + : m_entity( entity ){ +} +void pushElement( const XMLElement& element ){ + if ( strcmp( element.name(), "epair" ) == 0 ) { + m_entity.setKeyValue( element.attribute( "key" ), element.attribute( "value" ) ); + } +} +void popElement( const char* name ){ +} +std::size_t write( const char* data, std::size_t length ){ + return length; +} }; class entity_export : public XMLExporter { - class ExportXMLVisitor : public Entity::Visitor - { - XMLImporter& m_importer; - public: - ExportXMLVisitor(XMLImporter& importer) : m_importer(importer) - { - } - void visit(const char* key, const char* value) - { - StaticElement element("epair"); - element.insertAttribute("key", key); - element.insertAttribute("value", value); - m_importer.pushElement(element); - m_importer.popElement(element.name()); - } - }; - - const Entity& m_entity; +class ExportXMLVisitor : public Entity::Visitor +{ +XMLImporter& m_importer; +public: +ExportXMLVisitor( XMLImporter& importer ) : m_importer( importer ){ +} +void visit( const char* key, const char* value ){ + StaticElement element( "epair" ); + element.insertAttribute( "key", key ); + element.insertAttribute( "value", value ); + m_importer.pushElement( element ); + m_importer.popElement( element.name() ); +} +}; + +const Entity& m_entity; public: - entity_export(const Entity& entity) : m_entity(entity) - { - } - void exportXML(XMLImporter& observer) - { - ExportXMLVisitor visitor(observer); - - m_entity.forEachKeyValue(visitor); - } +entity_export( const Entity& entity ) : m_entity( entity ){ +} +void exportXML( XMLImporter& observer ){ + ExportXMLVisitor visitor( observer ); + + m_entity.forEachKeyValue( visitor ); +} }; -inline void entity_copy(Entity& entity, const Entity& other) -{ - entity_export exporter(other); - entity_import importer(entity); - exporter.exportXML(importer); +inline void entity_copy( Entity& entity, const Entity& other ){ + entity_export exporter( other ); + entity_import importer( entity ); + exporter.exportXML( importer ); } template class EntityConstruction { public: - typedef EntityClass* type; - static type get(const EntityType& entity) - { - return &entity.getEntity().getEntityClass(); - } - static void copy(EntityType& entity, const EntityType& other) - { - entity_copy(entity.getEntity(), other.getEntity()); - } +typedef EntityClass* type; +static type get( const EntityType& entity ){ + return &entity.getEntity().getEntityClass(); +} +static void copy( EntityType& entity, const EntityType& other ){ + entity_copy( entity.getEntity(), other.getEntity() ); +} };