From fa6e658f87726b4108e8019805a2b3387d6d8517 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 27 Oct 2006 23:08:24 +0000 Subject: Added the beginings of the new stream system. --- src/file.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/file.h | 23 +++++++++++++++++++++++ src/stream.cpp | 9 +++++++++ src/stream.h | 21 +++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 src/file.cpp create mode 100644 src/file.h create mode 100644 src/stream.cpp create mode 100644 src/stream.h diff --git a/src/file.cpp b/src/file.cpp new file mode 100644 index 0000000..9910b8a --- /dev/null +++ b/src/file.cpp @@ -0,0 +1,37 @@ +#include "file.h" +#include "exceptions.h" + +File::File( const char *sName, const char *sFlags ) +{ + fh = fopen( sName, sFlags ); +} + +File::~File() +{ +} + +void File::close() +{ + if( fh ) + { + fclose( fh ); + fh = NULL; + } +} + +size_t File::read( char *pBuf, size_t nBytes ) +{ + if( !fh ) + throw FileException("File not open."); + + return fread( pBuf, 1, nBytes, fh ); +} + +size_t File::write( char *pBuf, size_t nBytes ) +{ + if( !fh ) + throw FileException("File not open."); + + return fwrite( pBuf, 1, nBytes, fh ); +} + diff --git a/src/file.h b/src/file.h new file mode 100644 index 0000000..111a8b8 --- /dev/null +++ b/src/file.h @@ -0,0 +1,23 @@ +#ifndef FILE_H +#define FILE_H + +#include + +#include "stream.h" + +class File : public Stream +{ +public: + File( const char *sName, const char *sFlags ); + virtual ~File(); + + virtual void close(); + virtual size_t read( char *pBuf, size_t nBytes ); + virtual size_t write( char *pBuf, size_t nBytes ); + +private: + FILE *fh; + +}; + +#endif diff --git a/src/stream.cpp b/src/stream.cpp new file mode 100644 index 0000000..99c25f2 --- /dev/null +++ b/src/stream.cpp @@ -0,0 +1,9 @@ +#include "stream.h" + +Stream::Stream() +{ +} + +Stream::~Stream() +{ +} diff --git a/src/stream.h b/src/stream.h new file mode 100644 index 0000000..086e4a1 --- /dev/null +++ b/src/stream.h @@ -0,0 +1,21 @@ +#ifndef STREAM_H +#define STREAM_H + +#include +#include + +class Stream +{ +public: + Stream(); + virtual ~Stream(); + + virtual void close() = 0; + virtual size_t read( char *pBuf, size_t nBytes ) = 0; + virtual size_t write( char *pBuf, size_t nBytes ) = 0; + +private: + +}; + +#endif -- cgit v1.2.3