Frobby 0.9.5
Parameter.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 "Parameter.h"
19#include "error.h"
20#include "FrobbyStringStream.h"
21
23 const string& description):
24 _name(name),
25 _description(description) {
26}
27
30
31void Parameter::appendToDescription(const char* str) {
32 _description += str;
33}
34
42
44 unsigned int to,
45 const char** params,
46 unsigned int paramCount) {
47 if (from <= paramCount && paramCount <= to)
48 return;
49
51
52 errorMsg << "Option -" << getName() << " takes ";
53 if (from == to) {
54 if (from == 1)
55 errorMsg << "one parameter, ";
56 else
57 errorMsg << from << " parameters, ";
58 } else
59 errorMsg << "from " << from << " to " << to << " parameters, ";
60
61 if (paramCount == 0)
62 errorMsg << "but no parameters were provided.\n";
63 else {
64 if (paramCount == 1)
65 errorMsg << "but one parameter was provided.";
66 else
67 errorMsg << "but " << paramCount << " parameters were provided.";
68 errorMsg << '\n';
69
70 errorMsg << "The provided parameters were: ";
71 const char* prefix = "";
72 for (unsigned int i = 0; i < paramCount; ++i) {
73 errorMsg << prefix << params[i];
74 prefix = ", ";
75 }
76 errorMsg << ".\n";
77
78 if (paramCount > to)
79 errorMsg <<
80 "(Did you forget to put a - in front of one of the options?)\n";
81 }
82
83 errorMsg << "The option -"
84 << getName()
85 << " has the following description:\n "
86 << getDescription();
87
89}
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
A replacement for stringstream.
const string & getDescription() const
Definition Parameter.h:30
virtual void doProcessArguments(const char **args, size_t argCount)=0
virtual pair< size_t, size_t > doGetArgumentCountRange() const =0
string _description
Definition Parameter.h:50
void processArguments(const char **args, size_t argCount)
Definition Parameter.cpp:35
virtual ~Parameter()
Definition Parameter.cpp:28
const string & getName() const
Definition Parameter.h:29
void appendToDescription(const char *str)
Definition Parameter.cpp:31
Parameter(const string &name, const string &description)
Definition Parameter.cpp:22
void checkCorrectParameterCount(unsigned int from, unsigned int to, const char **params, unsigned int paramCount)
Definition Parameter.cpp:43
void reportError(const string &errorMsg)
Definition error.cpp:23
#define ASSERT(X)
Definition stdinc.h:86