Sandia Home Sandia Home
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

APPSPACK_Parameter_List.cpp

Go to the documentation of this file.
00001 // $Id: APPSPACK_Parameter_List.cpp,v 1.12.2.1 2005/06/29 17:07:42 tgkolda Exp $ 00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/src/APPSPACK_Parameter_List.cpp,v $ 00003 00004 //@HEADER 00005 // ************************************************************************ 00006 // 00007 // APPSPACK: Asynchronous Parallel Pattern Search 00008 // Copyright (2003) Sandia Corporation 00009 // 00010 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00011 // license for use of this work by or on behalf of the U.S. Government. 00012 // 00013 // This library is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU Lesser General Public License as 00015 // published by the Free Software Foundation; either version 2.1 of the 00016 // License, or (at your option) any later version. 00017 // 00018 // This library is distributed in the hope that it will be useful, but 00019 // WITHOUT ANY WARRANTY; without even the implied warranty of 00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 // Lesser General Public License for more details. 00022 // 00023 // You should have received a copy of the GNU Lesser General Public 00024 // License along with this library; if not, write to the Free Software 00025 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00026 // USA. . 00027 // 00028 // Questions? Contact Tammy Kolda (tgkolda@sandia.gov) 00029 // 00030 // ************************************************************************ 00031 //@HEADER 00032 00038 #include "APPSPACK_Parameter_List.hpp" 00039 00040 APPSPACK::Parameter::List::List() {} 00041 00042 APPSPACK::Parameter::List::List(const List& source) 00043 { 00044 params = source.params; 00045 } 00046 00047 APPSPACK::Parameter::List& APPSPACK::Parameter::List::operator=(const List& source) 00048 { 00049 if (&source == this) 00050 return *this; 00051 00052 params = source.params; 00053 return *this; 00054 } 00055 00056 APPSPACK::Parameter::List::~List() 00057 { 00058 } 00059 00060 void APPSPACK::Parameter::List::setParameter(const string& name, bool value) 00061 { 00062 params[name].setValue(value); 00063 } 00064 00065 void APPSPACK::Parameter::List::setParameter(const string& name, int value) 00066 { 00067 params[name].setValue(value); 00068 } 00069 00070 void APPSPACK::Parameter::List::setParameter(const string& name, double value) 00071 { 00072 params[name].setValue(value); 00073 } 00074 00075 void APPSPACK::Parameter::List::setParameter(const string& name, const char* value) 00076 { 00077 params[name].setValue(value); 00078 } 00079 00080 void APPSPACK::Parameter::List::setParameter(const string& name, const string& value) 00081 { 00082 params[name].setValue(value); 00083 } 00084 00085 void APPSPACK::Parameter::List::setParameter(const string& name, const Value& value) 00086 { 00087 params[name].setValue(value); 00088 } 00089 00090 void APPSPACK::Parameter::List::setParameter(const string& name, const Vector& value) 00091 { 00092 params[name].setValue(value); 00093 } 00094 00095 00096 bool APPSPACK::Parameter::List::getParameter(const string& name, bool nominal) 00097 { 00098 ConstIterator i = params.find(name); 00099 00100 if (i == params.end()) { 00101 params[name].setValue(nominal, true); 00102 i = params.find(name); 00103 } 00104 00105 if ((i != params.end()) && (entry(i).isBool())) 00106 return entry(i).getBoolValue(); 00107 00108 cerr << "APPSPACK::Parameter::List::getParameter - get error for bool" << endl; 00109 throw "APPSPACK Error"; 00110 } 00111 00112 int APPSPACK::Parameter::List::getParameter(const string& name, int nominal) 00113 { 00114 ConstIterator i = params.find(name); 00115 00116 if (i == params.end()) { 00117 params[name].setValue(nominal, true); 00118 i = params.find(name); 00119 } 00120 00121 if ((i != params.end()) && (entry(i).isInt())) 00122 return entry(i).getIntValue(); 00123 00124 cerr << "APPSPACK::Parameter::List::getParameter - get error for int" << endl; 00125 throw "APPSPACK Error"; 00126 } 00127 00128 double APPSPACK::Parameter::List::getParameter(const string& name, double nominal) 00129 { 00130 ConstIterator i = params.find(name); 00131 00132 if (i == params.end()) { 00133 params[name].setValue(nominal, true); 00134 i = params.find(name); 00135 } 00136 00137 if ((i != params.end()) && (entry(i).isDouble())) 00138 return entry(i).getDoubleValue(); 00139 00140 cerr << "APPSPACK::Parameter::List::getParameter - get error for double" << endl; 00141 throw "APPSPACK Error"; 00142 00143 } 00144 00145 const string& APPSPACK::Parameter::List::getParameter(const string& name, const char* nominal) 00146 { 00147 ConstIterator i = params.find(name); 00148 00149 if (i == params.end()) { 00150 params[name].setValue(nominal, true); 00151 i = params.find(name); 00152 } 00153 00154 if ((i != params.end()) && (entry(i).isString())) 00155 return entry(i).getStringValue(); 00156 00157 cerr << "APPSPACK::Parameter::List::getParameter - get error for string" << endl; 00158 throw "APPSPACK Error"; 00159 } 00160 00161 const string& APPSPACK::Parameter::List::getParameter(const string& name, const string& nominal) 00162 { 00163 ConstIterator i = params.find(name); 00164 00165 if (i == params.end()) { 00166 params[name].setValue(nominal, true); 00167 i = params.find(name); 00168 } 00169 00170 if ((i != params.end()) && (entry(i).isString())) 00171 return entry(i).getStringValue(); 00172 00173 cerr << "APPSPACK::Parameter::List::getParameter - get error for string" << endl; 00174 throw "APPSPACK Error"; 00175 } 00176 00177 const APPSPACK::Value& APPSPACK::Parameter::List::getParameter(const string& name, const Value& nominal) 00178 { 00179 ConstIterator i = params.find(name); 00180 00181 if (i == params.end()) 00182 { 00183 params[name].setValue(nominal, true); 00184 i = params.find(name); 00185 } 00186 00187 if ((i != params.end()) && (entry(i).isValue())) 00188 return entry(i).getValueValue(); 00189 00190 cerr << "APPSPACK::Parameter::List::getParameter - get error for Value" << endl; 00191 throw "APPSPACK Error"; 00192 } 00193 00194 const APPSPACK::Vector& APPSPACK::Parameter::List::getParameter(const string& name, const Vector& nominal) 00195 { 00196 ConstIterator i = params.find(name); 00197 00198 if (i == params.end()) 00199 { 00200 params[name].setValue(nominal, true); 00201 i = params.find(name); 00202 } 00203 00204 if ((i != params.end()) && (entry(i).isVector())) 00205 return entry(i).getVectorValue(); 00206 00207 cerr << "APPSPACK::Parameter::List::getParameter - get error for Vector" << endl; 00208 throw "APPSPACK Error"; 00209 } 00210 00211 bool APPSPACK::Parameter::List::getParameter(const string& name, bool nominal) const 00212 { 00213 ConstIterator i = params.find(name); 00214 if ((i != params.end()) && (entry(i).isBool())) 00215 return entry(i).getBoolValue(); 00216 return nominal; 00217 } 00218 00219 int APPSPACK::Parameter::List::getParameter(const string& name, int nominal) const 00220 { 00221 ConstIterator i = params.find(name); 00222 if ((i != params.end()) && (entry(i).isInt())) 00223 return entry(i).getIntValue(); 00224 return nominal; 00225 } 00226 00227 double APPSPACK::Parameter::List::getParameter(const string& name, double nominal) const 00228 { 00229 ConstIterator i = params.find(name); 00230 if ((i != params.end()) && (entry(i).isDouble())) 00231 return entry(i).getDoubleValue(); 00232 return nominal; 00233 } 00234 00235 const string& APPSPACK::Parameter::List::getParameter(const string& name, const char* nominal) const 00236 { 00237 ConstIterator i = params.find(name); 00238 if ((i != params.end()) && (entry(i).isString())) 00239 return entry(i).getStringValue(); 00240 00241 // Save nominal char* value as a string, and return the string value. 00242 tmpstrings.push_back(nominal); 00243 return tmpstrings.back(); 00244 } 00245 00246 const string& APPSPACK::Parameter::List::getParameter(const string& name, const string& nominal) const 00247 { 00248 ConstIterator i = params.find(name); 00249 if ((i != params.end()) && (entry(i).isString())) 00250 return entry(i).getStringValue(); 00251 return nominal; 00252 } 00253 00254 const APPSPACK::Value& APPSPACK::Parameter::List::getParameter(const string& name, const Value& nominal) const 00255 { 00256 ConstIterator i = params.find(name); 00257 if ((i != params.end()) && (entry(i).isValue())) 00258 return entry(i).getValueValue(); 00259 return nominal; 00260 } 00261 00262 const APPSPACK::Vector& APPSPACK::Parameter::List::getParameter(const string& name, const Vector& nominal) const 00263 { 00264 ConstIterator i = params.find(name); 00265 if ((i != params.end()) && (entry(i).isVector())) 00266 return entry(i).getVectorValue(); 00267 return nominal; 00268 } 00269 00270 00271 double APPSPACK::Parameter::List::getDoubleParameter(const string& name) const 00272 { 00273 ConstIterator i = params.find(name); 00274 00275 if ((i != params.end()) && (entry(i).isDouble())) 00276 return entry(i).getDoubleValue(); 00277 00278 cerr << "APPSPACK::Parameter::List::getValueParameter - no such parameter (" << name << ")"<< endl; 00279 throw "APPSPACK Error"; 00280 } 00281 00282 const APPSPACK::Value& APPSPACK::Parameter::List::getValueParameter(const string& name) const 00283 { 00284 ConstIterator i = params.find(name); 00285 00286 if ((i != params.end()) && (entry(i).isValue())) 00287 return entry(i).getValueValue(); 00288 00289 cerr << "APPSPACK::Parameter::List::getValueParameter - no such parameter (" << name << ")"<< endl; 00290 throw "APPSPACK Error"; 00291 } 00292 00293 const APPSPACK::Vector& APPSPACK::Parameter::List::getVectorParameter(const string& name) const 00294 { 00295 ConstIterator i = params.find(name); 00296 00297 if ((i != params.end()) && (entry(i).isVector())) 00298 return entry(i).getVectorValue(); 00299 00300 cerr << "APPSPACK::Parameter::List::getVectorParameter - no such parameter (" << name << ")" << endl; 00301 throw "APPSPACK Error"; 00302 } 00303 00304 bool APPSPACK::Parameter::List::isParameterBool(const string& name) const 00305 { 00306 ConstIterator i = params.find(name); 00307 00308 if (i != params.end()) 00309 return (entry(i).isBool()); 00310 00311 return false; 00312 } 00313 00314 bool APPSPACK::Parameter::List::isParameterInt(const string& name) const 00315 { 00316 ConstIterator i = params.find(name); 00317 00318 if (i != params.end()) 00319 return (entry(i).isInt()); 00320 00321 return false; 00322 } 00323 00324 bool APPSPACK::Parameter::List::isParameterDouble(const string& name) const 00325 { 00326 ConstIterator i = params.find(name); 00327 00328 if (i != params.end()) 00329 return (entry(i).isDouble()); 00330 00331 return false; 00332 } 00333 00334 bool APPSPACK::Parameter::List::isParameterString(const string& name) const 00335 { 00336 ConstIterator i = params.find(name); 00337 00338 if (i != params.end()) 00339 return (entry(i).isString()); 00340 00341 return false; 00342 } 00343 00344 bool APPSPACK::Parameter::List::isParameterSublist(const string& name) const 00345 { 00346 ConstIterator i = params.find(name); 00347 00348 if (i != params.end()) 00349 return (entry(i).isList()); 00350 00351 return false; 00352 } 00353 00354 bool APPSPACK::Parameter::List::isParameterValue(const string& name) const 00355 { 00356 ConstIterator i = params.find(name); 00357 00358 if (i != params.end()) 00359 return (entry(i).isValue()); 00360 00361 return false; 00362 } 00363 00364 bool APPSPACK::Parameter::List::isParameterVector(const string& name) const 00365 { 00366 ConstIterator i = params.find(name); 00367 00368 if (i != params.end()) 00369 return (entry(i).isVector()); 00370 00371 return false; 00372 } 00373 00374 bool APPSPACK::Parameter::List::isParameter(const string& name) const 00375 { 00376 return (params.find(name) != params.end()); 00377 } 00378 00379 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, bool value) const 00380 { 00381 ConstIterator i = params.find(name); 00382 if ((i != params.end()) && (entry(i).isBool())) 00383 return (entry(i).getBoolValue() == value); 00384 return false; 00385 } 00386 00387 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, int value) const 00388 { 00389 ConstIterator i = params.find(name); 00390 if ((i != params.end()) && (entry(i).isInt())) 00391 return (entry(i).getIntValue() == value); 00392 return false; 00393 } 00394 00395 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, double value) const 00396 { 00397 ConstIterator i = params.find(name); 00398 if ((i != params.end()) && (entry(i).isDouble())) 00399 return (entry(i).getDoubleValue() == value); 00400 return false; 00401 } 00402 00403 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, const char* value) const 00404 { 00405 ConstIterator i = params.find(name); 00406 if ((i != params.end()) && (entry(i).isString())) 00407 return (entry(i).getStringValue() == value); 00408 return false; 00409 } 00410 00411 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, const string& value) const 00412 { 00413 ConstIterator i = params.find(name); 00414 if ((i != params.end()) && (entry(i).isString())) 00415 return (entry(i).getStringValue() == value); 00416 return false; 00417 } 00418 00419 00420 APPSPACK::Parameter::List& APPSPACK::Parameter::List::sublist(const string& name) 00421 { 00422 // Find name in list, if it exists. 00423 Iterator i = params.find(name); 00424 00425 // If it does exist and is a list, return the list value. 00426 // Otherwise, throw an error. 00427 if (i != params.end()) { 00428 if (entry(i).isList()) 00429 return (entry(i).getListValue()); 00430 else 00431 cerr << "ERROR: Parameter " << name << " is not a list." << endl; 00432 throw "NOX Error"; 00433 } 00434 00435 // If it does not exist, create a new empty list and return a reference 00436 return params[name].setList(true); 00437 } 00438 00439 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, const Value& value) const 00440 { 00441 ConstIterator i = params.find(name); 00442 if ((i != params.end()) && (entry(i).isValue())) 00443 return (entry(i).getValueValue() == value); 00444 return false; 00445 } 00446 00447 00448 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, const Vector& value) const 00449 { 00450 ConstIterator i = params.find(name); 00451 if ((i != params.end()) && (entry(i).isVector())) 00452 return (entry(i).getVectorValue() == value); 00453 return false; 00454 } 00455 00456 00457 const APPSPACK::Parameter::List& APPSPACK::Parameter::List::sublist(const string& name) const 00458 { 00459 // Find name in list, if it exists. 00460 ConstIterator i = params.find(name); 00461 00462 // If it does not exist, throw an error 00463 if (i == params.end()) { 00464 cerr << "ERROR: Parameter " << name << " is not a valid list." << endl; 00465 throw "NOX Error"; 00466 } 00467 00468 // If it does exist and is a list, return the list value. 00469 if (entry(i).isList()) 00470 return (entry(i).getListValue()); 00471 00472 // Otherwise, the parameter exists but is not a list. Throw an error. 00473 cerr << "ERROR: Parameter " << name << " is not a list." << endl; 00474 throw "NOX Error"; 00475 } 00476 00477 ostream& APPSPACK::Parameter::List::print(ostream& stream, int indent) const 00478 { 00479 if (params.begin() == params.end()) 00480 { 00481 for (int j = 0; j < indent; j ++) 00482 stream << ' '; 00483 stream << "[empty list]" << endl; 00484 } 00485 else 00486 for (ConstIterator i = params.begin(); i != params.end(); ++i) 00487 { 00488 for (int j = 0; j < indent; j ++) 00489 stream << ' '; 00490 if (entry(i).isList()) 00491 { 00492 stream << name(i) << " -> " << endl; 00493 entry(i).getListValue().print(stream, indent + 2); 00494 } 00495 else 00496 stream << name(i) << " = " << entry(i) << endl; 00497 } 00498 return stream; 00499 } 00500 00501 void APPSPACK::Parameter::List::pack() const 00502 { 00503 for (ConstIterator i = params.begin(); i != params.end(); ++i) 00504 { 00505 GCI::pack(NEW_ENTRY); 00506 GCI::pack(name(i)); 00507 entry(i).pack(); 00508 } 00509 GCI::pack(END_OF_LIST); 00510 } 00511 00512 void APPSPACK::Parameter::List::unpack() 00513 { 00514 int code; 00515 string name; 00516 GCI::unpack(code); 00517 00518 while (code != END_OF_LIST) 00519 { 00520 GCI::unpack(name); 00521 params[name].unpack(); 00522 GCI::unpack(code); 00523 } 00524 00525 } 00526 00527 00528 #ifdef SNL_TFLOPS_ENV 00529 00530 const string& APPSPACK::Parameter::List::name(ConstIterator i) const 00531 { 00532 return ((*i).first); 00533 } 00534 00535 APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(Iterator i) 00536 { 00537 return ((*i).second); 00538 } 00539 00540 const APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(ConstIterator i) const 00541 { 00542 return ((*i).second); 00543 } 00544 00545 #else 00546 00547 const string& APPSPACK::Parameter::List::name(ConstIterator i) const 00548 { 00549 return (i->first); 00550 } 00551 00552 APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(Iterator i) 00553 { 00554 return (i->second); 00555 } 00556 00557 const APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(ConstIterator i) const 00558 { 00559 return (i->second); 00560 } 00561 00562 #endif 00563 00564

 

© Sandia Corporation | Site Contact | Privacy and Security

Generated on Wed Dec 14 18:41:04 2005 for APPSPACK 4.0.2 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2002