-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.hpp
More file actions
80 lines (67 loc) · 2.47 KB
/
value.hpp
File metadata and controls
80 lines (67 loc) · 2.47 KB
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
/*
isl-cpp: C++ bindings to the ISL (Integer Set Library)
Copyright (C) 2014 Jakob Leben <[email protected]>
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_VALUE_INCLUDED
#define ISL_CPP_VALUE_INCLUDED
#include "object.hpp"
#include "printer.hpp"
#include <isl/val.h>
#include <cassert>
namespace isl {
template<>
struct object_behavior<isl_val>
{
static isl_val * copy( isl_val * obj )
{
return isl_val_copy(obj);
}
static void destroy( isl_val *obj )
{
isl_val_free(obj);
}
static isl_ctx * get_context( isl_val * obj )
{
return isl_val_get_ctx(obj);
}
};
class value : public object<isl_val>
{
public:
value( isl_val *v ): object(v) {}
value( const context & ctx, long v ):
object(ctx, isl_val_int_from_si(ctx.get(), v)) {}
value( const context & ctx, unsigned long v ):
object(ctx, isl_val_int_from_ui(ctx.get(), v)) {}
value( const context & ctx, int v ):
object(ctx, isl_val_int_from_si(ctx.get(), v)) {}
value( const context & ctx, unsigned int v ):
object(ctx, isl_val_int_from_ui(ctx.get(), v)) {}
long numerator() const { return isl_val_get_num_si(get()); }
long denominator() const { return isl_val_get_den_si(get()); }
double real() const { return isl_val_get_d(get()); }
bool is_integer() const { return isl_val_is_int(get()); }
bool is_infinity() const { return is_pos_infinity() || is_neg_infinity(); }
bool is_pos_infinity() const { return isl_val_is_infty(get()); }
bool is_neg_infinity() const { return isl_val_is_neginfty(get()); }
long integer() const { assert(is_integer()); return numerator(); }
value operator-() const { return isl_val_neg(copy()); }
};
template<> inline
void printer::print<value>( const value & v )
{
m_printer = isl_printer_print_val(m_printer, v.get());
}
}
#endif