Frobby 0.9.5
CanonicalTermConsumer.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"
19#include "TermTranslator.h"
20#include "IdealComparator.h"
21
22#include "Term.h"
23
25 size_t varCount,
27 _varCount(varCount),
28 _storingList(false),
29 _ideals(),
30 _idealsDeleter(_ideals),
31 _consumer(consumer),
32 _translator(translator) {
33 ASSERT(_consumer.get() != 0);
34}
35
39
46
53
55 ASSERT(term.getVarCount() == _varCount);
56 ASSERT(!_ideals.empty());
57
58 _ideals.back()->insert(term);
59}
60
62 if (!_storingList) {
63 ASSERT(_ideals.size() == 1);
65 ASSERT(_ideals.empty());
66 }
67}
68
71
73 for (vector<Ideal*>::iterator it = _ideals.begin(); it != end; ++it)
75
76 // We are sorting in reverse because we are processing the ideals from
77 // the back, so they get passed on in the correct order.
78 if (_translator == 0) {
80 sort(_ideals.rbegin(), _ideals.rend(), comparator);
81 } else {
83 sort(_ideals.rbegin(), _ideals.rend(), comparator);
84 }
85
86 _consumer->beginConsumingList();
87 while (!_ideals.empty())
89 _consumer->doneConsumingList();
90}
91
93 ASSERT(!_ideals.empty());
94 ASSERT(_ideals.back() != 0);
95
96 auto_ptr<Ideal> ideal(_ideals.back());
97 _ideals.pop_back();
98
99 canonicalizeIdeal(*ideal);
100
101 _consumer->beginConsuming();
103 Ideal::const_iterator end = ideal->end();
104 for (Ideal::const_iterator it = ideal->begin(); it != end; ++it) {
105 tmp = *it;
106 _consumer->consume(tmp);
107 }
108 ideal.reset(0);
109
110 _consumer->doneConsuming();
111}
112
114 if (_translator == 0)
115 ideal.sortReverseLex();
116 else {
118 sort(ideal.begin(), ideal.end(), comparator);
119 }
120}
void exceptionSafePushBack(Container &container, auto_ptr< Element > pointer)
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
void canonicalizeIdeal(Ideal &ideal)
virtual void consume(const Term &term)
Consume a term.
virtual void beginConsumingList()
This method is not required to be called.
virtual void doneConsuming()
Must be called once after each time beginConsuming has been called.
virtual void beginConsuming()
Tell the consumer to begin consuming an ideal.
CanonicalTermConsumer(auto_ptr< TermConsumer > consumer, size_t varCount, TermTranslator *translator=0)
The translator, if non-null, is used to identify exponents that map to zero, which influences the sor...
virtual void consumeRing(const VarNames &names)
Passes on the call immediately.
virtual void doneConsumingList()
Must be called once after each time beginConsumingList has been called.
auto_ptr< TermConsumer > _consumer
Represents a monomial ideal with int exponents.
Definition Ideal.h:27
Cont::const_iterator const_iterator
Definition Ideal.h:43
void sortReverseLex()
Definition Ideal.cpp:510
const_iterator end() const
Definition Ideal.h:49
const_iterator begin() const
Definition Ideal.h:48
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
size_t getVarCount() const
Definition Term.h:85
A predicate that sorts according to reverse lexicographic order on the translated values of a term.
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
#define ASSERT(X)
Definition stdinc.h:86