|
18 | 18 | #ifndef itkInputStreamBase_h
|
19 | 19 | #define itkInputStreamBase_h
|
20 | 20 |
|
21 |
| -#include "itkPipeline.h" |
22 |
| -#include "itkWasmStringStream.h" |
23 |
| - |
| 21 | +#include <ios> |
| 22 | +#include <iosfwd> // For istream. |
| 23 | +#include <memory> // For unique_ptr. |
24 | 24 | #include <string>
|
25 |
| -#include <sstream> |
26 |
| -#include <fstream> |
27 | 25 |
|
28 | 26 | #include "WebAssemblyInterfaceExport.h"
|
29 | 27 |
|
@@ -54,52 +52,30 @@ class WebAssemblyInterface_EXPORT InputStreamBase
|
54 | 52 | std::istream *
|
55 | 53 | GetPointer()
|
56 | 54 | {
|
57 |
| - return m_IStream; |
| 55 | + return m_IStream.get(); |
58 | 56 | }
|
59 | 57 |
|
60 | 58 | void
|
61 |
| - SetJSON(const std::string & json) |
62 |
| - { |
63 |
| - if (m_DeleteIStream && m_IStream != nullptr) |
64 |
| - { |
65 |
| - delete m_IStream; |
66 |
| - } |
67 |
| - m_DeleteIStream = false; |
68 |
| - m_WasmStringStream = WasmStringStream::New(); |
69 |
| - m_WasmStringStream->SetJSON(json.c_str()); |
70 |
| - |
71 |
| - m_IStream = &(m_WasmStringStream->GetStringStream()); |
72 |
| - } |
| 59 | + SetJSON(const std::string & json); |
73 | 60 |
|
74 | 61 | virtual void
|
75 | 62 | SetFileName(const std::string & fileName) = 0;
|
76 | 63 |
|
77 | 64 | protected:
|
78 | 65 | void
|
79 |
| - SetFile(const std::string & fileName, const std::ios_base::openmode openMode) |
80 |
| - { |
81 |
| - if (m_DeleteIStream && m_IStream != nullptr) |
82 |
| - { |
83 |
| - delete m_IStream; |
84 |
| - } |
85 |
| - m_IStream = new std::ifstream(fileName, openMode); |
86 |
| - m_DeleteIStream = true; |
87 |
| - } |
| 66 | + SetFile(const std::string & fileName, const std::ios_base::openmode openMode); |
88 | 67 |
|
89 | 68 | InputStreamBase() = default;
|
90 |
| - virtual ~InputStreamBase() |
91 |
| - { |
92 |
| - if (m_DeleteIStream && m_IStream != nullptr) |
93 |
| - { |
94 |
| - delete m_IStream; |
95 |
| - } |
96 |
| - } |
97 | 69 |
|
98 |
| -private: |
99 |
| - std::istream * m_IStream{ nullptr }; |
100 |
| - bool m_DeleteIStream{ false }; |
| 70 | + // Move semantics for its derived classes: |
| 71 | + InputStreamBase(InputStreamBase &&) = default; |
| 72 | + InputStreamBase & |
| 73 | + operator=(InputStreamBase &&) = default; |
101 | 74 |
|
102 |
| - WasmStringStream::Pointer m_WasmStringStream; |
| 75 | + virtual ~InputStreamBase(); |
| 76 | + |
| 77 | +private: |
| 78 | + std::unique_ptr<std::istream> m_IStream; |
103 | 79 | };
|
104 | 80 |
|
105 | 81 |
|
|
0 commit comments