Skip to content

Commit 4f2ba74

Browse files
committed
feat: Let InputBinaryStream inherit from InputStreamBase
Very much reduces the amount of duplicate code. Adds the ability to call `GetPointer()` on an InputBinaryStream, just like it was already supported on an InputTextStream.
1 parent 2775c4c commit 4f2ba74

File tree

3 files changed

+6
-117
lines changed

3 files changed

+6
-117
lines changed

include/itkInputBinaryStream.h

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@
2020

2121
#include "itkPipeline.h"
2222
#include "itkWasmStringStream.h"
23+
#include "itkInputStreamBase.h"
2324

2425
#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>
3128

3229
#include "WebAssemblyInterfaceExport.h"
3330

@@ -40,66 +37,18 @@ namespace wasm
4037
*\class InputBinaryStream
4138
* \brief Input binary std::istream for an itk::wasm::Pipeline
4239
*
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-
*
4740
* \ingroup WebAssemblyInterface
4841
*/
49-
class WebAssemblyInterface_EXPORT InputBinaryStream
42+
class WebAssemblyInterface_EXPORT InputBinaryStream : public InputStreamBase
5043
{
5144
public:
52-
std::istream &
53-
Get()
54-
{
55-
return *m_IStream;
56-
}
57-
5845
void
59-
SetJSON(const std::string & json)
46+
SetFileName(const std::string & fileName) override
6047
{
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);
7049
}
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;
9750
};
9851

99-
100-
WebAssemblyInterface_EXPORT bool
101-
lexical_cast(const std::string & input, InputBinaryStream & inputStream);
102-
10352
} // end namespace wasm
10453
} // end namespace itk
10554

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ set(WebAssemblyInterface_SRCS
1616
itkWasmStringStream.cxx
1717
itkInputStreamBase.cxx
1818
itkOutputTextStream.cxx
19-
itkInputBinaryStream.cxx
2019
itkOutputBinaryStream.cxx
2120
itkIOComponentEnumFromWasmComponentType.cxx
2221
itkIOPixelEnumFromWasmPixelType.cxx

src/itkInputBinaryStream.cxx

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)