PolyWriter.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
Copyright (C) 2009 University of Aarhus
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "PolyWriter.h"
#include "BigPolynomial.h"
#include "Term.h"
namespace IO {
PolyWriter::PolyWriter(FILE* out):
_out(out),
_firstTerm(true) {
}
void PolyWriter::consumeRing(const VarNames& names) {
_names = names;
}
void PolyWriter::beginConsuming() {
_firstTerm = true;
doWriteHeader();
}
void PolyWriter::consume(const mpz_class& coef,
const Term& term,
const TermTranslator& translator) {
ASSERT(term.getVarCount() == _names.getVarCount());
bool firstTerm = _firstTerm; // To get tail recursion.
_firstTerm = false;
doWriteTerm(coef, term, translator, firstTerm);
}
void PolyWriter::consume(const mpz_class& coef, const vector<mpz_class>& term) {
ASSERT(term.size() == _names.getVarCount());
bool firstTerm = _firstTerm; // To get tail recursion.
_firstTerm = false;
doWriteTerm(coef, term, firstTerm);
}
void PolyWriter::doneConsuming() {
doWriteFooter(_firstTerm);
}
void PolyWriter::consume(const BigPolynomial& poly) {
consumeRing(poly.getNames());
_firstTerm = true;
doWriteHeader(poly.getTermCount());
for (size_t index = 0; index < poly.getTermCount(); ++index)
consume(poly.getCoef(index), poly.getTerm(index));
doneConsuming();
}
void PolyWriter::doWriteHeader(size_t generatorCount) {
doWriteHeader();
}
}
BigPolynomial.h
PolyWriter.h
Term.h
BigPolynomial
Definition BigPolynomial.h:27
BigPolynomial::getTerm
const vector< mpz_class > & getTerm(size_t index) const
Definition BigPolynomial.cpp:72
BigPolynomial::getTermCount
size_t getTermCount() const
Definition BigPolynomial.cpp:34
BigPolynomial::getCoef
const mpz_class & getCoef(size_t index) const
Definition BigPolynomial.cpp:66
BigPolynomial::getNames
const VarNames & getNames() const
Definition BigPolynomial.cpp:42
IO::PolyWriter::doWriteFooter
virtual void doWriteFooter(bool wasZero)=0
IO::PolyWriter::PolyWriter
PolyWriter(FILE *out)
Definition PolyWriter.cpp:25
IO::PolyWriter::doneConsuming
virtual void doneConsuming()
Definition PolyWriter.cpp:55
IO::PolyWriter::doWriteHeader
virtual void doWriteHeader()=0
IO::PolyWriter::beginConsuming
virtual void beginConsuming()
Definition PolyWriter.cpp:34
IO::PolyWriter::consumeRing
virtual void consumeRing(const VarNames &names)
Definition PolyWriter.cpp:30
IO::PolyWriter::_out
FILE *const _out
Definition PolyWriter.h:55
IO::PolyWriter::doWriteTerm
virtual void doWriteTerm(const mpz_class &coef, const Term &term, const TermTranslator &translator, bool firstGenerator)=0
IO::PolyWriter::_firstTerm
bool _firstTerm
Definition PolyWriter.h:56
IO::PolyWriter::_names
VarNames _names
Definition PolyWriter.h:57
IO::PolyWriter::consume
virtual void consume(const mpz_class &coef, const Term &term, const TermTranslator &translator)
Definition PolyWriter.cpp:39
TermTranslator
TermTranslator handles translation between terms whose exponents are infinite precision integers and ...
Definition TermTranslator.h:41
Term
Term represents a product of variables which does not include a coefficient.
Definition Term.h:49
Term::getVarCount
size_t getVarCount() const
Definition Term.h:85
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
IO
Definition CoCoA4IOHandler.cpp:33
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
ASSERT
#define ASSERT(X)
Definition stdinc.h:86