Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tell() and error() functions to istream + ostream devices #747

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading