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: 2008-05-13 18:48:32 $
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:
00037   typedef XMLReaderBase Self;
00038 
00040   itkSetStringMacro(Filename);
00041 
00043   itkGetStringMacro(Filename);
00044 
00046   virtual int CanReadFile(const char* name) = 0;
00047 
00049   virtual void GenerateOutputInformation();
00050 
00054   virtual void StartElement(const char * name,const char **atts) = 0;
00055 
00059   virtual void EndElement(const char *name) = 0;
00060 
00064   virtual void CharacterDataHandler(const char *inData, int inLength) = 0;
00065 protected:
00066   XMLReaderBase() {};
00067   virtual ~XMLReaderBase() {};
00069 
00074   void parse(void);
00075   std::string m_Filename;
00076 
00077 private:
00078   XMLReaderBase(const Self&); //purposely not implemented
00079   void operator=(const Self&); //purposely not implemented
00080 
00081 };
00082 
00089 template <class T> class 
00090 XMLReader : public XMLReaderBase
00091 {
00092 public:
00093   typedef XMLReader Self;
00094 
00098   void SetOutputObject(T *obj) { m_OutputObject = obj; }
00099 
00102   T *GetOutputObject(void) { return m_OutputObject; }
00103 protected:
00104   XMLReader() {};
00105   virtual ~XMLReader() {};
00107 
00108   T *m_OutputObject;
00109 
00110 private:
00111   XMLReader(const Self&); //purposely not implemented
00112   void operator=(const Self&); //purposely not implemented
00113 };
00114 
00123 template <class T>
00124 class XMLWriterBase : public LightProcessObject
00125 {
00126 public:
00127   typedef XMLWriterBase Self;
00128 
00132   XMLWriterBase()
00133     {
00134     m_InputObject = 0;
00135     }
00136 
00138   itkSetStringMacro(Filename);
00139 
00141   itkGetStringMacro(Filename);
00142 
00144   virtual int CanWriteFile(const char* name) = 0;
00145 
00147   void SetObject(T *toWrite) { m_InputObject = toWrite; }
00148 
00150   virtual int WriteFile() = 0;
00151 
00153   void WriteStartElement(const char *const tag,std::ofstream &file)
00154     {
00155     file << '<' << tag << '>';
00156     }
00157 
00159   void WriteEndElement(const char *const tag,std::ofstream &file) 
00160     {
00161     file << '<' << '/'  << tag << '>';
00162     }
00163 
00165   void WriteCharacterData(const char *const data,std::ofstream &file) 
00166     {
00167     file << data;
00168     }
00169 
00171   void WriteStartElement(std::string &tag,std::ofstream &file) 
00172     {
00173     WriteStartElement(tag.c_str(),file);
00174     }
00175 
00177   void WriteEndElement(std::string &tag,std::ofstream &file) 
00178     {
00179     WriteEndElement(tag.c_str(),file);
00180     }
00181 
00183   void WriteCharacterData(std::string &data,std::ofstream &file)
00184     {
00185     WriteCharacterData(data.c_str(),file);
00186     }
00187 protected:
00188   T          *m_InputObject;    // object to write out to an XML file
00189   std::string m_Filename;       // name of file to write.
00191 
00192 private:
00193   XMLWriterBase(const Self&); //purposely not implemented
00194   void operator=(const Self&); //purposely not implemented
00195 };
00196 
00197 }
00198 #endif
00199 

Generated at Wed Jul 30 00:07:00 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000