ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkXMLFile.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkXMLFile_h
19 #define __itkXMLFile_h
20 #include "itkLightProcessObject.h"
21 #include <fstream>
22 
23 namespace itk
24 {
34 {
35 public:
37 
39  itkSetStringMacro(Filename);
40 
42  itkGetStringMacro(Filename);
43 
45  virtual int CanReadFile(const char *name) = 0;
46 
48  virtual void GenerateOutputInformation();
49 
53  virtual void StartElement(const char *name, const char **atts) = 0;
54 
58  virtual void EndElement(const char *name) = 0;
59 
63  virtual void CharacterDataHandler(const char *inData, int inLength) = 0;
64 
65 protected:
67  virtual ~XMLReaderBase() {}
68  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
69 
74  void parse(void);
75 
76  std::string m_Filename;
77 
78 private:
79  XMLReaderBase(const Self &); //purposely not implemented
80  void operator=(const Self &); //purposely not implemented
81 };
82 
91 template< typename T >
92 class XMLReader: public XMLReaderBase
93 {
94 public:
95  typedef XMLReader Self;
96 
100  void SetOutputObject(T *obj) { m_OutputObject = obj; }
101 
104  T * GetOutputObject(void) { return m_OutputObject; }
105 
106 protected:
108  m_OutputObject(ITK_NULLPTR)
109  {}
110 
111  virtual ~XMLReader() {}
112 
114 
115 private:
116  XMLReader(const Self &); //purposely not implemented
117  void operator=(const Self &); //purposely not implemented
118 };
119 
129 template< typename T >
131 {
132 public:
134 
139  {
140  m_InputObject = ITK_NULLPTR;
141  }
142 
144  itkSetStringMacro(Filename);
145 
147  itkGetStringMacro(Filename);
148 
150  virtual int CanWriteFile(const char *name) = 0;
151 
153  void SetObject(T *toWrite) { m_InputObject = toWrite; }
154 
156  virtual int WriteFile() = 0;
157 
159  void WriteStartElement(const char *const tag, std::ofstream & file)
160  {
161  file << '<' << tag << '>';
162  }
163 
165  void WriteEndElement(const char *const tag, std::ofstream & file)
166  {
167  file << '<' << '/' << tag << '>';
168  }
169 
171  void WriteCharacterData(const char *const data, std::ofstream & file)
172  {
173  file << data;
174  }
175 
177  void WriteStartElement(std::string & tag, std::ofstream & file)
178  {
179  WriteStartElement(tag.c_str(), file);
180  }
181 
183  void WriteEndElement(std::string & tag, std::ofstream & file)
184  {
185  WriteEndElement(tag.c_str(), file);
186  }
187 
189  void WriteCharacterData(std::string & data, std::ofstream & file)
190  {
191  WriteCharacterData(data.c_str(), file);
192  }
193 
194 protected:
195  T *m_InputObject; // object to write out to an XML file
196  std::string m_Filename; // name of file to write.
197 
198 private:
199  XMLWriterBase(const Self &); //purposely not implemented
200  void operator=(const Self &); //purposely not implemented
201 };
202 }
203 #endif
virtual ~XMLReaderBase()
Definition: itkXMLFile.h:67
T * GetOutputObject(void)
Definition: itkXMLFile.h:104
Light weight base class for most itk classes.
virtual int WriteFile()=0
std::string m_Filename
Definition: itkXMLFile.h:76
XMLReaderBase Self
Definition: itkXMLFile.h:36
void SetOutputObject(T *obj)
Definition: itkXMLFile.h:100
void operator=(const Self &)
virtual int CanReadFile(const char *name)=0
virtual int CanWriteFile(const char *name)=0
virtual void EndElement(const char *name)=0
void SetObject(T *toWrite)
Definition: itkXMLFile.h:153
virtual void StartElement(const char *name, const char **atts)=0
virtual void CharacterDataHandler(const char *inData, int inLength)=0
template base class for an XMLReader It&#39;s purpose really is just to define the simple interface for e...
Definition: itkXMLFile.h:92
virtual void GenerateOutputInformation()
void operator=(const Self &)
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
XMLWriterBase Self
Definition: itkXMLFile.h:133
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void WriteStartElement(const char *const tag, std::ofstream &file)
Definition: itkXMLFile.h:159
XMLReader Self
Definition: itkXMLFile.h:95
virtual ~XMLReader()
Definition: itkXMLFile.h:111
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE