Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

File.h

Go to the documentation of this file.
00001 /*
00002     Extent File System - Volume data file storage
00003     Copyright (C) 2000-2002 Sebastian Gerlach EPFL-LSP
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #ifndef __FILE_H
00021 #define __FILE_H
00022 
00023 #include <windows.h>
00024 
00025 namespace extfile
00026 {
00028 
00030     class FileWrapper
00031     {
00033         HANDLE hFile;
00035         char filename[1024];
00036 
00037     public:
00039         enum {
00040             READ = 1,   
00041             WRITE = 2   
00042         };
00043 
00044     public:
00046         FileWrapper() 
00047         { 
00048             hFile=NULL;
00049         }
00051         ~FileWrapper() 
00052         { 
00053             close(); 
00054         }
00056 
00060         bool open(const char *fname, Int32 mode)
00061         {
00062             strcpy(filename,fname);
00063             // If open in write-only, delete file first
00064             if(mode==WRITE)
00065                 DeleteFile(fname);
00066             hFile=CreateFile(fname,((mode&READ) ? GENERIC_READ : 0) | ((mode&WRITE) ? GENERIC_WRITE : 0),0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
00067             return hFile!=INVALID_HANDLE_VALUE;
00068         }
00070         void close(bool destroy=false) 
00071         { 
00072             if(hFile)
00073             {
00074                 CloseHandle(hFile);
00075                 hFile=NULL;
00076                 if(destroy)
00077                     DeleteFile(filename);
00078             }
00079         }
00081 
00085         bool read(void *data, Int32 len)
00086         {
00087             DWORD br;
00088             ReadFile(hFile,data,len,&br,NULL);
00089             return true;
00090         }
00092 
00096         bool write(void *data, Int32 len)
00097         {
00098             DWORD br;
00099             WriteFile(hFile,data,len,&br,NULL);
00100             return true;
00101         }
00103 
00106         void seek(Int64 pos)
00107         {
00108             union {
00109                 struct { DWORD lp; LONG hp; };
00110                 LONGLONG qp;
00111             } p;
00112             p.qp=pos;
00113             SetFilePointer(hFile,p.lp,&p.hp,FILE_BEGIN);
00114         }
00115     };
00116 }
00117 
00118 
00119 #endif
00120 

Generated on Wed May 29 11:50:17 2002 for Extent File System by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001