-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.hpp
131 lines (103 loc) · 2.69 KB
/
context.hpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
isl-cpp: C++ bindings to the ISL (Integer Set Library)
Copyright (C) 2014 Jakob Leben <jakob.leben@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ISL_CPP_CONTEXT_INCLUDED
#define ISL_CPP_CONTEXT_INCLUDED
#include <isl/ctx.h>
#include <isl/options.h>
#include <memory>
#include <unordered_map>
#include <string>
#include <exception>
namespace isl {
using std::string;
class matrix;
class set;
class map;
class printer;
class context
{
public:
enum error_action
{
warn_on_error = ISL_ON_ERROR_WARN,
continue_on_error = ISL_ON_ERROR_CONTINUE,
abort_on_error = ISL_ON_ERROR_ABORT
};
context(): d( new data() )
{
m_store.emplace(d.get()->ctx, d);
}
context( const context & other ):
d(other.d)
{}
context( isl_ctx * ctx )
{
if (ctx == nullptr)
return;
auto iter = m_store.find(ctx);
if (iter != m_store.end())
{
d = iter->second.lock();
}
else
{
d = std::shared_ptr<data>( new data(ctx) );
m_store.emplace(ctx, d);
}
}
void set_error_action( int action )
{
isl_options_set_on_error(get(), action);
}
int error_action() const
{
return isl_options_get_on_error(get());
}
isl_ctx *get() const { return d->ctx; }
private:
struct data
{
data(isl_ctx * ctx): ctx(ctx) {}
data()
{
ctx = isl_ctx_alloc();
//isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
}
~data()
{
context::m_store.erase(ctx);
isl_ctx_free(ctx);
}
isl_ctx *ctx;
};
friend class data;
std::shared_ptr<data> d;
static std::unordered_map<isl_ctx*, std::weak_ptr<data>> m_store;
};
class error : public std::exception
{
public:
error() {}
error( const string & what ): m_what(what) {}
virtual const char *what()
{
return m_what.c_str();
}
private:
string m_what;
};
}
#endif // ISL_CPP_CONTEXT_INCLUDED