From 469bbcf0701e1eb8a6670c23145b0da87357e178 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 25 Mar 2012 20:00:08 +0000 Subject: Code is all reorganized. We're about ready to release. I should write up a little explenation of the arrangement. --- src/stable/file.h | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/stable/file.h (limited to 'src/stable/file.h') diff --git a/src/stable/file.h b/src/stable/file.h new file mode 100644 index 0000000..e3225fa --- /dev/null +++ b/src/stable/file.h @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2007-2011 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_FILE_H +#define BU_FILE_H + +#include +#include + +#include "bu/stream.h" +#include "bu/string.h" +#include "bu/exceptionbase.h" + +namespace Bu +{ + subExceptionDecl( FileException ); + + /** + * A file stream. + *@ingroup Streams + */ + class File : public Bu::Stream + { + public: + File( const Bu::String &sName, int iFlags ); + File( int fd ); + virtual ~File(); + + virtual void close(); + virtual Bu::size read( void *pBuf, Bu::size nBytes ); + virtual Bu::size write( const void *pBuf, Bu::size nBytes ); + using Stream::write; + + virtual Bu::size tell(); + virtual void seek( Bu::size offset ); + virtual void setPos( Bu::size pos ); + virtual void setPosEnd( Bu::size pos ); + virtual bool isEos(); + virtual bool isOpen(); + + virtual void flush(); + + virtual bool canRead(); + virtual bool canWrite(); + + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); + + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); + + enum { + // Flags + Read = 0x01, ///< Open file for reading + Write = 0x02, ///< Open file for writing + Create = 0x04, ///< Create file if it doesn't exist + Truncate = 0x08, ///< Truncate file if it does exist + Append = 0x10, ///< Always append on every write + NonBlock = 0x20, ///< Open file in non-blocking mode + Exclusive = 0x44, ///< Create file, if it exists then fail + + // Helpful mixes + ReadWrite = 0x03, ///< Open for reading and writing + WriteNew = 0x0E ///< Create a file (or truncate) for writing. + /// Same as Write|Create|Truncate + }; + + virtual void setSize( Bu::size iSize ); + + virtual size getSize() const; + virtual size getBlockSize() const; + virtual Bu::String getLocation() const; + + /** + * Create a temp file and return its handle. The file is opened + * Read/Write. + *@param sName (Bu::String) Give in the form: "/tmp/tmpfileXXXXXXXX" + * It will alter your (sName) setting the 'X's to random + * characters. + *@returns (Bu::File) A file object representing your temp file. + */ + static Bu::File tempFile( Bu::String &sName ); + +#ifndef WIN32 + /** + * Change the file access permissions. + *@param t (mode_t) The new file access permissions. + */ + void chmod( mode_t t ); +#endif + + private: + int getPosixFlags( int iFlags ); + + private: + int fd; + bool bEos; + }; +} + +#endif -- cgit v1.2.3