Frobby 0.9.6
IOParameters.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 "IOParameters.h"
19
20#include "IOFacade.h"
21#include "Macaulay2IOHandler.h"
22#include "Scanner.h"
23#include "error.h"
24#include "FrobbyStringStream.h"
25#include "DataType.h"
26
28 _inputType(input),
29 _outputType(output) {
30
31 string inputFormats;
32 string outputFormats;
33
34 string defaultOutput;
35 if (!_inputType.isNull())
37 else {
40 }
41
42 vector<string> names;
45 name != names.end(); ++name) {
47 ASSERT(handler.get() != 0);
48
49 if (handler->supportsInput(_inputType)) {
50 inputFormats += ' ';
51 inputFormats += handler->getName();
52 }
53 if (handler->supportsOutput(_outputType)) {
54 outputFormats += ' ';
55 outputFormats += handler->getName();
56 }
57 }
58
59 if (!_inputType.isNull()) {
60 string desc =
61 "The format used to read the input. "
62 "This action supports the formats:\n " + inputFormats + ".\n"
63 "The format \"" +
65 "\" instructs Frobby to guess the format.\n"
66 "Type 'frobby help io' for more information on input formats.";
67
68 _inputFormat.reset
70 ("iformat", desc.c_str(),
73 }
74
75 if (!output.isNull()) {
76 string desc =
77 "The format used to write the output. "
78 "This action supports the formats:\n " + outputFormats + ".\n";
79 if (!_inputType.isNull()) {
80 desc +=
81 "The format \"" +
83 + "\" instructs Frobby to use the input format.\n";
84 }
85 desc += "Type 'frobby help io' for more information on output formats.";
86
87 _outputFormat.reset
88 (new StringParameter("oformat", desc.c_str(), defaultOutput));
90 }
91}
92
95 ASSERT(_outputFormat.get() != 0);
96
98}
99
102
104}
105
106const string& IOParameters::getInputFormat() const {
108 ASSERT(_inputFormat.get() != 0);
109
110 return *_inputFormat;
111}
112
113const string& IOParameters::getOutputFormat() const {
115 ASSERT(_outputFormat.get() != 0);
116
117 if (!_inputType.isNull() &&
118 _outputFormat->getValue() ==
120 ASSERT(_inputFormat.get() != 0);
121 return *_inputFormat;
122 }
123
124 return *_outputFormat;
125}
126
132
138
151
153 IOFacade facade(false);
154
155 if (!_inputType.isNull()) {
157
158 if (!handler->supportsInput(_inputType)) {
160 errorMsg << "The "
161 << handler->getName()
162 << " format does not support input of "
164 << '.';
166 }
167 }
168
169 if (!_outputType.isNull()) {
171 /*
172 if (!handler->supportsOutput(_outputType)) {
173 FrobbyStringStream errorMsg;
174 errorMsg << "The "
175 << handler->getName()
176 << " format does not support output of "
177 << _outputType.getName()
178 << '.';
179 reportError(errorMsg);
180 }
181 */
182 }
183}
void getIOHandlerNames(vector< string > &names)
Add the name of each fomat to names.
string getFormatNameIndicatingToUseInputFormatAsOutputFormat()
Using the returned string in place of an (output) format name indicates to use the input format as th...
string getFormatNameIndicatingToGuessTheInputFormat()
Using the returned string in place of an (input) format name indicates to guess the format based on w...
unique_ptr< IOHandler > createIOHandler(const string &prefix)
Returns an IOHandler for the format whose name has the given prefix.
string autoDetectFormat(Scanner &in)
Return the format of what in is reading based on the first non-whitespace character.
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition DataType.h:29
const char * getName() const
Returns the name of the structure.
Definition DataType.cpp:24
bool isNull() const
Returns true if this object was returned by getNullType().
Definition DataType.cpp:28
A replacement for stringstream.
A facade for input and output of mathematical objects.
Definition IOFacade.h:39
void setOutputFormat(const string &format)
unique_ptr< StringParameter > _inputFormat
const string & getOutputFormat() const
void autoDetectInputFormat(Scanner &in)
If using the input format, this must be called before validating the ideals, since the auto detect fo...
unique_ptr< IOHandler > createInputHandler() const
IOParameters(const DataType &input, const DataType &output)
unique_ptr< StringParameter > _outputFormat
const string & getInputFormat() const
unique_ptr< IOHandler > createOutputHandler() const
void setInputFormat(const string &format)
const DataType & _inputType
const DataType & _outputType
void validateFormats() const
static const char * staticGetName()
void addParameter(Parameter *parameter)
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
void reportError(const string &errorMsg)
Definition error.cpp:23
#define ASSERT(X)
Definition stdinc.h:86