00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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;
00167 std::string m_Filename;
00168 };
00170
00171 }
00172 #endif
00173