00001 #ifndef CLASSLIB_FILE_MAPPING_H
00002 # define CLASSLIB_FILE_MAPPING_H
00003
00004
00005
00006 # include "classlib/iobase/Storage.h"
00007 # include <list>
00008
00009 namespace lat {
00010
00011
00012
00013
00014 class File;
00015
00016
00017
00018
00019
00021 class FileMapping
00022 {
00023
00024
00025
00026
00027
00028
00029
00030 public:
00031
00032 static const int ProtExec = 1;
00033 static const int ProtRead = 2;
00034 static const int ProtWrite = 4;
00035 static const int ProtNone = 8;
00036
00037
00038 static const int MapShared = 1;
00039
00040
00041
00042 static const int MapPrivate = 2;
00043
00044
00045
00046
00047
00048 static const int MapFixed = 4;
00049 static const int MapDenyWrite = 8;
00050
00051
00052 static const int MapExecutable = 16;
00053
00054
00055 explicit
00056 FileMapping (File *file, IOSize maxSize = 0, int prot = ProtRead);
00057 explicit
00058 FileMapping (IOSize maxSize, int prot = ProtRead | ProtWrite);
00059 virtual ~FileMapping (void);
00060
00061
00062 virtual IOBuffer map (void);
00063 virtual IOBuffer map (int prot, int flags);
00064 virtual IOBuffer map (IOOffset offset, IOSize length,
00065 int prot, int flags);
00066
00067
00068 virtual void unmap (void *address);
00069 virtual void unmap (void);
00070 virtual void close (void);
00071
00072
00073 virtual void flush (void *address, IOSize length);
00074
00075 private:
00076 struct View
00077 {
00078 void *m_address;
00079 IOSize m_bias;
00080 IOSize m_size;
00081 };
00082
00083 void initialise (void);
00084 void * create (IOOffset pos, IOSize length,
00085 int prot, int flags);
00086 void sysunmap (View &view);
00087 void sysclose (void);
00088
00089 void *m_handle;
00090 File *m_file;
00091 IOSize m_limit;
00092 int m_prot;
00093 std::list<View> m_views;
00094
00095
00096 FileMapping (const FileMapping &);
00097 FileMapping &operator= (const FileMapping &);
00098 };
00099
00100
00101
00102 }
00103 #endif // CLASSLIB_FILE_MAPPING_H