gen_fun: add copy constructor
[barvinok.git] / barvinok / genfun.h
blob2bfb0627af44074c158621159d10c6e559f59fb2
1 #ifndef GENFUN_H
2 #define GENFUN_H
4 #include <vector>
5 #include <gmp.h>
6 #include <NTL/mat_ZZ.h>
7 extern "C" {
8 #include <polylib/polylibgmp.h>
9 #include <barvinok/evalue.h>
12 #ifdef NTL_STD_CXX
13 using namespace NTL;
14 #endif
16 struct short_rat {
17 struct __short_rat_n {
18 /* rows: terms in numerator */
19 /* coeff has two columns: the numerator and the denominator */
20 mat_ZZ coeff;
21 mat_ZZ power;
22 } n;
23 struct __short_rat_d {
24 /* rows: factors in denominator */
25 mat_ZZ power;
26 } d;
27 void add(short_rat *rat);
28 bool reduced();
31 struct gen_fun {
32 std::vector< short_rat * > term;
33 Polyhedron *context;
35 void add(const ZZ& cn, const ZZ& cd, const vec_ZZ& num,
36 const mat_ZZ& den);
37 /* add cn/cd times gf */
38 void add(const ZZ& cn, const ZZ& cd, const gen_fun *gf);
39 void substitute(Matrix *CP, const mat_ZZ& map, const vec_ZZ& offset);
40 gen_fun *Hadamard_product(gen_fun *gf, unsigned MaxRays);
41 void add_union(gen_fun *gf, unsigned MaxRays);
42 void print(unsigned int nparam, char **param_name) const;
43 operator evalue *() const;
44 void coefficient(Value* params, Value* c) const;
46 gen_fun(const gen_fun *gf) {
47 ZZ one;
48 one = 1;
49 context = Polyhedron_Copy(gf->context);
50 add(one, one, gf);
52 gen_fun(Polyhedron *C = NULL) : context(C) {}
53 ~gen_fun() {
54 if (context)
55 Polyhedron_Free(context);
56 for (int i = 0; i < term.size(); ++i)
57 delete term[i];
61 #endif