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 <cstring>
00024 #include <mimetic/os/fileop.h>
00025
00026 namespace mimetic
00027 {
00028
00029
00030 struct MMFile: public FileOp
00031 {
00032 typedef char* iterator;
00033 typedef const char* const_iterator;
00034 MMFile();
00035 MMFile(const std::string&, int mode = O_RDONLY);
00036 ~MMFile();
00037 operator bool() const;
00038 bool open(const std::string&, int mode = O_RDONLY);
00039 void close();
00040 uint read(char*, int);
00041
00042 iterator begin();
00043 const_iterator begin() const;
00044 iterator end();
00045 const_iterator end() const;
00046
00047 protected:
00048 bool map();
00049 bool open(int flags);
00050 bool stat();
00051
00052 std::string m_fqn;
00053 bool m_stated;
00054 struct stat m_st;
00055 int m_fd;
00056
00057 char *m_beg, *m_end;
00058 };
00059
00060 }
00061
00062
00063 #endif
00064