BDataIO: Provide default implementations for Read()/Write()

This makes the interface somewhat more suitable for unidirectional use,
since one doesn't have to implement the other, not needed method.
This commit is contained in:
Ingo Weinhold 2014-06-20 15:16:23 +02:00
parent 4e37addd2f
commit 98759fe6e6
3 changed files with 32 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2007 Haiku, Inc. All rights reserved.
* Copyright 2007-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -38,7 +38,7 @@
The interface provided by this class applies to objects or data that are
limited to reading and writing data. Classes derived from this class should
re-implement both the Read() and Write() method from this class.
re-implement the Read() or the Write() method from this class or both.
Candidates of types of data or objects that should be derived from this class
are probably broadcasting media streams (which don't support reading at a
@ -62,22 +62,28 @@
/*!
\fn virtual ssize_t BDataIO::Read(void *buffer, size_t size) = 0
\brief Pure virtual to read data.
\fn virtual ssize_t BDataIO::Read(void *buffer, size_t size)
\brief Reads data from the object into a buffer.
Your implementation should copy data into \c buffer, with the maximum size
of \c size.
\return You should return the amount of bytes actually read, or an error code
in case of failure.
The default implementation is a no-op returning \c B_NOT_SUPPORTED.
\return You should return the amount of bytes actually read, or an error
code in case of failure.
*/
/*!
\fn virtual ssize_t BDataIO::Write(const void *buffer, size_t size) = 0
\brief Pure virtual to write data.
\fn virtual ssize_t BDataIO::Write(const void *buffer, size_t size)
\brief Writes data from a buffer to the object.
Your implementation should copy data from \c buffer, with the maximum size
of \c size.
The default implementation is a no-op returning \c B_NOT_SUPPORTED.
\return You should return the amount of bytes actually written, or an error
code in case of failure.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2005-2010, Haiku, Inc. All rights reserved.
* Copyright 2005-2014, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _DATA_IO_H
@ -14,8 +14,8 @@ public:
BDataIO();
virtual ~BDataIO();
virtual ssize_t Read(void* buffer, size_t size) = 0;
virtual ssize_t Write(const void* buffer, size_t size) = 0;
virtual ssize_t Read(void* buffer, size_t size);
virtual ssize_t Write(const void* buffer, size_t size);
private:
BDataIO(const BDataIO&);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2005-2006, Haiku.
* Copyright 2005-2014, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -24,6 +24,20 @@ BDataIO::~BDataIO()
}
ssize_t
BDataIO::Read(void* buffer, size_t size)
{
return B_NOT_SUPPORTED;
}
ssize_t
BDataIO::Write(const void* buffer, size_t size)
{
return B_NOT_SUPPORTED;
}
// Private or Reserved
BDataIO::BDataIO(const BDataIO &)