From ee568435999692c83d7099683818a6137c5db60a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 23 Jan 2020 15:02:39 +0100 Subject: [PATCH] Split InputReader into InputReader and StreamInputReader. Backported from 0981aef3083080030445c9510523e6247ea5e302 in master. --- src/stl_binary_reader.cc | 41 ++++++++++++++++++++++++++-------------- 1 file 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(_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(_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()); -- 2.30.2