1 /* Frobby: Software for monomial ideal computations.
2    Copyright (C) 2009 Bjarke Hammersholt Roune (www.broune.com)
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see http://www.gnu.org/licenses/.
16 */
17 #ifndef LIB_TEST_GUARD
18 #define LIB_TEST_GUARD
19 
20 #include "frobby.h"
21 #include "BigIdeal.h"
22 #include "BigPolynomial.h"
23 
24 #include <vector>
25 
26 /** Returns a library interface ideal that corresponds to the
27  parameter ideal.
28 */
29 Frobby::Ideal toLibIdeal(const BigIdeal& ideal);
30 
31 /** Returns a pointer to an array of mpt_t that represents the entries
32  in the mpz_class. The array is actually just the memory of the
33  vector, so the life time of the array is until the vector deallocates
34  or reallocates its array.
35 */
36 const mpz_t* castLibArray(const vector<mpz_class>& vect);
37 
38 /** Records library interface output into a BigIdeal. */
39 class LibIdealConsumer : public Frobby::IdealConsumer {
40  public:
41   LibIdealConsumer(const VarNames& names);
42 
43   virtual void idealBegin(size_t varCount);
44   virtual void consume(mpz_ptr* exponentVector);
45 
46   /** Returns the recorded ideal in a canonical form. */
47   const BigIdeal& getIdeal() const;
48 
49   /** Returns whether any ideal has been recorded. */
50   bool hasAnyOutput() const;
51 
52 private:
53   bool _hasAnyOutput;
54   mutable BigIdeal _ideal;
55 };
56 
57 /** Records library interface output into a vector of BigIdeals. */
58 class LibIdealsConsumer : public Frobby::IdealConsumer {
59 public:
60   LibIdealsConsumer(const VarNames& names);
61 
62   virtual void idealBegin(size_t varCount);
63   virtual void consume(mpz_ptr* exponentVector);
64 
65   /** Returns the recorded ideals in a canonical form. */
66   const vector<BigIdeal>& getIdeals() const;
67 
68 private:
69   mutable vector<BigIdeal> _ideals;
70   VarNames _names;
71 };
72 
73 /** Records library interface output into a BigPolynomial. */
74 class LibPolynomialConsumer : public Frobby::PolynomialConsumer {
75  public:
76   LibPolynomialConsumer(const VarNames& names);
77 
78   virtual void polynomialBegin(size_t varCount);
79   virtual void consume(const mpz_t coef, mpz_ptr* exponentVector);
80 
81   /** Returns the recorded polynomial in a canonical form. */
82   const BigPolynomial& getPolynomial() const;
83 
84  private:
85   mutable BigPolynomial _polynomial;
86 };
87 
88 #endif
89