diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 05:09:12 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 05:09:12 +0000 |
commit | c884da672645231b5ec47706c886381dab1b391a (patch) | |
tree | f9c0a0c4fb9006c2c1aa10c8c65de2f6e42894de /src/sfile.cpp | |
parent | da89e6d30e57bd6dbb10b4d36b093ce9bbf5c666 (diff) | |
download | libbu++-c884da672645231b5ec47706c886381dab1b391a.tar.gz libbu++-c884da672645231b5ec47706c886381dab1b391a.tar.bz2 libbu++-c884da672645231b5ec47706c886381dab1b391a.tar.xz libbu++-c884da672645231b5ec47706c886381dab1b391a.zip |
The file stream is imported and works, as does our first test, and the new
tweaks to archive. The && operator is now a template function, and as such
requires no special handling. It could be worth it to check this out for other
types, yet dangerous, since it would let you archive anything, even a class,
without writing the proper functions for it...we shall see what happens...
Diffstat (limited to 'src/sfile.cpp')
-rw-r--r-- | src/sfile.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/sfile.cpp b/src/sfile.cpp new file mode 100644 index 0000000..d7c5c83 --- /dev/null +++ b/src/sfile.cpp | |||
@@ -0,0 +1,90 @@ | |||
1 | #include "sfile.h" | ||
2 | #include "exceptions.h" | ||
3 | |||
4 | Bu::SFile::SFile( const char *sName, const char *sFlags ) | ||
5 | { | ||
6 | fh = fopen( sName, sFlags ); | ||
7 | } | ||
8 | |||
9 | Bu::SFile::~SFile() | ||
10 | { | ||
11 | close(); | ||
12 | } | ||
13 | |||
14 | void Bu::SFile::close() | ||
15 | { | ||
16 | if( fh ) | ||
17 | { | ||
18 | fclose( fh ); | ||
19 | fh = NULL; | ||
20 | } | ||
21 | } | ||
22 | |||
23 | size_t Bu::SFile::read( char *pBuf, size_t nBytes ) | ||
24 | { | ||
25 | if( !fh ) | ||
26 | throw FileException("File not open."); | ||
27 | |||
28 | return fread( pBuf, 1, nBytes, fh ); | ||
29 | } | ||
30 | |||
31 | size_t Bu::SFile::write( const char *pBuf, size_t nBytes ) | ||
32 | { | ||
33 | if( !fh ) | ||
34 | throw FileException("File not open."); | ||
35 | |||
36 | return fwrite( pBuf, 1, nBytes, fh ); | ||
37 | } | ||
38 | |||
39 | long Bu::SFile::tell() | ||
40 | { | ||
41 | if( !fh ) | ||
42 | throw FileException("File not open."); | ||
43 | |||
44 | return ftell( fh ); | ||
45 | } | ||
46 | |||
47 | void Bu::SFile::seek( long offset ) | ||
48 | { | ||
49 | if( !fh ) | ||
50 | throw FileException("File not open."); | ||
51 | |||
52 | fseek( fh, offset, SEEK_CUR ); | ||
53 | } | ||
54 | |||
55 | void Bu::SFile::setPos( long pos ) | ||
56 | { | ||
57 | if( !fh ) | ||
58 | throw FileException("File not open."); | ||
59 | |||
60 | fseek( fh, pos, SEEK_SET ); | ||
61 | } | ||
62 | |||
63 | void Bu::SFile::setPosEnd( long pos ) | ||
64 | { | ||
65 | if( !fh ) | ||
66 | throw FileException("File not open."); | ||
67 | |||
68 | fseek( fh, pos, SEEK_END ); | ||
69 | } | ||
70 | |||
71 | bool Bu::SFile::isEOS() | ||
72 | { | ||
73 | return feof( fh ); | ||
74 | } | ||
75 | |||
76 | bool Bu::SFile::canRead() | ||
77 | { | ||
78 | return true; | ||
79 | } | ||
80 | |||
81 | bool Bu::SFile::canWrite() | ||
82 | { | ||
83 | return true; | ||
84 | } | ||
85 | |||
86 | bool Bu::SFile::canSeek() | ||
87 | { | ||
88 | return true; | ||
89 | } | ||
90 | |||