112 lines
2.7 KiB
C++
112 lines
2.7 KiB
C++
/******************************************************************************/
|
|
/* STREAMS ********************************************************************/
|
|
/******************************************************************************/
|
|
|
|
#ifndef _H_EBCL_STREAMS
|
|
#define _H_EBCL_STREAMS
|
|
#include <ebcl/Externals.hh>
|
|
#include <ebcl/Utilities.hh>
|
|
#include <ebcl/Pointers.hh>
|
|
#include <ebcl/Buffers.hh>
|
|
namespace ebcl {
|
|
|
|
|
|
/*= STREAM ERRORS ============================================================*/
|
|
|
|
enum class E_StreamError {
|
|
NOT_SUPPORTED , // Operation not supported
|
|
INVALID_POSITION ,
|
|
END , // End of stream
|
|
BAD_DATA , // Invalid data read from the stream
|
|
SYSTEM_ERROR ,
|
|
UNAVAILABLE , // Stream is no longer available
|
|
};
|
|
|
|
|
|
class X_StreamError : public std::exception
|
|
{
|
|
private:
|
|
E_StreamError error_;
|
|
int sysError_;
|
|
|
|
public:
|
|
explicit X_StreamError( E_StreamError e );
|
|
explicit X_StreamError( int error );
|
|
|
|
X_StreamError( ) = delete;
|
|
X_StreamError( X_StreamError const& ) = default;
|
|
X_StreamError( X_StreamError&& ) noexcept = default;
|
|
virtual X_StreamError& operator= ( X_StreamError const& ) = default;
|
|
virtual X_StreamError& operator= ( X_StreamError&& ) = default;
|
|
|
|
E_StreamError code( ) const;
|
|
int systemError( ) const;
|
|
|
|
char const * what( ) const noexcept;
|
|
};
|
|
|
|
|
|
/*= BASE ABSTRACT CLASSES FOR STREAMS ========================================*/
|
|
|
|
class A_Stream
|
|
{
|
|
private:
|
|
const bool isInput_;
|
|
const bool knownSize_;
|
|
|
|
protected:
|
|
size_t size_;
|
|
size_t position_;
|
|
|
|
A_Stream( bool isInput , size_t position ) noexcept;
|
|
A_Stream( bool isInput , size_t position , size_t size ) noexcept;
|
|
|
|
public:
|
|
A_Stream( ) = delete;
|
|
A_Stream( A_Stream const& ) = delete;
|
|
A_Stream( A_Stream&& ) = delete;
|
|
virtual ~A_Stream( ) = 0;
|
|
|
|
bool isInput( ) const;
|
|
bool isSizeKnown( ) const;
|
|
size_t position( ) const;
|
|
size_t size( ) const;
|
|
};
|
|
|
|
|
|
M_ABSTRACT_POINTERS( Stream );
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
class A_InputStream : public A_Stream
|
|
{
|
|
protected:
|
|
explicit A_InputStream( size_t position ) noexcept;
|
|
A_InputStream( size_t position , size_t size ) noexcept;
|
|
|
|
public:
|
|
virtual size_t read( void* data , size_t size ) = 0;
|
|
};
|
|
|
|
|
|
M_ABSTRACT_POINTERS( InputStream );
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
class A_OutputStream : public A_Stream
|
|
{
|
|
protected:
|
|
A_OutputStream( size_t position ) noexcept;
|
|
A_OutputStream( size_t position , size_t size ) noexcept;
|
|
|
|
public:
|
|
virtual size_t write( void const* data , size_t size ) = 0;
|
|
virtual void flush( );
|
|
};
|
|
|
|
|
|
M_ABSTRACT_POINTERS( OutputStream );
|
|
|
|
} // namespace
|
|
#include <ebcl/inline/Streams.hh>
|
|
#endif // _H_EBCL_STREAMS
|