Frobby  0.9.5
PolyTransformAction.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 "PolyTransformAction.h"
19 
20 #include "Scanner.h"
21 #include "IOFacade.h"
22 #include "BigPolynomial.h"
23 #include "PolynomialFacade.h"
24 #include "DataType.h"
25 
27  Action
28 (staticGetName(),
29  "Change the representation of the input polynomial.",
30  "By default, transform simply writes the input polynomial to output. A\n"
31  "number of parameters allow one to transform the input polynomial in various\n"
32  "ways.",
33  false),
34 
35  _io(DataType::getPolynomialType(), DataType::getPolynomialType()),
36 
37  _canonicalize
38  ("canon",
39  "Sort variables and generators to get a canonical representation.",
40  false),
41 
42  _sortTerms
43  ("sort",
44  "Sort the terms.",
45  false) {
46 }
47 
48 void PolyTransformAction::obtainParameters(vector<Parameter*>& parameters) {
49  Action::obtainParameters(parameters);
50  _io.obtainParameters(parameters);
51  parameters.push_back(&_canonicalize);
52  parameters.push_back(&_sortTerms);
53 }
54 
56  Scanner in(_io.getInputFormat(), stdin);
59 
60  IOFacade facade(_printActions);
61 
62  BigPolynomial polynomial;
63  facade.readPolynomial(in, polynomial);
64  in.expectEOF();
65 
66  PolynomialFacade polyFacade(_printActions);
67  if (_canonicalize)
68  polyFacade.sortVariables(polynomial);
70  polyFacade.sortTerms(polynomial);
71 
72  auto_ptr<IOHandler> output = _io.createOutputHandler();
73  facade.writePolynomial(polynomial, output.get(), stdout);
74 }
75 
77  return "ptransform";
78 }
Definition: Action.h:25
BoolParameter _printActions
Definition: Action.h:68
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
void writePolynomial(const BigPolynomial &polynomial, IOHandler *handler, FILE *out)
Definition: IOFacade.cpp:205
void readPolynomial(Scanner &in, BigPolynomial &polynomial)
Definition: IOFacade.cpp:192
void autoDetectInputFormat(Scanner &in)
If using the input format, this must be called before validating the ideals, since the auto detect fo...
auto_ptr< IOHandler > createOutputHandler() const
const string & getInputFormat() const
void validateFormats() const
void obtainParameters(vector< Parameter * > &parameters)
virtual void obtainParameters(vector< Parameter * > &parameters)
static const char * staticGetName()
BoolParameter _canonicalize
A facade for operations on polynomials.
void sortVariables(BigPolynomial &poly)
Sort the variables of poly.
void sortTerms(BigPolynomial &poly)
Sort the terms of poly.
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
void expectEOF()
Require that there is no more input.
Definition: Scanner.cpp:77