ITK  6.0.0
Insight Toolkit
itkXMLFile.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
21#include "ITKIOXMLExport.h"
22#include <fstream>
23
24namespace itk
25{
35class ITKIOXML_EXPORT XMLReaderBase : public LightProcessObject
36{
37public:
38 ITK_DISALLOW_COPY_AND_MOVE(XMLReaderBase);
39
41
43 itkSetStringMacro(Filename);
44
46 itkGetStringMacro(Filename);
47
49 virtual int
50 CanReadFile(const char * name) = 0;
51
53 virtual void
55
59 virtual void
60 StartElement(const char * name, const char ** atts) = 0;
61
65 virtual void
66 EndElement(const char * name) = 0;
67
71 virtual void
72 CharacterDataHandler(const char * inData, int inLength) = 0;
73
74protected:
75 XMLReaderBase() = default;
76 ~XMLReaderBase() override = default;
77 void
78 PrintSelf(std::ostream & os, Indent indent) const override;
79
84 void
86
87 std::string m_Filename{};
88};
89
99template <typename T>
100class ITK_TEMPLATE_EXPORT XMLReader : public XMLReaderBase
101{
102public:
103 ITK_DISALLOW_COPY_AND_MOVE(XMLReader);
104
106
110 void
112 {
113 m_OutputObject = obj;
114 }
115
118 T *
120 {
121 return m_OutputObject;
122 }
123
124protected:
126 : m_OutputObject(nullptr)
127 {}
128
129 ~XMLReader() override = default;
130
131 T * m_OutputObject{};
132};
133
144template <typename T>
145class ITK_TEMPLATE_EXPORT XMLWriterBase : public LightProcessObject
146{
147public:
148 ITK_DISALLOW_COPY_AND_MOVE(XMLWriterBase);
149
151
155 XMLWriterBase() { m_InputObject = nullptr; }
156
158 itkSetStringMacro(Filename);
159
161 itkGetStringMacro(Filename);
162
164 virtual int
165 CanWriteFile(const char * name) = 0;
166
168 void
169 SetObject(T * toWrite)
170 {
171 m_InputObject = toWrite;
172 }
173
175 virtual int
177
178#if !defined(ITK_WRAPPING_PARSER)
180 void
181 WriteStartElement(const char * const tag, std::ofstream & file)
182 {
183 file << '<' << tag << '>';
184 }
185
187 void
188 WriteEndElement(const char * const tag, std::ofstream & file)
189 {
190 file << '<' << '/' << tag << '>';
191 }
192
194 void
195 WriteCharacterData(const char * const data, std::ofstream & file)
196 {
197 file << data;
198 }
199
201 void
202 WriteStartElement(std::string & tag, std::ofstream & file)
203 {
204 WriteStartElement(tag.c_str(), file);
205 }
206
208 void
209 WriteEndElement(std::string & tag, std::ofstream & file)
210 {
211 WriteEndElement(tag.c_str(), file);
212 }
213
215 void
216 WriteCharacterData(std::string & data, std::ofstream & file)
217 {
218 WriteCharacterData(data.c_str(), file);
219 }
220#endif
221
222protected:
223 T * m_InputObject{}; // object to write out to an XML file
224 std::string m_Filename{}; // name of file to write.
225};
226} // namespace itk
227#endif
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
virtual int CanReadFile(const char *name)=0
virtual void EndElement(const char *name)=0
~XMLReaderBase() override=default
virtual void GenerateOutputInformation()
virtual void CharacterDataHandler(const char *inData, int inLength)=0
virtual void StartElement(const char *name, const char **atts)=0
XMLReaderBase()=default
void PrintSelf(std::ostream &os, Indent indent) const override
template base class for an XMLReader Its purpose really is just to define the simple interface for ex...
Definition: itkXMLFile.h:101
~XMLReader() override=default
T * GetOutputObject()
Definition: itkXMLFile.h:119
void SetOutputObject(T *obj)
Definition: itkXMLFile.h:111
virtual int WriteFile()=0
void WriteStartElement(const char *const tag, std::ofstream &file)
Definition: itkXMLFile.h:181
virtual int CanWriteFile(const char *name)=0
void SetObject(T *toWrite)
Definition: itkXMLFile.h:169
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....