Lunchbox  1.8.0
memoryMap.h
1 
2 /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef LUNCHBOX_MEMORYMAP_H
19 #define LUNCHBOX_MEMORYMAP_H
20 
21 #include <lunchbox/api.h>
22 #include <lunchbox/nonCopyable.h>
23 
24 #include <iostream>
25 #include <string>
26 
27 namespace lunchbox
28 {
30 class MemoryMap : public NonCopyable
31 {
32 public:
34  LUNCHBOX_API MemoryMap();
35 
37  LUNCHBOX_API MemoryMap( const std::string& filename );
38 
46  LUNCHBOX_API ~MemoryMap();
47 
58  LUNCHBOX_API const void* map( const std::string& filename );
59 
61  LUNCHBOX_API void unmap();
62 
64  const void* getAddress() const { return _ptr; }
65 
67  size_t getSize() const { return _size; }
68 
69 private:
70 #ifdef _WIN32
71  void* _map;
72 #else
73  int _fd;
74 #endif
75 
76  void* _ptr;
77  size_t _size;
78 };
79 
80 inline std::ostream& operator << ( std::ostream& os, const MemoryMap& m )
81 {
82  return os << "MemoryMap at " << m.getAddress() << " size " << m.getSize();
83 }
84 
85 }
86 
87 #endif //LUNCHBOX_MEMORYMAP_H