Lunchbox  1.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
memoryMap.h
1 
2 /* Copyright (c) 2009-2014, 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 <boost/noncopyable.hpp>
23 #include <iostream>
24 #include <string>
25 
26 namespace lunchbox
27 {
28 namespace detail { class MemoryMap; }
29 
36 class MemoryMap : public boost::noncopyable
37 {
38 public:
40  LUNCHBOX_API MemoryMap();
41 
43  LUNCHBOX_API explicit MemoryMap( const std::string& filename );
44 
46  LUNCHBOX_API MemoryMap( const std::string& filename, const size_t size );
47 
55  LUNCHBOX_API ~MemoryMap();
56 
67  LUNCHBOX_API const void* map( const std::string& filename );
68 
78  LUNCHBOX_API const void* remap( const std::string& filename );
79 
91  LUNCHBOX_API void* create( const std::string& filename, const size_t size );
92 
103  LUNCHBOX_API void* recreate( const std::string& filename,
104  const size_t size );
105 
107  LUNCHBOX_API void unmap();
108 
110  LUNCHBOX_API const void* getAddress() const;
111 
113  LUNCHBOX_API void* getAddress();
114 
116  template< class T > const T* getAddress() const
117  { return static_cast< const T* >( getAddress( )); }
118 
120  template< class T > T* getAddress()
121  { return static_cast< T* >( getAddress( )); }
122 
124  LUNCHBOX_API size_t getSize() const;
125 
126 private:
127  detail::MemoryMap* const impl_;
128 };// LB_DEPRECATED;
129 
130 inline std::ostream& operator << ( std::ostream& os, const MemoryMap& m )
131 {
132  return os << "MemoryMap at " << m.getAddress() << " size " << m.getSize();
133 }
134 
135 }
136 
137 #endif //LUNCHBOX_MEMORYMAP_H
Defines export visibility macros for Lunchbox.
LUNCHBOX_API size_t getSize() const
LUNCHBOX_API void * recreate(const std::string &filename, const size_t size)
Recreate a different writable file for this memory map.
LUNCHBOX_API void * create(const std::string &filename, const size_t size)
Create a writable file to a memory address.
LUNCHBOX_API const void * getAddress() const
LUNCHBOX_API ~MemoryMap()
Destruct the memory map.
Helper to map a file to a memory address (mmap).
Definition: memoryMap.h:36
LUNCHBOX_API const void * remap(const std::string &filename)
Remap a different file for this memory map.
LUNCHBOX_API void unmap()
Unmap the file.
LUNCHBOX_API const void * map(const std::string &filename)
Map a file to a memory address.
LUNCHBOX_API MemoryMap()
Construct a new memory map.
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
Definition: array.h:47
const T * getAddress() const
Definition: memoryMap.h:116