ITK  4.9.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 "ITKIOXMLExport.h"
22 #include <fstream>
23 
24 namespace itk
25 {
34 class ITKIOXML_EXPORT XMLReaderBase:public LightProcessObject
35 {
36 public:
38 
40  itkSetStringMacro(Filename);
41 
43  itkGetStringMacro(Filename);
44 
46  virtual int CanReadFile(const char *name) = 0;
47 
49  virtual void GenerateOutputInformation();
50 
54  virtual void StartElement(const char *name, const char **atts) = 0;
55 
59  virtual void EndElement(const char *name) = 0;
60 
64  virtual void CharacterDataHandler(const char *inData, int inLength) = 0;
65 
66 protected:
68  virtual ~XMLReaderBase() {}
69  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
70 
75  void parse();
76 
77  std::string m_Filename;
78 
79 private:
80  XMLReaderBase(const Self &) ITK_DELETE_FUNCTION;
81  void operator=(const Self &) ITK_DELETE_FUNCTION;
82 };
83 
92 template< typename T >
93 class XMLReader: public XMLReaderBase
94 {
95 public:
96  typedef XMLReader Self;
97 
101  void SetOutputObject(T *obj) { m_OutputObject = obj; }
102 
105  T * GetOutputObject(void) { return m_OutputObject; }
106 
107 protected:
109  m_OutputObject(ITK_NULLPTR)
110  {}
111 
112  virtual ~XMLReader() {}
113 
115 
116 private:
117  XMLReader(const Self &) ITK_DELETE_FUNCTION;
118  void operator=(const Self &) ITK_DELETE_FUNCTION;
119 };
120 
130 template< typename T >
132 {
133 public:
135 
140  {
141  m_InputObject = ITK_NULLPTR;
142  }
143 
145  itkSetStringMacro(Filename);
146 
148  itkGetStringMacro(Filename);
149 
151  virtual int CanWriteFile(const char *name) = 0;
152 
154  void SetObject(T *toWrite) { m_InputObject = toWrite; }
155 
157  virtual int WriteFile() = 0;
158 
160  void WriteStartElement(const char *const tag, std::ofstream & file)
161  {
162  file << '<' << tag << '>';
163  }
164 
166  void WriteEndElement(const char *const tag, std::ofstream & file)
167  {
168  file << '<' << '/' << tag << '>';
169  }
170 
172  void WriteCharacterData(const char *const data, std::ofstream & file)
173  {
174  file << data;
175  }
176 
178  void WriteStartElement(std::string & tag, std::ofstream & file)
179  {
180  WriteStartElement(tag.c_str(), file);
181  }
182 
184  void WriteEndElement(std::string & tag, std::ofstream & file)
185  {
186  WriteEndElement(tag.c_str(), file);
187  }
188 
190  void WriteCharacterData(std::string & data, std::ofstream & file)
191  {
192  WriteCharacterData(data.c_str(), file);
193  }
194 
195 protected:
196  T *m_InputObject; // object to write out to an XML file
197  std::string m_Filename; // name of file to write.
198 
199 private:
200  XMLWriterBase(const Self &) ITK_DELETE_FUNCTION;
201  void operator=(const Self &) ITK_DELETE_FUNCTION;
202 };
203 }
204 #endif
virtual ~XMLReaderBase()
Definition: itkXMLFile.h:68
T * GetOutputObject(void)
Definition: itkXMLFile.h:105
Light weight base class for most itk classes.
std::string m_Filename
Definition: itkXMLFile.h:77
XMLReaderBase Self
Definition: itkXMLFile.h:37
void SetOutputObject(T *obj)
Definition: itkXMLFile.h:101
void SetObject(T *toWrite)
Definition: itkXMLFile.h:154
template base class for an XMLReader It&#39;s purpose really is just to define the simple interface for e...
Definition: itkXMLFile.h:93
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
XMLWriterBase Self
Definition: itkXMLFile.h:134
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void WriteStartElement(const char *const tag, std::ofstream &file)
Definition: itkXMLFile.h:160
XMLReader Self
Definition: itkXMLFile.h:96
virtual ~XMLReader()
Definition: itkXMLFile.h:112