Frobby  0.9.5
LatticeFormatAction.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 "LatticeFormatAction.h"
19 
20 #include "BigIdeal.h"
21 #include "IOFacade.h"
22 #include "fplllIO.h"
23 #include "LatticeFacade.h"
24 #include "Scanner.h"
25 #include "error.h"
26 #include "IOHandler.h"
27 
29 Action
30 (staticGetName(),
31  "Change the representation of the input lattice.",
32  "By default, latformat simply writes the input lattice to output.\n"
33  "The main functionality is to change the format.",
34  false),
35 
36 _inputFormat
37  ("iformat",
38  "The input format. The available formats are 4ti2 and fplll.",
39  "4ti2"),
40 
41  _outputFormat
42  ("oformat",
43  "The output format. The additional format \"" +
45  "\" means use input format.",
47 
48  _zero
49  ("zero",
50  "Adjust lattice basis to increase the number of zero entries.",
51  false) {
52 }
53 
54 void LatticeFormatAction::obtainParameters(vector<Parameter*>& parameters) {
55  Action::obtainParameters(parameters);
56  parameters.push_back(&_inputFormat);
57  parameters.push_back(&_outputFormat);
58  parameters.push_back(&_zero);
59 }
60 
62  string iformat = _inputFormat.getValue();
63  string oformat = _outputFormat.getValue();
64 
66  oformat = iformat;
67 
68  IOFacade facade(_printActions);
69 
70  if (!facade.isValidLatticeFormat(iformat))
71  reportError("Unknown lattice input format \"" + iformat + "\".");
72  if (!facade.isValidLatticeFormat(oformat))
73  reportError("Unknown lattice output format \"" + oformat + "\".");
74 
75  BigIdeal basis;
76  Scanner in(iformat, stdin);
77  facade.readLattice(in, basis);
78  in.expectEOF();
79 
80  if (_zero) {
81  LatticeFacade latticeFacade(_printActions);
82  latticeFacade.makeZeroesInLatticeBasis(basis);
83  }
84 
85  facade.writeLattice(stdout, basis, oformat);
86 }
87 
89  return "latformat";
90 }
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
Definition: Action.h:25
BoolParameter _printActions
Definition: Action.h:68
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
A facade for input and output of mathematical objects.
Definition: IOFacade.h:39
bool isValidLatticeFormat(const string &format)
Definition: IOFacade.cpp:318
void readLattice(Scanner &in, BigIdeal &ideal)
Definition: IOFacade.cpp:329
void writeLattice(FILE *out, const BigIdeal &ideal, const string &format)
Definition: IOFacade.cpp:344
A facade for operations on lattices.
Definition: LatticeFacade.h:27
void makeZeroesInLatticeBasis(BigIdeal &basis)
static const char * staticGetName()
StringParameter _outputFormat
StringParameter _inputFormat
virtual void obtainParameters(vector< Parameter * > &parameters)
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
const string & getValue() const
void reportError(const string &errorMsg)
Definition: error.cpp:23