Frobby  0.9.5
BoolParameter.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 "BoolParameter.h"
19 
20 #include "error.h"
21 #include "FrobbyStringStream.h"
22 
23 BoolParameter::BoolParameter(const string& name,
24  const string& description,
25  bool defaultValue):
26  Parameter(name, description),
27  _value(defaultValue) {
28 }
29 
31  return "[BOOL]";
32 }
33 
35  if (_value)
36  return "on";
37  else
38  return "off";
39 }
40 
41 pair<size_t, size_t> BoolParameter::doGetArgumentCountRange() const {
42  return make_pair(0, 1);
43 }
44 
45 void BoolParameter::doProcessArguments(const char** args, size_t argCount) {
46  if (argCount == 0) {
47  _value = true;
48  return;
49  }
50  ASSERT(argCount == 1);
51 
52  string arg(args[0]);
53  if (arg == "off")
54  _value = false;
55  else if (arg == "on")
56  _value = true;
57  else {
58  FrobbyStringStream errorMsg;
59  errorMsg << "Option -"
60  << getName()
61  << " was given the argument \""
62  << arg
63  << "\". The only valid arguments are \"on\" and \"off\".";
64  reportError(errorMsg);
65  }
66 }
BoolParameter(const string &name, const string &description, bool defaultValue)
virtual void doProcessArguments(const char **args, size_t argCount)
virtual string doGetArgumentType() const
virtual pair< size_t, size_t > doGetArgumentCountRange() const
virtual string doGetValueAsString() const
A replacement for stringstream.
const string & getName() const
Definition: Parameter.h:29
void reportError(const string &errorMsg)
Definition: error.cpp:23
#define ASSERT(X)
Definition: stdinc.h:86