Frobby 0.9.5
CountingIOHandler.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 "CountingIOHandler.h"
19
20#include "BigTermConsumer.h"
21#include "CoefBigTermConsumer.h"
22#include "DataType.h"
23#include "BigIdeal.h"
24#include "BigPolynomial.h"
25
26namespace IO {
27 namespace {
30 class CountingConsumer :
32 public:
33 CountingConsumer(FILE* out):
34 _termCount(0),
35 _out(out) {
36 }
37
43 virtual ~CountingConsumer() {
44 // Destructors must not throw exceptions. As far as I know,
45 // bad_alloc is the only thing that could be thrown from
46 // gmp_fprintf.
47 }
48
49 virtual void consumeRing(const VarNames& names) {
50 }
51
52 virtual void beginConsuming() {
53 _termCount = 0;
54 }
55
56 virtual void consume(const Term& term, const TermTranslator& translator) {
57 ++_termCount;
58 }
59
60 virtual void consume(const vector<mpz_class>& term) {
61 ++_termCount;
62 }
63
64 virtual void consume(const BigIdeal& ideal) {
65 beginConsuming();
66 _termCount += ideal.getGeneratorCount();
67 doneConsuming();
68 }
69
70 virtual void consume(const mpz_class& coef, const Term& term) {
71 ++_termCount;
72 }
73
74 virtual void consume(const mpz_class& coef,
75 const Term& term,
77 ++_termCount;
78 }
79
80 virtual void consume(const mpz_class& coef,
81 const vector<mpz_class>& term) {
82 ++_termCount;
83 }
84
85 virtual void consume(const BigPolynomial& poly) {
86 beginConsuming();
87 _termCount += poly.getTermCount();
88 doneConsuming();
89 }
90
91 virtual void doneConsuming() {
92 gmp_fprintf(_out, "%Zd\n", _termCount.get_mpz_t());
93 }
94
95 private:
96 mpz_class _termCount;
97 FILE* _out;
98 };
99 }
100
107
109 return "count";
110 }
111
113 return new CountingConsumer(out);
114 }
115
117 return new CountingConsumer(out);
118 }
119
120 void CountingIOHandler::doWriteTerm(const vector<mpz_class>& term,
121 const VarNames& names,
122 FILE* out) {
123 fputc('1', out);
124 }
125}
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
size_t getGeneratorCount() const
Definition BigIdeal.h:144
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
static const DataType & getPolynomialType()
Returns the one and only instance for polynomials.
Definition DataType.cpp:50
virtual CoefBigTermConsumer * doCreatePolynomialWriter(FILE *out)
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)
static const char * staticGetName()
virtual void doWriteTerm(const vector< mpz_class > &term, const VarNames &names, FILE *out)
This class contains a minimum level of functionality that makes it more convenient to derive from tha...
void registerOutput(const DataType &type)
Specify that output of the argument type is supported.
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