From bdd4bdd8615b1587974312a92219cbeab0068a7a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 31 Oct 2006 05:44:33 +0000 Subject: Changed the file class to be SFile so that it will collide less, all of them will be named like that, make life easier. --- src/file.cpp | 37 ------------------------------------- src/file.h | 23 ----------------------- src/sfile.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/sfile.h | 23 +++++++++++++++++++++++ src/tests/sha1.cpp | 4 ++-- 5 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 src/file.cpp delete mode 100644 src/file.h create mode 100644 src/sfile.cpp create mode 100644 src/sfile.h diff --git a/src/file.cpp b/src/file.cpp deleted file mode 100644 index 9910b8a..0000000 --- a/src/file.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#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 deleted file mode 100644 index 111a8b8..0000000 --- a/src/file.h +++ /dev/null @@ -1,23 +0,0 @@ -#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/sfile.cpp b/src/sfile.cpp new file mode 100644 index 0000000..9c5f830 --- /dev/null +++ b/src/sfile.cpp @@ -0,0 +1,37 @@ +#include "sfile.h" +#include "exceptions.h" + +SFile::SFile( const char *sName, const char *sFlags ) +{ + fh = fopen( sName, sFlags ); +} + +SFile::~SFile() +{ +} + +void SFile::close() +{ + if( fh ) + { + fclose( fh ); + fh = NULL; + } +} + +size_t SFile::read( char *pBuf, size_t nBytes ) +{ + if( !fh ) + throw FileException("SFile not open."); + + return fread( pBuf, 1, nBytes, fh ); +} + +size_t SFile::write( char *pBuf, size_t nBytes ) +{ + if( !fh ) + throw FileException("SFile not open."); + + return fwrite( pBuf, 1, nBytes, fh ); +} + diff --git a/src/sfile.h b/src/sfile.h new file mode 100644 index 0000000..f94aef7 --- /dev/null +++ b/src/sfile.h @@ -0,0 +1,23 @@ +#ifndef SFILE_H +#define SFILE_H + +#include + +#include "stream.h" + +class SFile : public Stream +{ +public: + SFile( const char *sName, const char *sFlags ); + virtual ~SFile(); + + 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/tests/sha1.cpp b/src/tests/sha1.cpp index 51c5104..df3113c 100644 --- a/src/tests/sha1.cpp +++ b/src/tests/sha1.cpp @@ -1,5 +1,5 @@ #include "sha1.h" -#include "file.h" +#include "sfile.h" #define BS 1024 @@ -16,7 +16,7 @@ int main( int argc, char *argv[] ) char buf[BS]; Sha1 s; - File fin( *argv, "rb" ); + SFile fin( *argv, "rb" ); for(;;) { int nRead = fin.read( buf, BS ); -- cgit v1.2.3