diff --git a/CMakeLists.txt b/CMakeLists.txt index f6dcab3..3047e44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,8 +112,8 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities") set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local) set(META_VERSION_MAJOR 5) -set(META_VERSION_MINOR 0) -set(META_VERSION_PATCH 2) +set(META_VERSION_MINOR 1) +set(META_VERSION_PATCH 0) # find required 3rd party libraries include(3rdParty) diff --git a/io/binaryreader.cpp b/io/binaryreader.cpp index c2ca799..e111d1b 100644 --- a/io/binaryreader.cpp +++ b/io/binaryreader.cpp @@ -44,10 +44,9 @@ void BinaryReader::setStream(istream *stream, bool giveOwnership) /*! * \brief Returns the size of the assigned stream. - * - * The size is determined by seeking to the end of the stream and returning this offset. - * - * \remarks The method will seek back to the previous offset before returning. + * \remarks + * - The size is determined by seeking to the end of the stream and returning this offset. + * - The method will seek back to the previous offset before returning. */ istream::pos_type BinaryReader::readStreamsize() { @@ -58,6 +57,21 @@ istream::pos_type BinaryReader::readStreamsize() return streamsize; } +/*! + * \brief Returns the number of remaining bytes in the stream from the current offset. + * \remarks + * - This is achieved by seeking to the end of the stream. + * - The method will seek back to the previous offset before returning. + */ +istream::pos_type BinaryReader::readRemainingBytes() +{ + istream::pos_type cp = m_stream->tellg(); + m_stream->seekg(0, ios_base::end); + const auto streamsize = m_stream->tellg(); + m_stream->seekg(cp); + return streamsize - cp; +} + void BinaryReader::bufferVariableLengthInteger() { static constexpr int maxPrefixLength = 8; diff --git a/io/binaryreader.h b/io/binaryreader.h index 49fd4cd..253c8d7 100644 --- a/io/binaryreader.h +++ b/io/binaryreader.h @@ -26,6 +26,7 @@ public: bool eof() const; bool canRead() const; std::istream::pos_type readStreamsize(); + std::istream::pos_type readRemainingBytes(); void read(char *buffer, std::streamsize length); void read(std::uint8_t *buffer, std::streamsize length); void read(std::vector &buffer, std::streamsize length); diff --git a/tests/iotests.cpp b/tests/iotests.cpp index f18dd94..6582f1b 100644 --- a/tests/iotests.cpp +++ b/tests/iotests.cpp @@ -92,6 +92,7 @@ void IoTests::testBinaryReader() BinaryReader reader(&testFile); CPPUNIT_ASSERT_EQUAL(reader.readStreamsize(), static_cast(398)); CPPUNIT_ASSERT(reader.readUInt16LE() == 0x0102u); + CPPUNIT_ASSERT_EQUAL(reader.readRemainingBytes(), static_cast(396)); CPPUNIT_ASSERT(reader.readUInt16BE() == 0x0102u); CPPUNIT_ASSERT(reader.readUInt24LE() == 0x010203u); CPPUNIT_ASSERT(reader.readUInt24BE() == 0x010203u);