Skip to content

Commit

Permalink
feat: add tell() and error() functions to istream + ostream devices (#…
Browse files Browse the repository at this point in the history
…747)

The class file_stream_device already has such functions, and now
both istream_device and ostream_device have them, too, making the
device classes more consistent.

Closes #724
  • Loading branch information
striezel authored May 17, 2024
1 parent abb561a commit 481b6e7
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion include/boost/gil/io/device.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny
// Copyright 2024 Dirk Stolle
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
Expand Down Expand Up @@ -409,13 +410,29 @@ class istream_device
);
}

long int tell()
{
auto pos = _in.tellg();

io_error_if( pos == std::istream::pos_type(-1)
, "istream_device: file position error"
);

return static_cast<long int>(pos);
}

void write(const byte_t*, std::size_t)
{
io_error( "istream_device: Bad io error." );
}

void flush() {}

int error()
{
return _in.fail();
}

private:

std::istream& _in;
Expand Down Expand Up @@ -450,6 +467,17 @@ class ostream_device
);
}

long int tell()
{
auto pos = _out.tellp();

io_error_if( pos == std::ostream::pos_type(-1)
, "ostream_device: file position error"
);

return static_cast<long int>(pos);
}

void write( const byte_t* data
, std::size_t count )
{
Expand Down Expand Up @@ -509,7 +537,10 @@ class ostream_device
_out << line;
}


int error()
{
return _out.fail();
}

private:

Expand Down

0 comments on commit 481b6e7

Please sign in to comment.