APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_manager_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_manager_inline.hh
3 *
4 * APRON Library / C++ inline functions
5 *
6 * DO NOT INCLUDE THIS FILE DIRECTLY
7 *
8 * Copyright (C) Antoine Mine' 2007
9 *
10 */
11/* This file is part of the APRON Library, released under LGPL license
12 with an exception allowing the redistribution of statically linked
13 executables.
14
15 Please read the COPYING file packaged in the distribution.
16*/
17
18
19/* =============== */
20/* tbool_t */
21/* =============== */
22
23inline tbool::tbool(bool a) : x(a ? tbool_true : tbool_false)
24{
25}
26
27inline tbool::tbool(tbool_t a) : x(a)
28{
29}
30
31inline tbool::operator tbool_t()
32{
33 return x;
34}
35
36inline tbool::operator bool()
37{
38 return x==tbool_true;
39}
40
41inline tbool operator|| (tbool a, tbool b)
42{
43 return tbool(tbool_or(a.x,b.x));
44}
45
46inline tbool operator&& (tbool a, tbool b)
47{
48 return tbool(tbool_and(a.x,b.x));
49}
50
51inline tbool operator! (tbool a)
52{
53 return tbool(tbool_not(a.x));
54}
55
56inline std::ostream& operator<<(std::ostream& os, tbool x)
57{
58 switch (x.x) {
59 case tbool_true: return os << "true";
60 case tbool_false: return os << "false";
61 case tbool_top: return os << "top";
62 default: throw std::invalid_argument("apron::operator<<(ostream&, tbool) invalid boolean");
63 }
64}
65
66
67
68/* =============== */
69/* manager */
70/* =============== */
71
72
73
74inline manager::manager(ap_manager_t* m) : m(m)
75{
76 if (!m) throw std::invalid_argument("apron::manager::manager(ap_manager_t* m) m is NULL");
77 // disable aborting as we manually check exception flags and throw C++ exceptions (see raise)
78 for (size_t i=0; i<AP_EXC_SIZE; i++)
79 m->option.abort_if_exception[i] = 0;
80}
81
82inline bool manager::exception_raised()
83{
84 return (m->result.exclog && m->result.exclog->exn!=AP_EXC_NONE);
85}
86
87// called at the end of every abstract function
88inline void manager::raise(ap_manager_t* m, const char* msg, ap_abstract0_t* a)
89{
90 if (!m->result.exclog) return;
91
92 std::string s = std::string(msg)+" : "+m->result.exclog->msg;
93
94 switch (m->result.exclog->exn) {
95
96 case AP_EXC_NONE:
97 break;
98
99 case AP_EXC_TIMEOUT:
100 ap_manager_clear_exclog(m);
101 if (a) ap_abstract0_free(m,a);
102 throw timeout(s);
103 break;
104
105 case AP_EXC_OUT_OF_SPACE:
106 ap_manager_clear_exclog(m);
107 if (a) ap_abstract0_free(m,a);
108 throw std::length_error(s);
109 break;
110
111 case AP_EXC_OVERFLOW:
112 ap_manager_clear_exclog(m);
113 if (a) ap_abstract0_free(m,a);
114 throw std::overflow_error(s);
115 break;
116
117 case AP_EXC_INVALID_ARGUMENT:
118 ap_manager_clear_exclog(m);
119 if (a) ap_abstract0_free(m,a);
120 throw std::invalid_argument(s);
121 break;
122
123 case AP_EXC_NOT_IMPLEMENTED:
124 ap_manager_clear_exclog(m);
125 if (a) ap_abstract0_free(m,a);
126 throw not_implemented(s);
127 break;
128
129 default:
130 ap_manager_clear_exclog(m);
131 if (a) ap_abstract0_free(m,a);
132 throw std::range_error(s+" (unknwon exception type)");
133 break;
134 }
135}
136
137inline void manager::raise(const char* msg, ap_abstract0_t* a)
138{
139 manager::raise(m, msg, a);
140}
141
142inline void manager::raise(ap_manager_t* m, const char* msg, ap_abstract1_t a)
143{
144 if (!m->result.exclog || m->result.exclog->exn==AP_EXC_NONE) return;
145 ap_environment_free(a.env);
146 raise(m,msg,a.abstract0);
147
148}
149
150inline void manager::raise(const char* msg, ap_abstract1_t a)
151{
152 manager::raise(m, msg, a);
153}
154
155inline manager::manager(const manager& x)
156 : m(ap_manager_copy(x.m))
157{
158}
159
160inline manager::~manager()
161{
162 ap_manager_free(m);
163}
164
165inline manager& manager::operator= (const manager& x)
166{
167 ap_manager_t* mm = ap_manager_copy(x.m);
168 ap_manager_free(m);
169 m = mm;
170 return *this;
171}
172
173inline std::string manager::get_library() const
174{
175 return std::string(ap_manager_get_library(m));
176}
177
178inline std::string manager::get_version() const
179{
180 return std::string(ap_manager_get_version(m));
181}
182
183inline ap_funopt_t& manager::get_funopt(ap_funid_t funid)
184{
185 if (funid<=AP_FUNID_UNKNOWN || funid>=AP_FUNID_SIZE)
186 throw std::out_of_range("apron::manager::get_funopt(ap_funid_t) unknown funid");
187 return m->option.funopt[funid];
188}
189
190inline ap_scalar_discr_t& manager::get_scalar_discr()
191{
192 return m->option.scalar_discr;
193}
194
195inline bool manager::get_flag_exact()
196{
197 return ap_manager_get_flag_exact(m);
198}
199
200inline bool manager::get_flag_best()
201{
202 return ap_manager_get_flag_best(m);
203}
204
205
206inline ap_manager_t* manager::get_ap_manager_t()
207{
208 return m;
209}
210
211inline const ap_manager_t* manager::get_ap_manager_t() const
212{
213 return m;
214}
215
216inline void manager::fpu_init()
217{
218 if (!ap_fpu_init())
219 throw std::runtime_error("apron::manager::fpu_init() failed");
220}
221
222inline std::ostream& operator<< (std::ostream& os, const manager& s)
223{
224 return os << ap_manager_get_library(s.m) << ", " << ap_manager_get_version(s.m);
225}
tbool operator!(tbool a)
Definition apxx_manager_inline.hh:51
tbool operator&&(tbool a, tbool b)
Definition apxx_manager_inline.hh:46
std::ostream & operator<<(std::ostream &os, tbool x)
Definition apxx_manager_inline.hh:56
tbool operator||(tbool a, tbool b)
Definition apxx_manager_inline.hh:41