doc: update gen_fun documentation
[barvinok.git] / edomain.h
blobf32e977196e44c30ca78f3b81ff2794afb94c493
1 #include <iostream>
2 #include <vector>
3 #include <gmp.h>
4 extern "C" {
5 #include <polylib/polylibgmp.h>
7 #include <barvinok/evalue.h>
8 #include <barvinok/options.h>
10 struct EDomain_floor {
11 int refcount;
12 evalue *e;
13 Vector *v;
15 EDomain_floor(const evalue *f, int dim);
16 ~EDomain_floor() {
17 free_evalue_refs(e);
18 delete e;
19 Vector_Free(v);
21 EDomain_floor *ref() {
22 ++refcount;
23 return this;
25 static void unref(EDomain_floor* floor) {
26 if (!--floor->refcount)
27 delete floor;
29 void print(std::ostream& os, char **p) const;
30 void eval(Value *values, Value *res) const;
33 struct EDomain {
34 Polyhedron *D;
35 Vector *sample;
36 std::vector<EDomain_floor *> floors;
38 EDomain(Polyhedron *D) {
39 this->D = Polyhedron_Copy(D);
40 sample = NULL;
42 EDomain(Polyhedron *D, std::vector<EDomain_floor *>floors) {
43 this->D = Polyhedron_Copy(D);
44 add_floors(floors);
45 sample = NULL;
47 EDomain(EDomain *ED) {
48 this->D = Polyhedron_Copy(ED->D);
49 add_floors(ED->floors);
50 sample = NULL;
52 EDomain(Polyhedron *D, EDomain *ED, std::vector<EDomain_floor *>floors) {
53 this->D = Polyhedron_Copy(D);
54 add_floors(ED->floors);
55 add_floors(floors);
56 sample = NULL;
58 void add_floors(std::vector<EDomain_floor *>floors) {
59 for (int i = 0; i < floors.size(); ++i)
60 this->floors.push_back(floors[i]->ref());
62 int find_floor(evalue *needle) const {
63 for (int i = 0; i < floors.size(); ++i)
64 if (eequal(needle, floors[i]->e))
65 return i;
66 return -1;
68 void print(FILE *out, char **p);
69 void print_constraints(std::ostream& os, char **p,
70 barvinok_options *options) const;
71 ~EDomain() {
72 for (int i = 0; i < floors.size(); ++i)
73 EDomain_floor::unref(floors[i]);
74 Polyhedron_Free(D);
75 if (sample)
76 Vector_Free(sample);
79 unsigned dimension() const {
80 return D->Dimension - floors.size();
82 bool contains(Value *point, int len) const;
84 Matrix *add_ge_constraint(evalue *constraint,
85 std::vector<EDomain_floor *>& new_floors) const;
88 int evalue2constraint(EDomain *D, evalue *E, Value *cons, int len);