ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkOutputStreamBase.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 itkOutputStreamBase_h
19#define itkOutputStreamBase_h
20
21#include "itkPipeline.h"
22#include "itkWasmStringStream.h"
23
24#include <string>
25#ifndef ITK_WASM_NO_MEMORY_IO
26# include <sstream>
27#endif
28#ifndef ITK_WASM_NO_FILESYSTEM_IO
29# include <fstream>
30#endif
31
32#include "WebAssemblyInterfaceExport.h"
33
34namespace itk
35{
36namespace wasm
37{
38
49class WebAssemblyInterface_EXPORT OutputStreamBase
50{
51public:
52 std::ostream &
54 {
55 return *m_OStream;
56 }
57
58 virtual void
59 SetFileName(const std::string & fileName) = 0;
60
62 void
63 SetIdentifier(const std::string & identifier)
64 {
65 if (m_DeleteOStream && m_OStream != nullptr)
66 {
67 delete m_OStream;
68 }
69 m_DeleteOStream = false;
71
72 m_OStream = &(m_WasmStringStream->GetStringStream());
73 this->m_Identifier = identifier;
74 }
75 const std::string &
77 {
78 return this->m_Identifier;
79 }
80
81protected:
82 OutputStreamBase() = default;
84
85 void
86 SetFile(const std::string & fileName, const std::ios_base::openmode openMode)
87 {
88 if (m_DeleteOStream && m_OStream != nullptr)
89 {
90 delete m_OStream;
91 }
92 m_OStream = new std::ofstream(fileName, openMode);
93 m_DeleteOStream = true;
94 }
95
96private:
97 std::ostream * m_OStream{ nullptr };
98 bool m_DeleteOStream{ false };
99
100 std::string m_Identifier;
101
103};
104
105
106WebAssemblyInterface_EXPORT bool
107lexical_cast(const std::string & output, OutputStreamBase & outputStream);
108
109} // end namespace wasm
110} // end namespace itk
111
112#endif
SmartPointer< Self > Pointer
static Pointer New()
Base class of output stream for an itk::wasm::Pipeline.
void SetIdentifier(const std::string &identifier)
WasmStringStream::Pointer m_WasmStringStream
virtual void SetFileName(const std::string &fileName)=0
void SetFile(const std::string &fileName, const std::ios_base::openmode openMode)
const std::string & GetIdentifier() const
bool lexical_cast(const std::string &input, InputImage< TImage > &inputImage)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....