Merge pull request #3794 from mapycz/char_array_buffer-seekpos

char_array_buffer should implement also seekpos()
This commit is contained in:
Artem Pavlenko 2017-11-14 09:55:43 +01:00 committed by GitHub
commit 2cd335509b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -68,6 +68,13 @@ private:
return end_ - current_; return end_ - current_;
} }
pos_type seekpos(pos_type off,
std::ios_base::openmode /*which*/)
{
current_ = std::min(begin_ + off, end_);
return pos_type(off_type(current_ - begin_));
}
pos_type seekoff(off_type off, std::ios_base::seekdir dir, pos_type seekoff(off_type off, std::ios_base::seekdir dir,
std::ios_base::openmode which = std::ios_base::in | std::ios_base::out ) std::ios_base::openmode which = std::ios_base::in | std::ios_base::out )
{ {

View file

@ -0,0 +1,19 @@
#include "catch.hpp"
#include <mapnik/util/char_array_buffer.hpp>
#include <istream>
TEST_CASE("char_array_buffer") {
SECTION("std::istream seekg, tellg") {
const std::size_t buffer_size = 66;
char buffer[buffer_size];
mapnik::util::char_array_buffer array_buff(buffer, buffer_size);
std::istream stream(&array_buff);
CHECK(stream.seekg(0).tellg() == 0);
CHECK(stream.seekg(buffer_size).tellg() == buffer_size);
CHECK(stream.seekg(70).tellg() == buffer_size);
}
}