From 98759fe6e6024510ef4cf06cf8042c30ece9a615 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 20 Jun 2014 15:16:23 +0200 Subject: [PATCH] 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. --- docs/user/support/DataIO.dox | 22 ++++++++++++++-------- headers/os/support/DataIO.h | 6 +++--- src/kits/support/DataIO.cpp | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/docs/user/support/DataIO.dox b/docs/user/support/DataIO.dox index f4b0b6c0b0..fe9fb58df8 100644 --- a/docs/user/support/DataIO.dox +++ b/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: @@ -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. */ diff --git a/headers/os/support/DataIO.h b/headers/os/support/DataIO.h index b2b927f189..539b65d1a6 100644 --- a/headers/os/support/DataIO.h +++ b/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 @@ -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&); diff --git a/src/kits/support/DataIO.cpp b/src/kits/support/DataIO.cpp index aee5f212ae..71f81f91c9 100644 --- a/src/kits/support/DataIO.cpp +++ b/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: @@ -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 &)