Skip to content

Commit 41aad29

Browse files
committed
be more specific on errors of mismatch type in parameters and allow query string for file
1 parent eeaadb0 commit 41aad29

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

src/CoinParam.cpp

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ CoinParam::CoinParam()
6161
Constructor for double parameter
6262
*/
6363
CoinParam::CoinParam(std::string name, std::string help,
64-
double lower, double upper,
64+
double lower, double upper,
6565
std::string longHelp,
6666
CoinDisplayPriority displayPriority)
6767
: type_(paramDbl)
@@ -96,7 +96,7 @@ CoinParam::CoinParam(std::string name, std::string help,
9696
Constructor for integer parameter
9797
*/
9898
CoinParam::CoinParam(std::string name, std::string help,
99-
int lower, int upper,
99+
int lower, int upper,
100100
std::string longHelp,
101101
CoinDisplayPriority displayPriority)
102102
: type_(paramInt)
@@ -128,7 +128,7 @@ CoinParam::CoinParam(std::string name, std::string help,
128128
}
129129

130130
/*
131-
Constructor for any parameter taking a string (or no value).
131+
Constructor for any parameter taking a string (or no value).
132132
Type is not optional to resolve ambiguity.
133133
*/
134134
CoinParam::CoinParam(std::string name, CoinParamType type,
@@ -246,7 +246,7 @@ CoinParam::~CoinParam()
246246
Methods to manipulate a CoinParam object.
247247
*/
248248

249-
/* Methods to initialize a parameter that's already constructed */
249+
/* Methods to initialize a parameter that's already constructed */
250250

251251
/* Set up a double parameter */
252252
void CoinParam::setup(std::string name, std::string help,
@@ -290,7 +290,7 @@ void CoinParam::setup(std::string name, std::string help,
290290

291291
/*
292292
Process the parameter name.
293-
293+
294294
Process the name for efficient matching: determine if an `!' is present. If
295295
so, locate and record the position and remove the `!'.
296296
*/
@@ -626,10 +626,11 @@ int CoinParam::getVal(std::string &value) const
626626
<< std::endl;
627627
return 1;
628628
default:
629-
std::cout << "getVal(): argument type doesn't match parameter type!"
629+
std::cout << "getVal(): argument type of " <<
630+
this->name_ << " doesn't match parameter type!"
630631
<< std::endl;
631632
return 1;
632-
}
633+
}
633634
}
634635

635636
int CoinParam::getVal(double &value) const
@@ -643,7 +644,8 @@ int CoinParam::getVal(double &value) const
643644
<< std::endl;
644645
return 1;
645646
default:
646-
std::cout << "getVal(): argument type doesn't match parameter type!"
647+
std::cout << "getVal(): argument type of " <<
648+
this->name_ << " doesn't match parameter type!"
647649
<< std::endl;
648650
return 1;
649651
}
@@ -660,7 +662,8 @@ int CoinParam::getVal(int &value) const
660662
<< std::endl;
661663
return 1;
662664
default:
663-
std::cout << "getVal(): argument type doesn't match parameter type!"
665+
std::cout << "getVal(): argument type of " <<
666+
this->name_ << " doesn't match parameter type!"
664667
<< std::endl;
665668
return 1;
666669
}
@@ -672,7 +675,7 @@ int CoinParam::readValue(std::deque<std::string> &inputQueue,
672675
std::string *message)
673676
{
674677
std::string field = CoinParamUtils::getNextField(inputQueue);
675-
678+
676679
if (field == ""){
677680
if (type_ == paramAct){
678681
// An argument is not required in this case, so just return
@@ -731,9 +734,9 @@ int CoinParam::readValue(std::deque<std::string> &inputQueue,
731734
std::string home(environVar);
732735
value = value.erase(0, 1);
733736
value = home + value;
734-
}
737+
}
735738
}
736-
739+
737740
return 0;
738741
}
739742

@@ -794,7 +797,7 @@ int CoinParam::readValue(std::deque<std::string> &inputQueue,
794797
for (it = definedKwds_.begin(); it != definedKwds_.end(); it++) {
795798
std::string kwd = it->first;
796799
std::string::size_type shriekPos = kwd.find('!');
797-
if (shriekPos == std::string::npos)
800+
if (shriekPos == std::string::npos)
798801
shriekPos = kwd.find('#');
799802
kwd = kwd.substr(0, shriekPos);
800803
if (kwd==fieldThis) {
@@ -890,15 +893,15 @@ void CoinParam::appendKwd(std::string kwd)
890893
int CoinParam::kwdToMode(std::string input) const
891894
{
892895
assert(type_ == paramKwd);
893-
896+
894897
/* We need code to scan for !. With current code
895898
-direction max or -direction maximize does not work
896899
(only -direction max!imize works!)
897900
*/
898901
#if 0
899902

900903
std::map<std::string, int>::const_iterator it;
901-
904+
902905
it = definedKwds_.find(input);
903906

904907
if (it == definedKwds_.end()) {
@@ -916,7 +919,7 @@ int CoinParam::kwdToMode(std::string input) const
916919
input = input.substr(0, shriekPos) + input.substr(shriekPos + 1);
917920
}
918921
// This code scans through the list and allows for partial matches,
919-
922+
920923
int whichItem = -987654321;
921924
size_t numberItems = definedKwds_.size();
922925
if (numberItems > 0) {
@@ -1042,14 +1045,14 @@ int CoinParam::setModeVal(int newMode, std::string *message, ParamPushMode pMode
10421045
}
10431046
if (it == definedKwds_.end()){
10441047
if (message){
1045-
std::ostringstream buffer;
1048+
std::ostringstream buffer;
10461049
buffer << "Illegal keyword." << printKwds() << std::endl;
10471050
*message = buffer.str();
10481051
}
10491052
return 1;
10501053
}else{
10511054
if (message){
1052-
std::ostringstream buffer;
1055+
std::ostringstream buffer;
10531056
buffer << "Option for " << name_ << " changed from ";
10541057
buffer << currentKwd_ << " to " << newKwd << std::endl;
10551058
*message = buffer.str();
@@ -1077,22 +1080,22 @@ int CoinParam::setModeValDefault(int newMode, std::string *message)
10771080
}
10781081
if (it == definedKwds_.end()){
10791082
if (message){
1080-
std::ostringstream buffer;
1083+
std::ostringstream buffer;
10811084
buffer << "Illegal keyword." << printKwds() << std::endl;
10821085
*message = buffer.str();
10831086
}
10841087
return 1;
10851088
}else{
10861089
if (message){
1087-
std::ostringstream buffer;
1090+
std::ostringstream buffer;
10881091
buffer << "Default option for " << name_ << " set to " << newKwd
10891092
<< std::endl;
10901093
*message = buffer.str();
10911094
}
10921095

10931096
defaultKwd_ = currentKwd_ = newKwd;
10941097
defaultMode_ = currentMode_ = newMode;
1095-
1098+
10961099
return 0;
10971100
}
10981101
}
@@ -1105,7 +1108,7 @@ std::string CoinParam::kwdVal() const
11051108
assert(type_ == paramKwd);
11061109

11071110
std::string returnStr;
1108-
1111+
11091112
std::string::size_type shriekPos = currentKwd_.find('!');
11101113
if (shriekPos != std::string::npos) {
11111114
//contains '!'
@@ -1114,7 +1117,7 @@ std::string CoinParam::kwdVal() const
11141117
}else{
11151118
returnStr = currentKwd_;
11161119
}
1117-
1120+
11181121
return (returnStr);
11191122
}
11201123
// Return the string for an integer mode of keyword parameter
@@ -1225,7 +1228,7 @@ int CoinParam::setStrVal(std::string value, std::string *message,
12251228
assert(type_ == paramStr);
12261229

12271230
if (message){
1228-
std::ostringstream buffer;
1231+
std::ostringstream buffer;
12291232
buffer << name_ << " was changed from ";
12301233
buffer << strValue_ << " to " << value << std::endl;
12311234
*message = buffer.str();
@@ -1243,7 +1246,7 @@ int CoinParam::setStrVal(std::string value, std::string *message,
12431246
} else{
12441247
strValue_ = value;
12451248
}
1246-
1249+
12471250
if (pMode == pushOn){
12481251
pushFunc_(*this);
12491252
}
@@ -1255,20 +1258,20 @@ int CoinParam::setStrValDefault(std::string value, std::string *message)
12551258
assert(type_ == paramStr);
12561259

12571260
if (message){
1258-
std::ostringstream buffer;
1261+
std::ostringstream buffer;
12591262
buffer << "default value for " << name_ << " was set to " << value
12601263
<< std::endl;
12611264
*message = buffer.str();
12621265
}
1263-
1266+
12641267
strDefaultValue_ = strValue_ = value;
1265-
1268+
12661269
return 0;
12671270
}
12681271

12691272
std::string CoinParam::strVal() const
12701273
{
1271-
assert(type_ == paramStr);
1274+
assert(type_ == paramStr || type_ == paramFile);
12721275

12731276
return (strValue_);
12741277
}
@@ -1296,18 +1299,18 @@ int CoinParam::setDirName(std::string value, std::string *message,
12961299
std::string home(environVar);
12971300
dir = dir.erase(0, 1);
12981301
dir = home + dir;
1299-
}
1302+
}
13001303
}
13011304

13021305
if (message){
1303-
std::ostringstream buffer;
1306+
std::ostringstream buffer;
13041307
buffer << "directory parameter " << name_ << " was changed from ";
13051308
buffer << strValue_ << " to " << dir << std::endl;
13061309
*message = buffer.str();
13071310
}
13081311

13091312
strValue_ = dir;
1310-
1313+
13111314
if (pMode == pushOn){
13121315
pushFunc_(*this);
13131316
}
@@ -1332,18 +1335,18 @@ int CoinParam::setDirNameDefault(std::string value, std::string *message)
13321335
std::string home(environVar);
13331336
dir = dir.erase(0, 1);
13341337
dir = home + dir;
1335-
}
1338+
}
13361339
}
13371340

13381341
if (message){
1339-
std::ostringstream buffer;
1342+
std::ostringstream buffer;
13401343
buffer << "default value for directory parameter " << name_
13411344
<< " was set to " << dir << std::endl;
13421345
*message = buffer.str();
13431346
}
13441347

13451348
strDefaultValue_ = strValue_ = dir;
1346-
1349+
13471350
return 0;
13481351
}
13491352

@@ -1378,14 +1381,14 @@ int CoinParam::setFileName(std::string value, std::string *message,
13781381
}
13791382

13801383
if (message){
1381-
std::ostringstream buffer;
1384+
std::ostringstream buffer;
13821385
buffer << "file parameter " << name_ << " was changed from ";
13831386
buffer << strValue_ << " to " << fileName << std::endl;
13841387
*message = buffer.str();
13851388
}
13861389

13871390
strValue_ = fileName;
1388-
1391+
13891392
if (pMode == pushOn){
13901393
pushFunc_(*this);
13911394
}
@@ -1411,7 +1414,7 @@ int CoinParam::setFileNameDefault(std::string value, std::string *message)
14111414
}
14121415

14131416
if (message){
1414-
std::ostringstream buffer;
1417+
std::ostringstream buffer;
14151418
buffer << "default value for file parameter "<< name_ << " was set to ";
14161419
buffer << strValue_;
14171420
*message = buffer.str();
@@ -1480,7 +1483,7 @@ int CoinParam::setDblValDefault(double value, std::string *message)
14801483
buffer << name_ << " default was set to " << value << std::endl;
14811484
*message = buffer.str();
14821485
}
1483-
1486+
14841487
dblDefaultValue_ = dblValue_ = value;
14851488

14861489
return 0;

0 commit comments

Comments
 (0)