Frobby 0.9.5
NewMonosIOHandler.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
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#include "stdinc.h"
18#include "NewMonosIOHandler.h"
19
20#include "Scanner.h"
21#include "VarNames.h"
22#include "BigTermConsumer.h"
23#include "DataType.h"
24#include "IdealWriter.h"
25#include "error.h"
26#include "InputConsumer.h"
27
28#include <cstdio>
29
30namespace IO {
36 namespace N = NewMonos;
37
39 public:
42
43 private:
44 virtual void doWriteHeader(bool first) {
45 fputs("(monomial-ideal-with-order\n ", getFile());
47 }
48
49 virtual void doWriteTerm(const Term& term,
51 bool first) {
52 fputs("\n ", getFile());
54 }
55
56 virtual void doWriteTerm(const vector<mpz_class>& term,
57 bool first) {
58 fputs("\n ", getFile());
60 }
61
62 virtual void doWriteFooter(bool wasZeroIdeal) {
63 fputs("\n)\n", getFile());
64 }
65
66 virtual void doWriteEmptyList() {
68 }
69 };
70
77
79 return "newmonos";
80 }
81
85
86 void NewMonosIOHandler::doWriteTerm(const vector<mpz_class>& term,
87 const VarNames& names,
88 FILE* out) {
90 }
91
93 consumer.consumeTermProductNotation(in);
94 }
95
100
102 in.expect('(');
103 if (in.peek('l') || in.peek('L')) {
106 consumer.consumeRing(names);
107 return;
108 }
109
110 do {
112 } while (in.match('('));
113 }
114
115 void N::writeRing(const VarNames& names, FILE* out) {
116 fputs("(lex-order", out);
117 for (unsigned int i = 0; i < names.getVarCount(); ++i) {
118 putc(' ', out);
119 fputs(names.getName(i).c_str(), out);
120 }
121 fputc(')', out);
122 }
123
125 in.expect("lex-order");
126 while (!in.match(')'))
127 names.addVarSyntaxCheckUnique(in, in.readIdentifier());
128 }
129
131 in.expect("monomial-ideal-with-order");
132
134 in.expect('(');
136 consumer.consumeRing(names);
137
138 consumer.beginIdeal();
139 while (!in.match(')'))
140 consumer.consumeTermProductNotation(in);
141 consumer.endIdeal();
142 }
143}
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
static const DataType & getMonomialIdealListType()
Returns the one and only instance for monomial ideal lists.
Definition DataType.cpp:54
static const DataType & getMonomialIdealType()
Returns the one and only instance for monomial ideals.
Definition DataType.cpp:45
This class contains a minimum level of functionality that makes it more convenient to derive from tha...
void registerInput(const DataType &type)
Specify that input of the argument type is supported.
void registerOutput(const DataType &type)
Specify that output of the argument type is supported.
FILE * getFile()
Definition IdealWriter.h:43
const VarNames & getNames()
Definition IdealWriter.h:44
virtual void doReadTerm(Scanner &in, InputConsumer &consumer)
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)
void doReadIdeal(Scanner &in, InputConsumer &consumer)
virtual void doWriteTerm(const vector< mpz_class > &term, const VarNames &names, FILE *out)
static const char * staticGetName()
void doReadIdeals(Scanner &in, InputConsumer &consumer)
virtual void doWriteTerm(const Term &term, const TermTranslator &translator, bool first)
virtual void doWriteTerm(const vector< mpz_class > &term, bool first)
virtual void doWriteHeader(bool first)
virtual void doWriteFooter(bool wasZeroIdeal)
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
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
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
void writeRing(const VarNames &names, FILE *out)
void readRingNoLeftParen(Scanner &in, VarNames &names)
void readIdealNoLeftParen(Scanner &in, InputConsumer &consumer)
void writeTermProduct(const Term &term, const TermTranslator &translator, FILE *out)