VFile.h

Go to the documentation of this file.
00001 #ifndef __LDK_VFILE_H__
00002 #define __LDK_VFILE_H__
00003 
00005 //   Copyright (C) 2003-2006 Lorien Dunn.
00006 //
00007 //   Contact: loriendunn AT users DOT sourceforge DOT net
00008 //
00009 //   This software is provided 'as-is', without any express or implied warranty.
00010 //   In no event will the authors be held liable for any damages arising from
00011 //   the use of this software.
00012 //
00013 //   Permission is granted to anyone to use this software for any purpose,
00014 //   including commercial applications, and to alter it and redistribute it
00015 //   freely, subject to the following restrictions:
00016 //
00017 //   1. The origin of this software must not be misrepresented; you must not
00018 //   claim that you wrote the original software. If you use this software in a
00019 //   product, an acknowledgment in the product documentation would be
00020 //   appreciated but is not required.
00021 //
00022 //   2. Altered source versions must be plainly marked as such, and must not be
00023 //   misrepresented as being the original software.
00024 //
00025 //   3. This notice may not be removed or altered from any source distribution.
00026 //
00028 
00033 
00034 
00035 #include "LDK/String.h"
00036 #include "LDK/SmartPointers.h"
00037 #include "LDK/ByteOrder.h"
00038 #include <stdarg.h>
00039 
00040 #ifdef putc
00041 #undef putc
00042 #endif
00043 
00044 #ifdef puts
00045 #undef puts
00046 #endif
00047 
00048 #ifdef getc
00049 #undef getc
00050 #endif
00051 
00052 namespace LDK
00053 {
00071 class LDK_API VFile : public Object
00072 {
00073 protected:
00074     bool mTextMode;
00075     bool mWriteable;
00076     String mName;
00077 public:
00078 
00080     VFile() : mTextMode(true), mWriteable(false) {}
00081 
00083     virtual ~VFile() throw() {};
00084 
00087     inline const char* name() { return mName.c_str(); }
00088 
00093     virtual void openRead(const char* fileName, bool text=false)  = 0;
00094 
00099     virtual void openWrite(const char* fileName, bool text=false) = 0;
00100 
00105     virtual void openAppend(const char* fileName, bool text=false) = 0;
00106 
00109     virtual void close() = 0;
00110 
00115     virtual int64 length() = 0;
00116 
00120     virtual bool eof() = 0;
00121 
00125     virtual int64 tell() = 0;
00126 
00133     virtual int64 seek(int64 offset, int whence) = 0;
00134 
00137     virtual void flush() = 0;
00138 
00147     virtual int64 read(void *buffer, uint32 objCount, uint32 objSize=1) = 0;
00148 
00153     virtual int32 getc() = 0;
00154 
00162     virtual int32 ungetc(char c) = 0;
00163 
00171     virtual uint32 getString(char* buffer,uint32 size);
00172 
00179     virtual const char* gets(char* buffer, uint32 size) = 0;
00180 
00186     inline int16  readSLE16()
00187     {
00188         assert(!mTextMode);
00189         int16 dat = 0;
00190         this->read(&dat,1,2);
00191         return swapSLE16(dat);
00192     }
00193 
00199     inline uint16 readULE16()
00200     {
00201         assert(!mTextMode);
00202         uint16 dat = 0;
00203         this->read(&dat,1,2);
00204         return swapULE16(dat);
00205     }
00206 
00212     inline int16  readSBE16()
00213     {
00214         assert(!mTextMode);
00215         int16 dat = 0;
00216         this->read(&dat,1,2);
00217         return swapSBE16(dat);
00218     }
00219 
00225     inline uint16 readUBE16()
00226     {
00227         assert(!mTextMode);
00228         uint16 dat = 0;
00229         this->read(&dat,1,2);
00230         return swapUBE16(dat);
00231     }
00232 
00238     inline int32  readSLE32()
00239     {
00240         assert(!mTextMode);
00241         int32 dat = 0;
00242         this->read(&dat,1,4);
00243         return swapSLE32(dat);
00244     }
00245 
00251     inline uint32 readULE32()
00252     {
00253         assert(!mTextMode);
00254         uint32 dat = 0;
00255         this->read(&dat,1,4);
00256         return swapULE32(dat);
00257     }
00258 
00264     inline int32  readSBE32()
00265     {
00266         assert(!mTextMode);
00267         int32 dat = 0;
00268         this->read(&dat,1,4);
00269         return swapSBE32(dat);
00270     }
00271 
00277     inline uint32 readUBE32()
00278     {
00279         assert(!mTextMode);
00280         uint32 dat = 0;
00281         this->read(&dat,1,4);
00282         return swapUBE32(dat);
00283     }
00284 
00290     inline int64  readSLE64()
00291     {
00292         assert(!mTextMode);
00293         int64 dat = 0;
00294         this->read(&dat,1,8);
00295         return swapSLE64(dat);
00296     }
00297 
00303     inline uint64 readULE64()
00304     {
00305         assert(!mTextMode);
00306         uint64 dat = 0;
00307         this->read(&dat,1,8);
00308         return swapULE64(dat);
00309     }
00310 
00316     inline int64  readSBE64()
00317     {
00318         assert(!mTextMode);
00319         int64 dat = 0;
00320         this->read(&dat,1,8);
00321         return swapSBE64(dat);
00322     }
00323 
00329     inline uint64 readUBE64()
00330     {
00331         assert(!mTextMode);
00332         uint64 dat = 0;
00333         this->read(&dat,1,8);
00334         return swapUBE64(dat);
00335     }
00336 
00345     virtual int64 write(const void *buffer, uint32 objCount, uint32 objSize=1) = 0;
00346 
00351     virtual int32 putc(char c) = 0;
00352 
00356     virtual int32 puts(const char* str) = 0;
00357 
00363     virtual int32 printf(const char* format, ...) = 0;
00364 
00370     virtual int32 vprintf(const char *format, va_list ap) = 0;
00371 
00377     inline void writeSLE16(int16 dat)
00378     {
00379         assert(!mTextMode);
00380         dat = swapSLE16(dat);
00381         this->write(&dat,1,2);
00382     }
00383 
00389     inline void writeULE16(uint16 dat)
00390     {
00391         assert(!mTextMode);
00392         dat = swapULE16(dat);
00393         this->write(&dat,1,2);
00394     }
00395 
00401     inline void writeSBE16(int16 dat)
00402     {
00403         assert(!mTextMode);
00404         dat = swapSBE16(dat);
00405         this->write(&dat,1,2);
00406     }
00407 
00413     inline void writeUBE16(uint16 dat)
00414     {
00415         assert(!mTextMode);
00416         dat = swapUBE16(dat);
00417         this->write(&dat,1,2);
00418     }
00419 
00425     inline void writeSLE32(int32 dat)
00426     {
00427         assert(!mTextMode);
00428         dat = swapSLE32(dat);
00429         this->write(&dat,1,4);
00430     }
00431 
00437     inline void writeULE32(uint32 dat)
00438     {
00439         assert(!mTextMode);
00440         dat = swapULE32(dat);
00441         this->write(&dat,1,4);
00442     }
00443 
00449     inline void writeSBE32(int32 dat)
00450     {
00451         assert(!mTextMode);
00452         dat = swapSBE32(dat);
00453         this->write(&dat,1,4);
00454     }
00455 
00461     inline void writeUBE32(uint32 dat)
00462     {
00463         assert(!mTextMode);
00464         dat = swapUBE32(dat);
00465         this->write(&dat,1,4);
00466     }
00467 
00473     inline void writeSLE64(int64 dat)
00474     {
00475         assert(!mTextMode);
00476         dat = swapSLE64(dat);
00477         this->write(&dat,1,8);
00478     }
00479 
00485     inline void writeULE64(uint64 dat)
00486     {
00487         assert(!mTextMode);
00488         dat = swapULE64(dat);
00489         this->write(&dat,1,8);
00490     }
00491 
00497     inline void writeSBE64(int64 dat)
00498     {
00499         assert(!mTextMode);
00500         dat = swapSBE64(dat);
00501         this->write(&dat,1,8);
00502     }
00503 
00509     inline void writeUBE64(uint64 dat)
00510     {
00511         assert(!mTextMode);
00512         dat = swapUBE64(dat);
00513         this->write(&dat,1,8);
00514     }
00515 
00517     inline bool writeable() { return mWriteable; }
00518 };
00519 
00520 typedef IntrusiveSmartPointer<VFile> SmartFile;
00521 
00522 }//namespace LDK
00523 
00524 #endif //__LDK_VFILE_H__

Generated on Fri Aug 17 18:32:26 2007 for LDK by  doxygen 1.5.1