00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MIMETIC_OS_MMFILE_H
00017 #define _MIMETIC_OS_MMFILE_H
00018 #include <sys/types.h>
00019 #include <sys/stat.h>
00020 #include <fcntl.h>
00021 #include <sys/mman.h>
00022 #include <string>
00023 #include <mimetic/os/fileop.h>
00024
00025 namespace mimetic
00026 {
00027
00028
00029 struct MMFile: public FileOp
00030 {
00031 typedef char* iterator;
00032 typedef const char* const_iterator;
00033 MMFile();
00034 MMFile(const std::string&, int mode = O_RDONLY);
00035 ~MMFile();
00036 operator bool() const;
00037 bool open(const std::string&, int mode = O_RDONLY);
00038 void close();
00039 uint read(char*, int);
00040
00041 iterator begin();
00042 const_iterator begin() const;
00043 iterator end();
00044 const_iterator end() const;
00045
00046 protected:
00047 bool map();
00048 bool open(int flags);
00049 bool stat();
00050
00051 std::string m_fqn;
00052 bool m_stated;
00053 struct stat m_st;
00054 int m_fd;
00055
00056 char *m_beg, *m_end;
00057 };
00058
00059 }
00060
00061
00062 #endif
00063