Frobby 0.9.5
IntegerParameter.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 "IntegerParameter.h"
19
20#include "error.h"
21#include "FrobbyStringStream.h"
22
24 const string& description,
25 unsigned int defaultValue):
26 Parameter(name, description),
27 _value(defaultValue) {
28}
29
31 return "INTEGER";
32}
33
36 str << getValue();
37 return str.str();
38}
39
40pair<size_t, size_t> IntegerParameter::doGetArgumentCountRange() const {
41 return make_pair(1, 1);
42}
43
44void IntegerParameter::doProcessArguments(const char** args, size_t argCount) {
45 ASSERT(argCount == 1);
46
47 bool ok = true;
48 mpz_class integer;
49 try {
50 FrobbyStringStream::parseInteger(integer, args[0]);
52 ok = false;
53 }
54
55 if (!ok || !integer.fits_uint_p()) {
56 FrobbyStringStream errorMsg;
57 errorMsg << "Option -"
58 << getName()
59 << " was given the parameter \""
60 << args[0]
61 << "\", which is not an integer in the range [0, 2^31-1].";
62 reportError(errorMsg);
63 }
64
65 _value = integer.get_ui();
66}
A replacement for stringstream.
static void parseInteger(mpz_class &integer, const string &str)
Throws NotAnIntegerException if str is not the string representation of an integer.
unsigned int _value
IntegerParameter(const string &name, const string &description, unsigned int defaultValue)
unsigned int getValue() const
virtual void doProcessArguments(const char **args, size_t argCount)
virtual string doGetValueAsString() const
virtual pair< size_t, size_t > doGetArgumentCountRange() const
virtual string doGetArgumentType() const
const string & getName() const
Definition Parameter.h:29
void reportError(const string &errorMsg)
Definition error.cpp:23
This header file includes common definitions and is included as the first line of code in every imple...
#define ASSERT(X)
Definition stdinc.h:86