Skip to content

Commit

Permalink
BDataIO: Provide default implementations for Read()/Write()
Browse files Browse the repository at this point in the history
This makes the interface somewhat more suitable for unidirectional use,
since one doesn't have to implement the other, not needed method.
  • Loading branch information
weinhold committed Jun 23, 2014
1 parent 4e37add commit 98759fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
22 changes: 14 additions & 8 deletions docs/user/support/DataIO.dox
@@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down
6 changes: 3 additions & 3 deletions headers/os/support/DataIO.h
@@ -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
Expand All @@ -14,8 +14,8 @@ class BDataIO {
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&);
Expand Down
16 changes: 15 additions & 1 deletion src/kits/support/DataIO.cpp
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2006, Haiku.
* Copyright 2005-2014, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
Expand All @@ -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 &)
Expand Down

0 comments on commit 98759fe

Please sign in to comment.