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