Frobby  0.9.5
InputConsumer.h
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2011 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 #ifndef INPUT_CONSUMER_GUARD
18 #define INPUT_CONSUMER_GUARD
19 
20 #include "BigIdeal.h"
21 #include "SquareFreeIdeal.h"
22 #include "VarNames.h"
23 #include "ElementDeleter.h"
24 #include <vector>
25 #include <list>
26 #include <string>
27 
28 class Scanner;
29 
31  public:
32  InputConsumer();
33 
34  void consumeRing(const VarNames& names);
35 
36  void requireSquareFree();
37 
39  void beginIdeal();
40 
44  void hintGenCount(size_t hintGenCount);
45 
47  void beginTerm();
48 
50  size_t consumeVar(Scanner& in);
51 
54  size_t consumeVarNumber(Scanner& in);
55 
57  void consumeVarExponentOne(size_t var, const Scanner& in);
58 
62  void consumeVarExponent(size_t var, Scanner& in);
63 
65  void endTerm();
66 
69 
71  void endIdeal();
72 
74  bool empty() const {return _ideals.empty();}
75 
80  void releaseIdeal(auto_ptr<SquareFreeIdeal>& sqf, auto_ptr<BigIdeal>& big);
81 
84  auto_ptr<BigIdeal> releaseBigIdeal();
85 
88  auto_ptr<SquareFreeIdeal> releaseSquareFreeIdeal();
89 
91  const VarNames& getRing() const {return _names;}
92 
93  private:
94  struct Entry {
95  auto_ptr<BigIdeal> _big;
96  auto_ptr<SquareFreeIdeal> _sqf;
97  };
98  void releaseIdeal(Entry& e);
99 
100  void errorVariableAppearsTwice(const Scanner& in, size_t var);
101  void idealNotSquareFree();
102  static void toBigIdeal
103  (auto_ptr<SquareFreeIdeal>& sqf, auto_ptr<BigIdeal>& big);
104 
105  string _tmpString;
107  auto_ptr<BigIdeal> _bigIdeal;
108  auto_ptr<SquareFreeIdeal> _sqfIdeal;
109  vector<string> _term;
110 
111  std::list<Entry*> _ideals;
113  bool _inIdeal;
115 };
116 
117 #endif
void requireSquareFree()
void errorVariableAppearsTwice(const Scanner &in, size_t var)
auto_ptr< SquareFreeIdeal > releaseSquareFreeIdeal()
Returns the least recently read ideal that has not been released.
bool empty() const
Returns true if there are ideals stored.
Definition: InputConsumer.h:74
size_t consumeVarNumber(Scanner &in)
Reads variable as a number so that the first variable is 1.
void idealNotSquareFree()
void releaseIdeal(auto_ptr< SquareFreeIdeal > &sqf, auto_ptr< BigIdeal > &big)
Struct that keeps either a BigIdeal or a SquareFreeIdeal.
void beginTerm()
Start consuming a term.
void beginIdeal()
Start consuming an ideal.
const VarNames & getRing() const
Returns the current ring.
Definition: InputConsumer.h:91
bool _requireSquareFree
VarNames _names
size_t consumeVar(Scanner &in)
Reads variable and returns id.
std::list< Entry * > _ideals
void consumeTermProductNotation(Scanner &in)
Reads a term in a format like "a^4*b*c^2".
static void toBigIdeal(auto_ptr< SquareFreeIdeal > &sqf, auto_ptr< BigIdeal > &big)
void consumeRing(const VarNames &names)
void consumeVarExponent(size_t var, Scanner &in)
Consumes var raised to an exponent read from in.
void hintGenCount(size_t hintGenCount)
Suggest that the current ideal will have the given number of generators.
auto_ptr< BigIdeal > releaseBigIdeal()
Returns the least recently read ideal that has not been released.
auto_ptr< SquareFreeIdeal > _sqfIdeal
void consumeVarExponentOne(size_t var, const Scanner &in)
Consumes var raised to the exponent 1.
ElementDeleter< std::list< Entry * > > _idealsDeleter
auto_ptr< BigIdeal > _bigIdeal
void endIdeal()
Done reading an ideal.
vector< string > _term
void endTerm()
Done reading a term.
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40
auto_ptr< SquareFreeIdeal > _sqf
Definition: InputConsumer.h:96
auto_ptr< BigIdeal > _big
Definition: InputConsumer.h:95