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: 2007-03-17 21:02:11 $
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     {
00112     m_InputObject = 0;
00113     }
00114 
00116   itkSetStringMacro(Filename);
00117 
00119   itkGetStringMacro(Filename);
00120 
00122   virtual int CanWriteFile(const char* name) = 0;
00123 
00125   void SetObject(T *toWrite) { m_InputObject = toWrite; }
00126 
00128   virtual int WriteFile() = 0;
00129 
00131   void WriteStartElement(const char *const tag,std::ofstream &file)
00132     {
00133     file << '<' << tag << '>';
00134     }
00135 
00137   void WriteEndElement(const char *const tag,std::ofstream &file) 
00138     {
00139     file << '<' << '/'  << tag << '>';
00140     }
00141 
00143   void WriteCharacterData(const char *const data,std::ofstream &file) 
00144     {
00145     file << data;
00146     }
00147 
00149   void WriteStartElement(std::string &tag,std::ofstream &file) 
00150     {
00151     WriteStartElement(tag.c_str(),file);
00152     }
00153 
00155   void WriteEndElement(std::string &tag,std::ofstream &file) 
00156     {
00157     WriteEndElement(tag.c_str(),file);
00158     }
00159 
00161   void WriteCharacterData(std::string &data,std::ofstream &file)
00162     {
00163     WriteCharacterData(data.c_str(),file);
00164     }
00165 protected:
00166   T          *m_InputObject;    // object to write out to an XML file
00167   std::string m_Filename;       // name of file to write.
00168 };
00170 
00171 }
00172 #endif
00173 

Generated at Mon Apr 14 15:05:12 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000