20
20
21
21
#include " itkPipeline.h"
22
22
#include " itkWasmStringStream.h"
23
+ #include " itkInputStreamBase.h"
23
24
24
25
#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
26
+ #include < sstream>
27
+ #include < fstream>
31
28
32
29
#include " WebAssemblyInterfaceExport.h"
33
30
@@ -40,66 +37,18 @@ namespace wasm
40
37
*\class InputBinaryStream
41
38
* \brief Input binary std::istream for an itk::wasm::Pipeline
42
39
*
43
- * This stream is read from the filesystem or memory when ITK_WASM_PARSE_ARGS is called.
44
- *
45
- * Call `Get()` to get the std::istream & to use an input to a pipeline.
46
- *
47
40
* \ingroup WebAssemblyInterface
48
41
*/
49
- class WebAssemblyInterface_EXPORT InputBinaryStream
42
+ class WebAssemblyInterface_EXPORT InputBinaryStream : public InputStreamBase
50
43
{
51
44
public:
52
- std::istream &
53
- Get ()
54
- {
55
- return *m_IStream;
56
- }
57
-
58
45
void
59
- SetJSON (const std::string & json)
46
+ SetFileName (const std::string & fileName) override
60
47
{
61
- if (m_DeleteIStream && m_IStream != nullptr )
62
- {
63
- delete m_IStream;
64
- }
65
- m_DeleteIStream = false ;
66
- m_WasmStringStream = WasmStringStream::New ();
67
- m_WasmStringStream->SetJSON (json.c_str ());
68
-
69
- m_IStream = &(m_WasmStringStream->GetStringStream ());
48
+ InputStreamBase::SetFile (fileName, std::ios_base::binary);
70
49
}
71
-
72
- void
73
- SetFileName (const std::string & fileName)
74
- {
75
- if (m_DeleteIStream && m_IStream != nullptr )
76
- {
77
- delete m_IStream;
78
- }
79
- m_IStream = new std::ifstream (fileName, std::ifstream::in | std::ifstream::binary);
80
- m_DeleteIStream = true ;
81
- }
82
-
83
- InputBinaryStream () = default ;
84
- ~InputBinaryStream ()
85
- {
86
- if (m_DeleteIStream && m_IStream != nullptr )
87
- {
88
- delete m_IStream;
89
- }
90
- }
91
-
92
- private:
93
- std::istream * m_IStream{ nullptr };
94
- bool m_DeleteIStream{ false };
95
-
96
- WasmStringStream::Pointer m_WasmStringStream;
97
50
};
98
51
99
-
100
- WebAssemblyInterface_EXPORT bool
101
- lexical_cast (const std::string & input, InputBinaryStream & inputStream);
102
-
103
52
} // end namespace wasm
104
53
} // end namespace itk
105
54
0 commit comments