Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_MEMORY_MAPPED_IO__
00021 #define __CS_MEMORY_MAPPED_IO__
00022
00027 #include "csextern.h"
00028 #include "bitarray.h"
00029 #include "ref.h"
00030 #include "refcount.h"
00031
00032 struct iVFS;
00033
00034
00035
00036
00037
00038 #if defined(CS_PLATFORM_WIN32)
00039 #include "win32/mmap.h"
00040 #define csPlatformMemoryMapping csPlatformMemoryMappingWin32
00041 #elif defined(CS_HAVE_POSIX_MMAP)
00042 #include "mmap_posix.h"
00043 #define csPlatformMemoryMapping csPlatformMemoryMappingPosix
00044 #else
00045 #include "mmap_dummy.h"
00046 #define csPlatformMemoryMapping csPlatformMemoryMappingDummy
00047 #endif
00048
00052 class csMemoryMapping : public csRefCount
00053 {
00054 public:
00056 virtual size_t GetLength() = 0;
00058 virtual void* GetData() = 0;
00059 };
00060
00064 class CS_CRYSTALSPACE_EXPORT csMemoryMappedIO : public csPlatformMemoryMapping,
00065 public csRefCount
00066 {
00067 private:
00069 bool valid_mmio_object;
00070
00072 FILE *hMappedFile;
00073
00075 bool valid_platform;
00076 public:
00083 csMemoryMappedIO(char const *filename, iVFS* vfs = 0);
00084
00088 virtual ~csMemoryMappedIO();
00089
00093 csRef<csMemoryMapping> GetData (size_t offset, size_t length);
00094
00098 bool IsValid();
00099
00100 private:
00101
00102 struct PlatformMapping :
00103 public csPlatformMemoryMapping::PlatformMemoryMapping,
00104 public csMemoryMapping
00105 {
00106 csRef<csMemoryMappedIO> parent;
00107 size_t length;
00108 uint8* data;
00109
00110 PlatformMapping (csMemoryMappedIO* parent) : parent(parent) {}
00111 virtual ~PlatformMapping() { parent->FreeMapping (this); }
00112 virtual size_t GetLength() { return length; }
00113 virtual void* GetData() { return data; }
00114 };
00115 friend struct PlatformMapping;
00116
00117 void FreeMapping (PlatformMapping* mapping);
00118 };
00119
00120 #undef csPlatformMemoryMapping
00121
00122 #endif // __CS_MEMORY_MAPPED_IO__
00123