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:59:31 +0100 |
| commit | 0981aef3083080030445c9510523e6247ea5e302 (patch) | |
| tree | c215ceb98d47295b67a9e91b82c08782be4e5cdc /src/stl_binary_reader.cc | |
| parent | 2089fb99e5b289a24ad8aade07a20e0659905143 (diff) | |
Split InputReader into InputReader and StreamInputReader.
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()); |
