Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mmap.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_MMAP_H_)
21 #define __MITSUBA_CORE_MMAP_H_
22 
23 #include <mitsuba/core/fstream.h>
24 #include <boost/scoped_ptr.hpp>
25 
27 
28 /**
29  * \brief Basic cross-platform abstraction for memory mapped files
30  * \ingroup libcore
31  */
33 public:
34  /// Create a new memory-mapped file of the specified size
35  MemoryMappedFile(const fs::path &filename, size_t size);
36 
37  /// Map the specified file into memory
38  MemoryMappedFile(const fs::path &filename, bool readOnly = true);
39 
40  /// Return a pointer to the file contents in memory
41  void *getData();
42 
43  /// Return a pointer to the file contents in memory (const version)
44  const void *getData() const;
45 
46  /// Return the size of the mapped region
47  size_t getSize() const;
48 
49  /**
50  * \brief Resize the memory-mapped file
51  *
52  * This involves remapping the file, which will
53  * generally change the pointer obtained via getData()
54  */
55  void resize(size_t size);
56 
57  /// Return the associated filename
58  const fs::path &getFilename() const;
59 
60  /// Return whether the mapped memory region is read-only
61  bool isReadOnly() const;
62 
63  /// Return a string representation
64  std::string toString() const;
65 
66  /**
67  * \brief Create a temporary memory-mapped file
68  *
69  * \remark When closing the mapping, the file is
70  * automatically deleted.
71  */
72  static ref<MemoryMappedFile> createTemporary(size_t size);
73 
75 protected:
76  /// Internal constructor
78 
79  /// Release all resources
80  virtual ~MemoryMappedFile();
81 private:
82  struct MemoryMappedFilePrivate;
83  boost::scoped_ptr<MemoryMappedFilePrivate> d;
84 };
85 
87 
88 #endif /* __MITSUBA_CORE_MMAP_H_ */
#define MTS_EXPORT_CORE
Definition: getopt.h:29
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Basic cross-platform abstraction for memory mapped files.
Definition: mmap.h:32
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Reference counting helper.
Definition: ref.h:40
Parent of all Mitsuba classes.
Definition: object.h:38
virtual std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
#define MTS_NAMESPACE_END
Definition: platform.h:138