Main Page   Class Hierarchy   Alphabetical List   Compound List   Examples  

mmfile.h

00001 /***************************************************************************
00002     copyright            : (C) 2002-2005 by Stefano Barbato
00003     email                : [email protected]
00004 
00005     $Id: mmfile_8h-source.html,v 1.4 2006-03-12 12:28:31 tat Exp $
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
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 /// Memory mapped file
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