1818#ifndef itkOutputBinaryStream_h
1919#define itkOutputBinaryStream_h
2020
21- #include " itkPipeline.h"
22- #include " itkWasmStringStream.h"
21+ #include " itkOutputStreamBase.h"
2322
23+ #include < ios>
2424#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"
3325
3426namespace itk
3527{
@@ -38,70 +30,20 @@ namespace wasm
3830
3931/* *
4032 *\class OutputBinaryStream
41- * \brief Output text std::ostream for an itk::wasm::Pipeline
42- *
43- * This stream is written to the filesystem or memory when the object goes out of scope.
44- *
45- * Call `Get()` to get the std::ostream & to use an output for a pipeline.
33+ * \brief Output binary std::ostream for an itk::wasm::Pipeline
4634 *
4735 * \ingroup WebAssemblyInterface
4836 */
49- class WebAssemblyInterface_EXPORT OutputBinaryStream
37+ class OutputBinaryStream : public OutputStreamBase
5038{
5139public:
52- std::ostream &
53- Get ()
54- {
55- return *m_OStream;
56- }
57-
5840 void
59- SetFileName (const std::string & fileName)
41+ SetFileName (const std::string & fileName) override
6042 {
61- if (m_DeleteOStream && m_OStream != nullptr )
62- {
63- delete m_OStream;
64- }
65- m_OStream = new std::ofstream (fileName, std::ofstream::out | std::ofstream::binary);
66- m_DeleteOStream = true ;
43+ OutputStreamBase::SetFile (fileName, std::ios_base::binary);
6744 }
68-
69- OutputBinaryStream () = default ;
70- ~OutputBinaryStream ();
71-
72- /* * Output index. */
73- void
74- SetIdentifier (const std::string & identifier)
75- {
76- if (m_DeleteOStream && m_OStream != nullptr )
77- {
78- delete m_OStream;
79- }
80- m_DeleteOStream = false ;
81- m_WasmStringStream = WasmStringStream::New ();
82-
83- m_OStream = &(m_WasmStringStream->GetStringStream ());
84- this ->m_Identifier = identifier;
85- }
86- const std::string &
87- GetIdentifier () const
88- {
89- return this ->m_Identifier ;
90- }
91-
92- private:
93- std::ostream * m_OStream{ nullptr };
94- bool m_DeleteOStream{ false };
95-
96- std::string m_Identifier;
97-
98- WasmStringStream::Pointer m_WasmStringStream;
9945};
10046
101-
102- WebAssemblyInterface_EXPORT bool
103- lexical_cast (const std::string & output, OutputBinaryStream & outputStream);
104-
10547} // end namespace wasm
10648} // end namespace itk
10749
0 commit comments