-
Notifications
You must be signed in to change notification settings - Fork 4
/
WorkFile.cpp
78 lines (65 loc) · 1.44 KB
/
WorkFile.cpp
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
74
75
76
77
78
/*
Pharmit
Copyright (c) David Ryan Koes, University of Pittsburgh and contributors.
All rights reserved.
Pharmit is licensed under both the BSD 3-clause license and the GNU
Public License version 2. Any use of the code that retains its reliance
on the GPL-licensed OpenBabel library is subject to the terms of the GPL2.
Use of the Pharmit code independently of OpenBabel (or any other
GPL2 licensed software) may choose between the BSD or GPL licenses.
See the LICENSE file provided with the distribution for more information.
*/
/*
* WorkFile2.cpp
*
* Created on: Oct 18, 2011
* Author: dkoes
*/
#include "WorkFile.h"
#include <fstream>
#include <iostream>
using namespace boost::interprocess;
WorkFile::WorkFile(const char *name): map(NULL)
{
file = new ofstream(name);
assert(*file);
mapping = new file_mapping(name, read_only);
}
WorkFile::~WorkFile()
{
//these must be manually cleared
}
void WorkFile::set(const char *name)
{
clear();
file = new ofstream(name);
mapping = new file_mapping(name, read_only);
}
void WorkFile::switchToMap()
{
if(map == NULL)
{
file->close();
map = new mapped_region(*mapping, read_only);
}
}
//deallocate and reset
void WorkFile::clear()
{
if(file) {
delete file;
}
if(mapping) delete mapping;
if(map) delete map;
file = NULL;
mapping = NULL;
map = NULL;
}
void WorkFile::remove()
{
if(file == NULL)
return;
file->close();
boost::filesystem::remove(mapping->get_name());
clear();
}