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: 2004/01/08 00:39:08 $
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;
00045 
00047   virtual void GenerateOutputInformation();
00048 
00052   virtual void StartElement(const char * name,const char **atts) = 0;
00053 
00057   virtual void EndElement(const char *name) = 0;
00058 
00062   virtual void CharacterDataHandler(const char *inData, int inLength) = 0;
00063 protected:
00064 
00069   void parse(void);
00070   std::string m_Filename;
00071 };
00072 
00079 template <class T> class 
00080 XMLReader : public XMLReaderBase
00081 {
00082 public:
00086   void SetOutputObject(T *obj) { m_OutputObject = obj; }
00087 
00090   T *GetOutputObject(void) { return m_OutputObject; }
00091 protected:
00092   T *m_OutputObject;
00093 };
00094 
00103 template <class T>
00104 class XMLWriterBase : public LightProcessObject
00105 {
00106 public:
00110   XMLWriterBase() {
00111     m_InputObject = 0;
00112   }
00113 
00115   itkSetStringMacro(Filename);
00116 
00118   itkGetStringMacro(Filename);
00119 
00121   virtual int CanWriteFile(const char* name) = 0;
00122 
00124   void SetObject(T *toWrite) { m_InputObject = toWrite; }
00125 
00127   virtual int WriteFile() = 0;
00128 
00130   void WriteStartElement(const char *const tag,std::ofstream &file)
00131   {
00132     file << '<' << tag << '>';
00133   }
00134 
00136   void WriteEndElement(const char *const tag,std::ofstream &file) 
00137   {
00138     file << '<' << '/'  << tag << '>';
00139   }
00140 
00142   void WriteCharacterData(const char *const data,std::ofstream &file) 
00143   {
00144     file << data;
00145   }
00146 
00148   void WriteStartElement(std::string &tag,std::ofstream &file) 
00149   {
00150     WriteStartElement(tag.c_str(),file);
00151   }
00152 
00154   void WriteEndElement(std::string &tag,std::ofstream &file) 
00155   {
00156     WriteEndElement(tag.c_str(),file);
00157   }
00158 
00160   void WriteCharacterData(std::string &data,std::ofstream &file)
00161   {
00162     WriteCharacterData(data.c_str(),file);
00163   }
00164 protected:
00165   T *m_InputObject;             // object to write out to an XML file
00166   std::string m_Filename;       // name of file to write.
00167 };
00169 
00170 }
00171 #endif
00172 

Generated at Mon Mar 12 03:34:07 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000