2010-03-15 03:05:48 +00:00
|
|
|
#ifndef __MAPPED_FILE_H__
|
|
|
|
#define __MAPPED_FILE_H__
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2010-03-17 03:42:27 +00:00
|
|
|
#include <File/File.h>
|
2010-03-15 03:05:48 +00:00
|
|
|
|
2010-05-19 01:07:47 +00:00
|
|
|
class File;
|
2010-03-15 03:05:48 +00:00
|
|
|
|
|
|
|
class MappedFile {
|
|
|
|
public:
|
|
|
|
|
|
|
|
MappedFile();
|
|
|
|
MappedFile(MappedFile&);
|
2010-05-18 02:58:26 +00:00
|
|
|
MappedFile(const File &f, bool readOnly, size_t size = -1);
|
|
|
|
MappedFile(const char *name, bool readOnly);
|
2010-03-15 03:05:48 +00:00
|
|
|
|
|
|
|
~MappedFile();
|
|
|
|
|
2010-05-18 02:58:26 +00:00
|
|
|
|
|
|
|
static MappedFile *Create(const char *name, size_t size);
|
|
|
|
|
|
|
|
bool isValid() const
|
|
|
|
{
|
|
|
|
return _address != MAP_FAILED;
|
|
|
|
}
|
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
void sync();
|
|
|
|
void close();
|
|
|
|
|
|
|
|
void *address() const { return _address; }
|
|
|
|
size_t length() const { return _length; }
|
2010-05-18 02:58:26 +00:00
|
|
|
bool readOnly() const { return _readOnly; }
|
2010-03-15 03:05:48 +00:00
|
|
|
|
2010-03-17 03:42:27 +00:00
|
|
|
void swap(MappedFile &);
|
|
|
|
void adopt(MappedFile &);
|
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
private:
|
|
|
|
|
2010-03-17 03:42:27 +00:00
|
|
|
MappedFile& operator=(MappedFile &);
|
|
|
|
|
2010-05-18 02:58:26 +00:00
|
|
|
void init(const File &f, bool readOnly, size_t size);
|
|
|
|
|
2010-03-15 03:05:48 +00:00
|
|
|
void *_address;
|
|
|
|
size_t _length;
|
2010-05-18 02:58:26 +00:00
|
|
|
bool _readOnly;
|
2010-03-15 03:05:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|