Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkXMLFile.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkXMLFile.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:36 $ 00007 Version: $1.0$ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __itkXMLFile_h 00018 #define __itkXMLFile_h 00019 #include "itkLightProcessObject.h" 00020 #include "expat.h" 00021 #include <fstream> 00022 00023 namespace itk 00024 { 00025 00033 class 00034 XMLReaderBase : public LightProcessObject 00035 { 00036 public: 00038 itkSetStringMacro(Filename); 00039 00041 itkGetStringMacro(Filename); 00042 00044 virtual int CanReadFile(const char* name) = 0; 00046 virtual void GenerateOutputInformation(); 00050 virtual void StartElement(const char * name,const char **atts) = 0; 00054 virtual void EndElement(const char *name) = 0; 00058 virtual void CharacterDataHandler(const char *inData, int inLength) = 0; 00059 protected: 00064 void parse(void); 00065 std::string m_Filename; 00066 }; 00067 00074 template <class T> class 00075 XMLReader : public XMLReaderBase 00076 { 00077 public: 00081 void SetOutputObject(T *obj) { m_OutputObject = obj; } 00084 T *GetOutputObject(void) { return m_OutputObject; } 00085 protected: 00086 T *m_OutputObject; 00087 }; 00088 00097 template <class T> 00098 class XMLWriterBase : public LightProcessObject 00099 { 00100 public: 00104 XMLWriterBase() { 00105 m_InputObject = 0; 00106 } 00108 itkSetStringMacro(Filename); 00110 itkGetStringMacro(Filename); 00112 virtual int CanWriteFile(const char* name) = 0; 00114 void SetObject(T *toWrite) { m_InputObject = toWrite; } 00116 virtual int WriteFile() = 0; 00118 void WriteStartElement(const char *const tag,std::ofstream &file) 00119 { 00120 file << '<' << tag << '>'; 00121 } 00123 void WriteEndElement(const char *const tag,std::ofstream &file) 00124 { 00125 file << '<' << '/' << tag << '>'; 00126 } 00128 void WriteCharacterData(const char *const data,std::ofstream &file) 00129 { 00130 file << data; 00131 } 00133 void WriteStartElement(std::string &tag,std::ofstream &file) 00134 { 00135 WriteStartElement(tag.c_str(),file); 00136 } 00138 void WriteEndElement(std::string &tag,std::ofstream &file) 00139 { 00140 WriteEndElement(tag.c_str(),file); 00141 } 00143 void WriteCharacterData(std::string &data,std::ofstream &file) 00144 { 00145 WriteCharacterData(data.c_str(),file); 00146 } 00147 protected: 00148 T *m_InputObject; // object to write out to an XML file 00149 std::string m_Filename; // name of file to write. 00150 }; 00151 00152 } 00153 #endif

Generated at Sat Mar 31 02:35:24 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000