Frobby  0.9.5
IOHandler.h
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 #ifndef IO_HANDLER_GUARD
18 #define IO_HANDLER_GUARD
19 
20 #include <vector>
21 
22 class Term;
23 class Scanner;
24 class BigIdeal;
25 class VarNames;
26 class BigTermConsumer;
27 class DataType;
29 class SatBinomConsumer;
30 class InputConsumer;
31 
41 class IOHandler {
42  public:
43  virtual ~IOHandler();
44 
46  void readIdeal(Scanner& in, InputConsumer& consumer);
47 
49  void readIdeals(Scanner& in, InputConsumer& consumer);
50 
51  void readTerm
52  (Scanner& in, const VarNames& names, vector<mpz_class>& term);
53 
54  void readPolynomial(Scanner& in, CoefBigTermConsumer& consumer);
55 
56  void readSatBinomIdeal(Scanner& in, SatBinomConsumer& consumer);
57 
58  void writeTerm
59  (const vector<mpz_class>& term, const VarNames& names, FILE* out);
60 
61  bool hasMoreInput(Scanner& in) const;
62 
63  const char* getName() const;
64  const char* getDescription() const;
65 
66  auto_ptr<BigTermConsumer> createIdealWriter(FILE* out);
67  auto_ptr<BigTermConsumer> createIdealListWriter(FILE* out);
68  auto_ptr<CoefBigTermConsumer> createPolynomialWriter(FILE* out);
69 
70  bool supportsInput(const DataType& type) const;
71  bool supportsOutput(const DataType& type) const;
72 
73  protected:
74  virtual BigTermConsumer* doCreateIdealWriter(FILE* out) = 0;
76 
77  private:
78  virtual const char* doGetName() const = 0;
79  virtual const char* doGetDescription() const = 0;
80 
81  virtual void doReadIdeal(Scanner& in, InputConsumer& consumer) = 0;
82  virtual void doReadIdeals(Scanner& in, InputConsumer& consumer) = 0;
83  virtual void doReadTerm(Scanner& in, InputConsumer& consumer) = 0;
84  virtual void doReadPolynomial(Scanner& in, CoefBigTermConsumer& consumer) = 0;
85  virtual void doReadSatBinomIdeal(Scanner& in, SatBinomConsumer& consumer) = 0;
86  virtual void doWriteTerm(const vector<mpz_class>& term,
87  const VarNames& names,
88  FILE* out) = 0;
89  virtual bool doHasMoreInput(Scanner& in) const = 0;
90 
91  virtual bool doSupportsInput(const DataType& type) const = 0;
92  virtual bool doSupportsOutput(const DataType& type) const = 0;
93 };
94 
97 auto_ptr<IOHandler> createIOHandler(const string& prefix);
98 
102 auto_ptr<IOHandler> createOHandler(const string& input, const string& output);
103 
105 void getIOHandlerNames(vector<string>& names);
106 
107 void readFrobeniusInstance(Scanner& in, vector<mpz_class>& numbers);
108 
111 string autoDetectFormat(Scanner& in);
112 
117 
122 
123 #endif
void readFrobeniusInstance(Scanner &in, vector< mpz_class > &numbers)
Definition: IOHandler.cpp:160
void getIOHandlerNames(vector< string > &names)
Add the name of each fomat to names.
Definition: IOHandler.cpp:156
string getFormatNameIndicatingToUseInputFormatAsOutputFormat()
Using the returned string in place of an (output) format name indicates to use the input format as th...
Definition: IOHandler.cpp:230
string getFormatNameIndicatingToGuessTheInputFormat()
Using the returned string in place of an (input) format name indicates to guess the format based on w...
Definition: IOHandler.cpp:234
auto_ptr< IOHandler > createIOHandler(const string &prefix)
Returns an IOHandler for the format whose name has the given prefix.
Definition: IOHandler.cpp:145
auto_ptr< IOHandler > createOHandler(const string &input, const string &output)
Returns an IOHandler for the output format.
Definition: IOHandler.cpp:149
string autoDetectFormat(Scanner &in)
Return the format of what in is reading based on the first non-whitespace character.
Definition: IOHandler.cpp:198
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
An IOHandler implements input and output for some format in such a way that client code does not need...
Definition: IOHandler.h:41
virtual void doWriteTerm(const vector< mpz_class > &term, const VarNames &names, FILE *out)=0
virtual void doReadSatBinomIdeal(Scanner &in, SatBinomConsumer &consumer)=0
void readSatBinomIdeal(Scanner &in, SatBinomConsumer &consumer)
Definition: IOHandler.cpp:68
void readPolynomial(Scanner &in, CoefBigTermConsumer &consumer)
Definition: IOHandler.cpp:64
virtual bool doSupportsInput(const DataType &type) const =0
virtual void doReadIdeals(Scanner &in, InputConsumer &consumer)=0
void writeTerm(const vector< mpz_class > &term, const VarNames &names, FILE *out)
Definition: IOHandler.cpp:72
virtual const char * doGetDescription() const =0
virtual void doReadPolynomial(Scanner &in, CoefBigTermConsumer &consumer)=0
virtual CoefBigTermConsumer * doCreatePolynomialWriter(FILE *out)=0
void readIdeal(Scanner &in, InputConsumer &consumer)
Read an ideal and feed it to the consumer.
Definition: IOHandler.cpp:42
bool supportsInput(const DataType &type) const
Definition: IOHandler.cpp:119
auto_ptr< BigTermConsumer > createIdealWriter(FILE *out)
Definition: IOHandler.cpp:89
const char * getName() const
Definition: IOHandler.cpp:81
virtual const char * doGetName() const =0
auto_ptr< CoefBigTermConsumer > createPolynomialWriter(FILE *out)
Definition: IOHandler.cpp:110
virtual BigTermConsumer * doCreateIdealWriter(FILE *out)=0
virtual bool doSupportsOutput(const DataType &type) const =0
virtual void doReadIdeal(Scanner &in, InputConsumer &consumer)=0
auto_ptr< BigTermConsumer > createIdealListWriter(FILE *out)
Definition: IOHandler.cpp:98
const char * getDescription() const
Definition: IOHandler.cpp:85
virtual bool doHasMoreInput(Scanner &in) const =0
bool supportsOutput(const DataType &type) const
Definition: IOHandler.cpp:123
virtual void doReadTerm(Scanner &in, InputConsumer &consumer)=0
void readTerm(Scanner &in, const VarNames &names, vector< mpz_class > &term)
Definition: IOHandler.cpp:51
virtual ~IOHandler()
Definition: IOHandler.cpp:39
bool hasMoreInput(Scanner &in) const
Definition: IOHandler.cpp:77
void readIdeals(Scanner &in, InputConsumer &consumer)
Read a number of ideals and feed them to the consumer.
Definition: IOHandler.cpp:46
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
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