ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
117 T *
119 {
120 return m_OutputObject;
121 }
122
123protected:
125 : m_OutputObject(nullptr)
126 {}
127
128 ~XMLReader() override = default;
129
131};
132
143template <typename T>
144class ITK_TEMPLATE_EXPORT XMLWriterBase : public LightProcessObject
145{
146public:
147 ITK_DISALLOW_COPY_AND_MOVE(XMLWriterBase);
148
150
155 : m_InputObject(nullptr)
156 {}
157
159 itkSetStringMacro(Filename);
161 itkGetStringMacro(Filename);
163 virtual int
164 CanWriteFile(const char * name) = 0;
165
167 void
168 SetObject(T * toWrite)
169 {
170 m_InputObject = toWrite;
171 }
172
173 virtual int
175
176#if !defined(ITK_WRAPPING_PARSER)
178 void
179 WriteStartElement(const char * const tag, std::ofstream & file)
180 {
181 file << '<' << tag << '>';
182 }
183
185 void
186 WriteEndElement(const char * const tag, std::ofstream & file)
187 {
188 file << '<' << '/' << tag << '>';
189 }
190
192 void
193 WriteCharacterData(const char * const data, std::ofstream & file)
194 {
195 file << data;
196 }
197
199 void
200 WriteStartElement(std::string & tag, std::ofstream & file)
201 {
202 WriteStartElement(tag.c_str(), file);
203 }
204
206 void
207 WriteEndElement(std::string & tag, std::ofstream & file)
208 {
209 WriteEndElement(tag.c_str(), file);
210 }
211
213 void
214 WriteCharacterData(std::string & data, std::ofstream & file)
215 {
216 WriteCharacterData(data.c_str(), file);
217 }
218#endif
219
220protected:
221 T * m_InputObject{}; // object to write out to an XML file
222 std::string m_Filename{}; // name of file to write.
223};
224} // namespace itk
225#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
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
XMLReaderBase Self
Definition itkXMLFile.h:40
virtual void StartElement(const char *name, const char **atts)=0
XMLReaderBase()=default
std::string m_Filename
Definition itkXMLFile.h:87
void PrintSelf(std::ostream &os, Indent indent) const override
~XMLReader() override=default
T * GetOutputObject()
Definition itkXMLFile.h:118
XMLReader Self
Definition itkXMLFile.h:105
GroupSpatialObject< 3 > * m_OutputObject
Definition itkXMLFile.h:130
void SetOutputObject(T *obj)
Definition itkXMLFile.h:111
virtual int WriteFile()=0
void WriteStartElement(std::string &tag, std::ofstream &file)
Definition itkXMLFile.h:200
void WriteCharacterData(std::string &data, std::ofstream &file)
Definition itkXMLFile.h:214
void WriteEndElement(std::string &tag, std::ofstream &file)
Definition itkXMLFile.h:207
void WriteStartElement(const char *const tag, std::ofstream &file)
Definition itkXMLFile.h:179
virtual int CanWriteFile(const char *name)=0
void WriteCharacterData(const char *const data, std::ofstream &file)
Definition itkXMLFile.h:193
void WriteEndElement(const char *const tag, std::ofstream &file)
Definition itkXMLFile.h:186
void SetObject(T *toWrite)
Definition itkXMLFile.h:168
XMLWriterBase Self
Definition itkXMLFile.h:149
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....