Frobby  0.9.5
PolyWriter.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3  Copyright (C) 2009 University of Aarhus
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see http://www.gnu.org/licenses/.
17 */
18 #include "stdinc.h"
19 #include "PolyWriter.h"
20 
21 #include "BigPolynomial.h"
22 #include "Term.h"
23 
24 namespace IO {
26  _out(out),
27  _firstTerm(true) {
28  }
29 
30  void PolyWriter::consumeRing(const VarNames& names) {
31  _names = names;
32  }
33 
35  _firstTerm = true;
36  doWriteHeader();
37  }
38 
39  void PolyWriter::consume(const mpz_class& coef,
40  const Term& term,
41  const TermTranslator& translator) {
42  ASSERT(term.getVarCount() == _names.getVarCount());
43  bool firstTerm = _firstTerm; // To get tail recursion.
44  _firstTerm = false;
45  doWriteTerm(coef, term, translator, firstTerm);
46  }
47 
48  void PolyWriter::consume(const mpz_class& coef, const vector<mpz_class>& term) {
49  ASSERT(term.size() == _names.getVarCount());
50  bool firstTerm = _firstTerm; // To get tail recursion.
51  _firstTerm = false;
52  doWriteTerm(coef, term, firstTerm);
53  }
54 
57  }
58 
59  void PolyWriter::consume(const BigPolynomial& poly) {
60  consumeRing(poly.getNames());
61  _firstTerm = true;
63  for (size_t index = 0; index < poly.getTermCount(); ++index)
64  consume(poly.getCoef(index), poly.getTerm(index));
65  doneConsuming();
66  }
67 
68  void PolyWriter::doWriteHeader(size_t generatorCount) {
69  doWriteHeader();
70  }
71 }
const vector< mpz_class > & getTerm(size_t index) const
size_t getTermCount() const
const mpz_class & getCoef(size_t index) const
const VarNames & getNames() const
virtual void doWriteFooter(bool wasZero)=0
PolyWriter(FILE *out)
Definition: PolyWriter.cpp:25
virtual void doneConsuming()
Definition: PolyWriter.cpp:55
virtual void doWriteHeader()=0
virtual void beginConsuming()
Definition: PolyWriter.cpp:34
virtual void consumeRing(const VarNames &names)
Definition: PolyWriter.cpp:30
virtual void doWriteTerm(const mpz_class &coef, const Term &term, const TermTranslator &translator, bool firstGenerator)=0
VarNames _names
Definition: PolyWriter.h:57
virtual void consume(const mpz_class &coef, const Term &term, const TermTranslator &translator)
Definition: PolyWriter.cpp:39
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Term represents a product of variables which does not include a coefficient.
Definition: Term.h:49
size_t getVarCount() const
Definition: Term.h:85
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40
size_t getVarCount() const
Returns the current number of variables.
Definition: VarNames.h:113
#define ASSERT(X)
Definition: stdinc.h:86