Commit 6a6e5300 authored by Brad King's avatar Brad King Committed by Code Review
Browse files

Merge topic 'iostream-pos-off-types' into master

6d2b9838 vtk(Input|Output)Stream: Use appropriate types in API
122b241e Define vtkIOStream(Pos|Off) as portable std::stream(pos|off)
parents b81646d4 6d2b9838
......@@ -60,6 +60,9 @@ using std::fstream;
#pragma warning(pop)
#endif
typedef std::streampos vtkIOStreamPos;
typedef std::streamoff vtkIOStreamOff;
#else
// Include old-style streams.
......
......@@ -45,6 +45,9 @@ using std::fstream;
#pragma warning(pop)
#endif
typedef std::streampos vtkIOStreamPos;
typedef std::streamoff vtkIOStreamOff;
#else
# ifdef __BORLANDC__
# include <iosfwd.h>
......
......@@ -64,9 +64,9 @@ void vtkBase64InputStream::EndReading()
}
//----------------------------------------------------------------------------
int vtkBase64InputStream::Seek(unsigned long offset)
int vtkBase64InputStream::Seek(vtkIOStreamOff offset)
{
unsigned long triplet = offset/3;
vtkIOStreamOff triplet = offset/3;
int skipLength = offset%3;
// Seek to the beginning of the encoded triplet containing the
......@@ -100,11 +100,11 @@ int vtkBase64InputStream::Seek(unsigned long offset)
}
//----------------------------------------------------------------------------
unsigned long vtkBase64InputStream::Read(unsigned char* data,
unsigned long length)
size_t vtkBase64InputStream::Read(void* data_in, size_t length)
{
unsigned char* data = static_cast<unsigned char*>(data_in);
unsigned char* out = data;
unsigned char* end = data + length;
unsigned char* end = out + length;
// If the previous read ended before filling buffer, don't read
// more.
......
......@@ -39,12 +39,12 @@ public:
// Description:
// Seek to the given offset in the input data. Returns 1 for
// success, 0 for failure.
int Seek(unsigned long offset);
int Seek(vtkIOStreamOff offset);
// Description:
// Read input data of the given length. Returns amount actually
// read.
unsigned long Read(unsigned char* data, unsigned long length);
size_t Read(void* data, size_t length);
// Description:
// Called after all desired calls to Seek and Read have been made.
......
......@@ -97,12 +97,11 @@ int vtkBase64OutputStream::EndWriting()
}
//----------------------------------------------------------------------------
int vtkBase64OutputStream::Write(const unsigned char* data,
unsigned long length)
int vtkBase64OutputStream::Write(void const* data, size_t length)
{
unsigned long totalLength = this->BufferLength + length;
const unsigned char* in = data;
const unsigned char* end = data+length;
size_t totalLength = this->BufferLength + length;
unsigned char const* in = static_cast<unsigned char const*>(data);
unsigned char const* end = in+length;
if(totalLength >= 3)
{
......
......@@ -38,7 +38,7 @@ public:
// Description:
// Write output data of the given length.
int Write(const unsigned char* data, unsigned long length);
int Write(void const* data, size_t length);
// Description:
// Called after all desired calls to Write have been made. After
......
......@@ -52,19 +52,19 @@ void vtkInputStream::EndReading()
}
//----------------------------------------------------------------------------
int vtkInputStream::Seek(unsigned long offset)
int vtkInputStream::Seek(vtkIOStreamOff offset)
{
return (this->Stream->seekg(this->StreamStartPosition+offset)? 1:0);
}
//----------------------------------------------------------------------------
unsigned long vtkInputStream::Read(unsigned char* data, unsigned long length)
size_t vtkInputStream::Read(void* data, size_t length)
{
return this->Read(reinterpret_cast<char*>(data), length);
return this->ReadStream(static_cast<char*>(data), length);
}
//----------------------------------------------------------------------------
unsigned long vtkInputStream::Read(char* data, unsigned long length)
size_t vtkInputStream::ReadStream(char* data, size_t length)
{
this->Stream->read(data, length);
return this->Stream->gcount();
......
......@@ -50,13 +50,12 @@ public:
// Description:
// Seek to the given offset in the input data. Returns 1 for
// success, 0 for failure.
virtual int Seek(unsigned long offset);
virtual int Seek(vtkIOStreamOff offset);
// Description:
// Read input data of the given length. Returns amount actually
// read.
virtual unsigned long Read(unsigned char* data, unsigned long length);
unsigned long Read(char* data, unsigned long length);
virtual size_t Read(void* data, size_t length);
// Description:
// Called after all desired calls to Seek and Read have been made.
......@@ -71,9 +70,10 @@ protected:
// The real input stream.
istream* Stream;
size_t ReadStream(char* data, size_t length);
// The input stream's position when StartReading was called.
unsigned long StreamStartPosition;
vtkIOStreamPos StreamStartPosition;
private:
vtkInputStream(const vtkInputStream&); // Not implemented.
......
......@@ -54,13 +54,13 @@ int vtkOutputStream::EndWriting()
}
//----------------------------------------------------------------------------
int vtkOutputStream::Write(const unsigned char* data, unsigned long length)
int vtkOutputStream::Write(void const* data, size_t length)
{
return this->Write(reinterpret_cast<const char*>(data), length);
return this->WriteStream(static_cast<const char*>(data), length);
}
//----------------------------------------------------------------------------
int vtkOutputStream::Write(const char* data, unsigned long length)
int vtkOutputStream::WriteStream(const char* data, size_t length)
{
return (this->Stream->write(data, length)? 1:0);
}
......@@ -49,8 +49,7 @@ public:
// Description:
// Write output data of the given length.
virtual int Write(const unsigned char* data, unsigned long length);
int Write(const char* data, unsigned long length);
virtual int Write(void const* data, size_t length);
// Description:
// Called after all desired calls to Write have been made. After
......@@ -65,6 +64,7 @@ protected:
// The real output stream.
ostream* Stream;
int WriteStream(const char* data, size_t length);
private:
vtkOutputStream(const vtkOutputStream&); // Not implemented.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment