diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-01-23 15:02:39 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-01-23 20:20:13 +0000 |
| commit | ee568435999692c83d7099683818a6137c5db60a (patch) | |
| tree | 2d68d8e187aca9a42fa21643f7b4e94c173c8222 /src/stl_binary_reader.cc | |
| parent | 24bf4ff9ca5ae9a994eb4596549ff46a8ad245f5 (diff) | |
Split InputReader into InputReader and StreamInputReader.
Backported from 0981aef3083080030445c9510523e6247ea5e302 in master.
Diffstat (limited to 'src/stl_binary_reader.cc')
| -rw-r--r-- | src/stl_binary_reader.cc | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc index d96059c..f7effdd 100644 --- a/src/stl_binary_reader.cc +++ b/src/stl_binary_reader.cc @@ -41,26 +41,18 @@ using namespace sub; class InputReader : public boost::noncopyable { public: - InputReader (istream& in) - : _in (in) - , _buffer (new unsigned char[1024]) + InputReader () + : _buffer (new unsigned char[1024]) { } - ~InputReader () + virtual ~InputReader () { delete[] _buffer; } - - void read (int size, string what) - { - _in.read (reinterpret_cast<char *>(_buffer), size); - if (_in.gcount() != size) { - throw STLError (String::compose("Could not read %1 block from binary STL file", what)); - } - } + virtual void read (int size, string what) = 0; string get_string (int offset, int length) const { @@ -87,14 +79,35 @@ public: return Time::from_hmsf (_buffer[offset], _buffer[offset + 1], _buffer[offset + 2], _buffer[offset + 3], Rational (frame_rate, 1)); } +protected: + unsigned char* _buffer; +}; + + +class StreamInputReader : public InputReader +{ +public: + StreamInputReader (istream& in) + : _in (in) + { + + } + + void read (int size, string what) + { + _in.read (reinterpret_cast<char *>(_buffer), size); + if (_in.gcount() != size) { + throw STLError (String::compose("Could not read %1 block from binary STL file", what)); + } + } + private: std::istream& _in; - unsigned char* _buffer; }; STLBinaryReader::STLBinaryReader (istream& in) { - InputReader reader (in); + StreamInputReader reader (in); reader.read (1024, "GSI"); code_page_number = atoi (reader.get_string(0, 3).c_str()); |
