IdealWriter.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2009 University of Aarhus
Contact Bjarke Hammersholt Roune for license information (www.broune.com)
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 "IdealWriter.h"
#include "BigIdeal.h"
#include "Term.h"
namespace IO {
IdealWriter::IdealWriter(FILE* out):
_out(out),
_firstIdeal(true),
_firstGenerator(true) {
}
void IdealWriter::consumeRing(const VarNames& names) {
if (_names != names) {
_names = names;
_firstIdeal = true;
}
}
void IdealWriter::beginConsumingList() {
_firstIdeal = true;
}
void IdealWriter::beginConsuming() {
_firstGenerator = true;
doWriteHeader(_firstIdeal);
}
void IdealWriter::consume(const Term& term, const TermTranslator& translator) {
ASSERT(term.getVarCount() == _names.getVarCount());
bool firstGenerator = _firstGenerator; // To get tail recursion.
_firstGenerator = false;
doWriteTerm(term, translator, firstGenerator);
}
void IdealWriter::consume(const vector<mpz_class>& term) {
ASSERT(term.size() == _names.getVarCount());
bool firstGenerator = _firstGenerator; // To get tail recursion.
_firstGenerator = false;
doWriteTerm(term, firstGenerator);
}
void IdealWriter::doneConsuming() {
_firstIdeal = false;
doWriteFooter(_firstGenerator);
}
void IdealWriter::doneConsumingList() {
if (_firstIdeal)
doWriteEmptyList();
}
void IdealWriter::consume(const BigIdeal& ideal) {
consumeRing(ideal.getNames());
_firstGenerator = true;
doWriteHeader(_firstIdeal, ideal.getGeneratorCount());
for (size_t term = 0; term < ideal.getGeneratorCount(); ++term)
consume(ideal.getTerm(term));
doneConsuming();
}
void IdealWriter::doWriteHeader(bool firstIdeal, size_t generatorCount) {
doWriteHeader(firstIdeal);
}
}
BigIdeal.h
IdealWriter.h
Term.h
BigIdeal
Definition BigIdeal.h:27
BigIdeal::getTerm
const vector< mpz_class > & getTerm(size_t term) const
Definition BigIdeal.h:139
BigIdeal::getNames
const VarNames & getNames() const
Definition BigIdeal.cpp:253
BigIdeal::getGeneratorCount
size_t getGeneratorCount() const
Definition BigIdeal.h:144
IO::IdealWriter::_firstGenerator
bool _firstGenerator
Definition IdealWriter.h:59
IO::IdealWriter::_out
FILE *const _out
Definition IdealWriter.h:57
IO::IdealWriter::consume
virtual void consume(const Term &term, const TermTranslator &translator)
Definition IdealWriter.cpp:47
IO::IdealWriter::doneConsumingList
virtual void doneConsumingList()
Must be called once after each time beginConsumingList has been called.
Definition IdealWriter.cpp:66
IO::IdealWriter::doneConsuming
virtual void doneConsuming()
Must be called once after each time beginConsuming has been called.
Definition IdealWriter.cpp:61
IO::IdealWriter::IdealWriter
IdealWriter(FILE *out)
Definition IdealWriter.cpp:25
IO::IdealWriter::doWriteTerm
virtual void doWriteTerm(const Term &term, const TermTranslator &translator, bool firstGenerator)=0
IO::IdealWriter::doWriteEmptyList
virtual void doWriteEmptyList()=0
IO::IdealWriter::doWriteHeader
virtual void doWriteHeader(bool firstIdeal, size_t generatorCount)
Definition IdealWriter.cpp:81
IO::IdealWriter::beginConsuming
virtual void beginConsuming()
Tell the consumer to begin consuming an ideal.
Definition IdealWriter.cpp:42
IO::IdealWriter::consumeRing
virtual void consumeRing(const VarNames &names)
Tell the consumer which ring is being used.
Definition IdealWriter.cpp:31
IO::IdealWriter::_firstIdeal
bool _firstIdeal
Definition IdealWriter.h:58
IO::IdealWriter::_names
VarNames _names
Definition IdealWriter.h:60
IO::IdealWriter::doWriteFooter
virtual void doWriteFooter(bool wasZeroIdeal)=0
IO::IdealWriter::beginConsumingList
virtual void beginConsumingList()
Tell the consumer that the ideals that are consumed until the next call to doneConsumingList are to b...
Definition IdealWriter.cpp:38
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