## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csutil/mmapio.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2002-2005 by Jorrit Tyberghein
    00003               (C) 2005 by Frank Richter
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library 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 GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public
    00016     License along with this library; if not, write to the Free
    00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    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 /* Note: the "#define csPlatformMemoryMapping ..." is done to appease doxygen,
    00035  * which produces funny results when all the memory mapping base classes
    00036  * would be in unison named "csPlatformMemoryMapping".
    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