diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-10-27 23:08:24 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-10-27 23:08:24 +0000 |
commit | fa6e658f87726b4108e8019805a2b3387d6d8517 (patch) | |
tree | 17f1059a2a60f2223473435a51118110993fd578 | |
parent | e8f7e6ea10efede39afa1698779ed15889cc2fba (diff) | |
download | libbu++-fa6e658f87726b4108e8019805a2b3387d6d8517.tar.gz libbu++-fa6e658f87726b4108e8019805a2b3387d6d8517.tar.bz2 libbu++-fa6e658f87726b4108e8019805a2b3387d6d8517.tar.xz libbu++-fa6e658f87726b4108e8019805a2b3387d6d8517.zip |
Added the beginings of the new stream system.
-rw-r--r-- | src/file.cpp | 37 | ||||
-rw-r--r-- | src/file.h | 23 | ||||
-rw-r--r-- | src/stream.cpp | 9 | ||||
-rw-r--r-- | src/stream.h | 21 |
4 files changed, 90 insertions, 0 deletions
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 @@ | |||
1 | #include "file.h" | ||
2 | #include "exceptions.h" | ||
3 | |||
4 | File::File( const char *sName, const char *sFlags ) | ||
5 | { | ||
6 | fh = fopen( sName, sFlags ); | ||
7 | } | ||
8 | |||
9 | File::~File() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | void File::close() | ||
14 | { | ||
15 | if( fh ) | ||
16 | { | ||
17 | fclose( fh ); | ||
18 | fh = NULL; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | size_t File::read( char *pBuf, size_t nBytes ) | ||
23 | { | ||
24 | if( !fh ) | ||
25 | throw FileException("File not open."); | ||
26 | |||
27 | return fread( pBuf, 1, nBytes, fh ); | ||
28 | } | ||
29 | |||
30 | size_t File::write( char *pBuf, size_t nBytes ) | ||
31 | { | ||
32 | if( !fh ) | ||
33 | throw FileException("File not open."); | ||
34 | |||
35 | return fwrite( pBuf, 1, nBytes, fh ); | ||
36 | } | ||
37 | |||
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 @@ | |||
1 | #ifndef FILE_H | ||
2 | #define FILE_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | |||
6 | #include "stream.h" | ||
7 | |||
8 | class File : public Stream | ||
9 | { | ||
10 | public: | ||
11 | File( const char *sName, const char *sFlags ); | ||
12 | virtual ~File(); | ||
13 | |||
14 | virtual void close(); | ||
15 | virtual size_t read( char *pBuf, size_t nBytes ); | ||
16 | virtual size_t write( char *pBuf, size_t nBytes ); | ||
17 | |||
18 | private: | ||
19 | FILE *fh; | ||
20 | |||
21 | }; | ||
22 | |||
23 | #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 @@ | |||
1 | #include "stream.h" | ||
2 | |||
3 | Stream::Stream() | ||
4 | { | ||
5 | } | ||
6 | |||
7 | Stream::~Stream() | ||
8 | { | ||
9 | } | ||
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 @@ | |||
1 | #ifndef STREAM_H | ||
2 | #define STREAM_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | #include <stdio.h> | ||
6 | |||
7 | class Stream | ||
8 | { | ||
9 | public: | ||
10 | Stream(); | ||
11 | virtual ~Stream(); | ||
12 | |||
13 | virtual void close() = 0; | ||
14 | virtual size_t read( char *pBuf, size_t nBytes ) = 0; | ||
15 | virtual size_t write( char *pBuf, size_t nBytes ) = 0; | ||
16 | |||
17 | private: | ||
18 | |||
19 | }; | ||
20 | |||
21 | #endif | ||