File: MappedFile.h

package info (click to toggle)
fastdep 0.16-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 596 kB
  • ctags: 323
  • sloc: cpp: 2,144; ansic: 814; sh: 208; makefile: 124
file content (73 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef __MAPPEDFILE_H__
#define __MAPPEDFILE_H__

#include <string>

#ifdef WIN32

#include <windows.h> 

struct MapFileData
{	
	HANDLE 		hFile;
	HANDLE 		hFileMapping;
};

#else

struct MapFileData
{	
	int mapsize;
	int fd;
};

#endif

/** Class MappedFile creates memory file mapping.
 *
 *  Works with Windows Mingw GCC, VC++.NET and on Unix
 */
class MappedFile : MapFileData
{	
	bool 		opened_;
	long 		file_size;
	time_t 		last_change;	
	char* 		map_;	
	
public:

	/** C'tor
	 *
	 */
	MappedFile() : opened_(false),file_size(0),map_(0){}
	
	/** D'tor
	 *
	 */
	virtual ~MappedFile();

	/** Size of the opened file.
	 *
	 */
	long size() const {return file_size; }

	/** Modification time of the opened file.
	 *
	 */
	time_t time() const {return last_change; }

	/** Opens a file for memory mapping
	 *
	 */
	bool open(const std::string& name);

	/** Maps the file into memory
	 *
	 */
	char* map() throw (std::string) ;
};

#endif // __MAPPEDFILE_H__

// vim:ts=4:nu
//