NewMonosIOHandler.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (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 "NewMonosIOHandler.h"
#include "Scanner.h"
#include "VarNames.h"
#include "BigTermConsumer.h"
#include "DataType.h"
#include "IdealWriter.h"
#include "error.h"
#include "InputConsumer.h"
#include <cstdio>
namespace IO {
namespace NewMonos {
void writeRing(const VarNames& names, FILE* out);
void readRingNoLeftParen(Scanner& in, VarNames& names);
void readIdealNoLeftParen(Scanner& in, InputConsumer& consumer);
}
namespace N = NewMonos;
class NewMonosIdealWriter : public IdealWriter {
public:
NewMonosIdealWriter(FILE* out): IdealWriter(out) {
}
private:
virtual void doWriteHeader(bool first) {
fputs("(monomial-ideal-with-order\n ", getFile());
N::writeRing(getNames(), getFile());
}
virtual void doWriteTerm(const Term& term,
const TermTranslator& translator,
bool first) {
fputs("\n ", getFile());
writeTermProduct(term, translator, getFile());
}
virtual void doWriteTerm(const vector<mpz_class>& term,
bool first) {
fputs("\n ", getFile());
writeTermProduct(term, getNames(), getFile());
}
virtual void doWriteFooter(bool wasZeroIdeal) {
fputs("\n)\n", getFile());
}
virtual void doWriteEmptyList() {
N::writeRing(getNames(), getFile());
}
};
NewMonosIOHandler::NewMonosIOHandler():
IOHandlerImpl(staticGetName(), "Newer format used by the program Monos.") {
registerInput(DataType::getMonomialIdealType());
registerInput(DataType::getMonomialIdealListType());
registerOutput(DataType::getMonomialIdealType());
}
const char* NewMonosIOHandler::staticGetName() {
return "newmonos";
}
BigTermConsumer* NewMonosIOHandler::doCreateIdealWriter(FILE* out) {
return new NewMonosIdealWriter(out);
}
void NewMonosIOHandler::doWriteTerm(const vector<mpz_class>& term,
const VarNames& names,
FILE* out) {
writeTermProduct(term, names, out);
}
void NewMonosIOHandler::doReadTerm(Scanner& in, InputConsumer& consumer) {
consumer.consumeTermProductNotation(in);
}
void NewMonosIOHandler::doReadIdeal(Scanner& in, InputConsumer& consumer) {
in.expect('(');
N::readIdealNoLeftParen(in, consumer);
}
void NewMonosIOHandler::doReadIdeals(Scanner& in, InputConsumer& consumer) {
in.expect('(');
if (in.peek('l') || in.peek('L')) {
VarNames names;
N::readRingNoLeftParen(in, names);
consumer.consumeRing(names);
return;
}
do {
N::readIdealNoLeftParen(in, consumer);
} while (in.match('('));
}
void N::writeRing(const VarNames& names, FILE* out) {
fputs("(lex-order", out);
for (unsigned int i = 0; i < names.getVarCount(); ++i) {
putc(' ', out);
fputs(names.getName(i).c_str(), out);
}
fputc(')', out);
}
void N::readRingNoLeftParen(Scanner& in, VarNames& names) {
in.expect("lex-order");
while (!in.match(')'))
names.addVarSyntaxCheckUnique(in, in.readIdentifier());
}
void N::readIdealNoLeftParen(Scanner& in, InputConsumer& consumer) {
in.expect("monomial-ideal-with-order");
VarNames names;
in.expect('(');
N::readRingNoLeftParen(in, names);
consumer.consumeRing(names);
consumer.beginIdeal();
while (!in.match(')'))
consumer.consumeTermProductNotation(in);
consumer.endIdeal();
}
}
BigTermConsumer.h
DataType.h
IdealWriter.h
InputConsumer.h
NewMonosIOHandler.h
Scanner.h
VarNames.h
BigTermConsumer
Definition BigTermConsumer.h:29
DataType::getMonomialIdealListType
static const DataType & getMonomialIdealListType()
Returns the one and only instance for monomial ideal lists.
Definition DataType.cpp:54
DataType::getMonomialIdealType
static const DataType & getMonomialIdealType()
Returns the one and only instance for monomial ideals.
Definition DataType.cpp:45
IO::IOHandlerImpl::registerInput
void registerInput(const DataType &type)
Specify that input of the argument type is supported.
Definition IOHandlerImpl.cpp:60
IO::IOHandlerImpl::IOHandlerImpl
IOHandlerImpl(const char *formatName, const char *formatDescription)
Definition IOHandlerImpl.cpp:36
IO::IOHandlerImpl::registerOutput
void registerOutput(const DataType &type)
Specify that output of the argument type is supported.
Definition IOHandlerImpl.cpp:67
IO::IdealWriter::getFile
FILE * getFile()
Definition IdealWriter.h:43
IO::IdealWriter::IdealWriter
IdealWriter(FILE *out)
Definition IdealWriter.cpp:25
IO::IdealWriter::getNames
const VarNames & getNames()
Definition IdealWriter.h:44
IO::NewMonosIOHandler::doReadTerm
virtual void doReadTerm(Scanner &in, InputConsumer &consumer)
Definition NewMonosIOHandler.cpp:92
IO::NewMonosIOHandler::doCreateIdealWriter
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)
Definition NewMonosIOHandler.cpp:82
IO::NewMonosIOHandler::doReadIdeal
void doReadIdeal(Scanner &in, InputConsumer &consumer)
Definition NewMonosIOHandler.cpp:96
IO::NewMonosIOHandler::doWriteTerm
virtual void doWriteTerm(const vector< mpz_class > &term, const VarNames &names, FILE *out)
Definition NewMonosIOHandler.cpp:86
IO::NewMonosIOHandler::staticGetName
static const char * staticGetName()
Definition NewMonosIOHandler.cpp:78
IO::NewMonosIOHandler::NewMonosIOHandler
NewMonosIOHandler()
Definition NewMonosIOHandler.cpp:71
IO::NewMonosIOHandler::doReadIdeals
void doReadIdeals(Scanner &in, InputConsumer &consumer)
Definition NewMonosIOHandler.cpp:101
IO::NewMonosIdealWriter
Definition NewMonosIOHandler.cpp:38
IO::NewMonosIdealWriter::doWriteEmptyList
virtual void doWriteEmptyList()
Definition NewMonosIOHandler.cpp:66
IO::NewMonosIdealWriter::doWriteTerm
virtual void doWriteTerm(const Term &term, const TermTranslator &translator, bool first)
Definition NewMonosIOHandler.cpp:49
IO::NewMonosIdealWriter::NewMonosIdealWriter
NewMonosIdealWriter(FILE *out)
Definition NewMonosIOHandler.cpp:40
IO::NewMonosIdealWriter::doWriteTerm
virtual void doWriteTerm(const vector< mpz_class > &term, bool first)
Definition NewMonosIOHandler.cpp:56
IO::NewMonosIdealWriter::doWriteHeader
virtual void doWriteHeader(bool first)
Definition NewMonosIOHandler.cpp:44
IO::NewMonosIdealWriter::doWriteFooter
virtual void doWriteFooter(bool wasZeroIdeal)
Definition NewMonosIOHandler.cpp:62
InputConsumer
Definition InputConsumer.h:30
InputConsumer::beginIdeal
void beginIdeal()
Start consuming an ideal.
Definition InputConsumer.cpp:50
InputConsumer::consumeTermProductNotation
void consumeTermProductNotation(Scanner &in)
Reads a term in a format like "a^4*b*c^2".
Definition InputConsumer.cpp:148
InputConsumer::consumeRing
void consumeRing(const VarNames &names)
Definition InputConsumer.cpp:33
InputConsumer::endIdeal
void endIdeal()
Done reading an ideal.
Definition InputConsumer.cpp:191
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
Scanner::peek
bool peek(char character)
Skips whitespace and returns true if the next character is equal to the parameter(s).
Definition Scanner.h:262
Scanner::expect
void expect(char expected)
Require the next character to be equal to expected.
Definition Scanner.h:231
Scanner::readIdentifier
const char * readIdentifier()
The returned string is only valid until the next method on this object gets called.
Definition Scanner.cpp:255
Scanner::match
bool match(char c)
Return true if the next character is c, and in that case skip past it.
Definition Scanner.h:215
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
VarNames
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
VarNames::getVarCount
size_t getVarCount() const
Returns the current number of variables.
Definition VarNames.h:113
VarNames::getName
const string & getName(size_t index) const
The returned reference can become invalid next time addVar is called.
Definition VarNames.cpp:100
VarNames::addVarSyntaxCheckUnique
void addVarSyntaxCheckUnique(const Scanner &in, const string &name)
As addvar, except it reports a syntax error if name is already a variable.
Definition VarNames.cpp:68
error.h
IO::NewMonos
Definition NewMonosIOHandler.cpp:31
IO::NewMonos::writeRing
void writeRing(const VarNames &names, FILE *out)
Definition NewMonosIOHandler.cpp:115
IO::NewMonos::readRingNoLeftParen
void readRingNoLeftParen(Scanner &in, VarNames &names)
Definition NewMonosIOHandler.cpp:124
IO::NewMonos::readIdealNoLeftParen
void readIdealNoLeftParen(Scanner &in, InputConsumer &consumer)
Definition NewMonosIOHandler.cpp:130
IO
Definition CoCoA4IOHandler.cpp:33
IO::writeTermProduct
void writeTermProduct(const Term &term, const TermTranslator &translator, FILE *out)
Definition IOHandlerImpl.cpp:170
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...