/******************************************************************************/ /* STREAMS ********************************************************************/ /******************************************************************************/ #ifndef _H_EBCL_STREAMS #define _H_EBCL_STREAMS #include #include #include #include #include #include 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_; T_Optional< T_FSPath > path_; public: explicit X_StreamError( E_StreamError e , T_Optional< T_FSPath > p = {} ) noexcept; explicit X_StreamError( int error , T_Optional< T_FSPath > p = {} ) noexcept; 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&& ) noexcept = default; E_StreamError code( ) const noexcept; int systemError( ) const noexcept; T_Optional< T_FSPath > const& path( ) const noexcept; 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 ebcl #include #endif // _H_EBCL_STREAMS