Sandia Home Sandia Home
Main Page | Publications | Downloads | Configuration | Running the Code | Solver Parameters | FAQ | Namespace List | Class Hierarchy | 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.17 2006/06/30 01:42:08 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 Vector& value)
00086 {
00087   params[name].setValue(value);
00088 }
00089 
00090 void APPSPACK::Parameter::List::setParameter(const string& name, const Matrix& value)
00091 {
00092   params[name].setValue(value);
00093 }
00094 
00095 bool APPSPACK::Parameter::List::getParameter(const string& name, bool nominal)
00096 {
00097   ConstIterator i = params.find(name);
00098 
00099   if (i == params.end()) {
00100     params[name].setValue(nominal, true);
00101     i = params.find(name);
00102   }
00103 
00104   if ((i != params.end()) && (entry(i).isBool()))
00105     return entry(i).getBoolValue();
00106 
00107   cerr << "APPSPACK::Parameter::List::getParameter - get error for bool" << endl;
00108   throw "APPSPACK Error";
00109 }
00110 
00111 int APPSPACK::Parameter::List::getParameter(const string& name, int nominal) 
00112 {
00113   ConstIterator i = params.find(name);
00114 
00115   if (i == params.end()) {
00116     params[name].setValue(nominal, true);
00117     i = params.find(name);
00118   }
00119 
00120   if ((i != params.end()) && (entry(i).isInt()))
00121     return entry(i).getIntValue();
00122 
00123   cerr << "APPSPACK::Parameter::List::getParameter - get error for int" << endl;
00124   throw "APPSPACK Error";
00125 }
00126 
00127 double APPSPACK::Parameter::List::getParameter(const string& name, double nominal) 
00128 {
00129   ConstIterator i = params.find(name);
00130 
00131   if (i == params.end()) {
00132     params[name].setValue(nominal, true);
00133     i = params.find(name);
00134   }
00135 
00136   if ((i != params.end()) && (entry(i).isDouble()))
00137     return entry(i).getDoubleValue();
00138 
00139   cerr << "APPSPACK::Parameter::List::getParameter - get error for double" << endl;
00140   throw "APPSPACK Error";
00141 
00142 }
00143 
00144 const string& APPSPACK::Parameter::List::getParameter(const string& name, const char* nominal) 
00145 {
00146   ConstIterator i = params.find(name);
00147 
00148   if (i == params.end()) {
00149     params[name].setValue(nominal, true);
00150     i = params.find(name);
00151   }
00152 
00153   if ((i != params.end()) && (entry(i).isString()))
00154     return entry(i).getStringValue();
00155 
00156   cerr << "APPSPACK::Parameter::List::getParameter - get error for string" << endl;
00157   throw "APPSPACK Error";
00158 }
00159 
00160 const string& APPSPACK::Parameter::List::getParameter(const string& name, const string& nominal) 
00161 {
00162   ConstIterator i = params.find(name);
00163 
00164   if (i == params.end()) {
00165     params[name].setValue(nominal, true);
00166     i = params.find(name);
00167   }
00168 
00169   if ((i != params.end()) && (entry(i).isString()))
00170     return entry(i).getStringValue();
00171 
00172   cerr << "APPSPACK::Parameter::List::getParameter - get error for string" << endl;
00173   throw "APPSPACK Error";
00174 }
00175   
00176 const APPSPACK::Vector& APPSPACK::Parameter::List::getParameter(const string& name, const Vector& nominal) 
00177 {
00178   ConstIterator i = params.find(name);
00179 
00180   if (i == params.end()) 
00181   {
00182     params[name].setValue(nominal, true);
00183     i = params.find(name);
00184   }
00185 
00186   if ((i != params.end()) && (entry(i).isVector()))
00187     return entry(i).getVectorValue();
00188 
00189   cerr << "APPSPACK::Parameter::List::getParameter - get error for Vector" << endl;
00190   throw "APPSPACK Error";
00191 }
00192   
00193 bool APPSPACK::Parameter::List::getParameter(const string& name, bool nominal) const
00194 {
00195   ConstIterator i = params.find(name);
00196   if ((i != params.end()) && (entry(i).isBool()))
00197     return entry(i).getBoolValue();
00198   return nominal;
00199 }
00200 
00201 int APPSPACK::Parameter::List::getParameter(const string& name, int nominal) const
00202 {
00203   ConstIterator i = params.find(name);
00204   if ((i != params.end()) && (entry(i).isInt()))
00205     return entry(i).getIntValue();
00206   return nominal;
00207 }
00208 
00209 double APPSPACK::Parameter::List::getParameter(const string& name, double nominal) const
00210 {
00211   ConstIterator i = params.find(name);
00212   if ((i != params.end()) && (entry(i).isDouble()))
00213     return entry(i).getDoubleValue();
00214   return nominal;
00215 }
00216 
00217 const string& APPSPACK::Parameter::List::getParameter(const string& name, const char* nominal) const
00218 {
00219   ConstIterator i = params.find(name);
00220   if ((i != params.end()) && (entry(i).isString()))
00221     return entry(i).getStringValue();
00222 
00223   // Save nominal char* value as a string, and return the string value.
00224   tmpstrings.push_back(nominal);
00225   return tmpstrings.back();
00226 }
00227 
00228 const string& APPSPACK::Parameter::List::getParameter(const string& name, const string& nominal) const
00229 {
00230   ConstIterator i = params.find(name);
00231   if ((i != params.end()) && (entry(i).isString()))
00232     return entry(i).getStringValue();
00233   return nominal;
00234 }
00235   
00236 const APPSPACK::Vector& APPSPACK::Parameter::List::getParameter(const string& name, const Vector& nominal) const
00237 {
00238   ConstIterator i = params.find(name);
00239   if ((i != params.end()) && (entry(i).isVector()))
00240     return entry(i).getVectorValue();
00241   return nominal;
00242 }
00243   
00244 
00245 double APPSPACK::Parameter::List::getDoubleParameter(const string& name) const
00246 {
00247   ConstIterator i = params.find(name);
00248 
00249   if ((i != params.end()) && (entry(i).isDouble()))
00250     return entry(i).getDoubleValue();
00251 
00252   cerr << "APPSPACK::Parameter::List::getValueParameter - no such parameter (" << name << ")"<< endl;
00253   throw "APPSPACK Error";
00254 }
00255   
00256 const APPSPACK::Vector& APPSPACK::Parameter::List::getVectorParameter(const string& name) const
00257 {
00258   ConstIterator i = params.find(name);
00259 
00260   if ((i != params.end()) && (entry(i).isVector()))
00261     return entry(i).getVectorValue();
00262 
00263   cerr << "APPSPACK::Parameter::List::getVectorParameter - no such parameter (" << name << ")" << endl;
00264   throw "APPSPACK Error";
00265 }
00266 
00267 const APPSPACK::Matrix& APPSPACK::Parameter::List::getMatrixParameter(const string& name) const
00268 {
00269   ConstIterator i = params.find(name);
00270 
00271   if ((i != params.end()) && (entry(i).isMatrix()))
00272     return entry(i).getMatrixValue();
00273 
00274   cerr << "APPSPACK::Parameter::List::getMatrixParameter - no such parameter (" << name << ")" << endl;
00275   throw "APPSPACK Error";
00276 }
00277 
00278 bool APPSPACK::Parameter::List::isParameterBool(const string& name) const
00279 {
00280   ConstIterator i = params.find(name);
00281 
00282   if (i != params.end())
00283     return (entry(i).isBool());
00284 
00285   return false;
00286 }
00287 
00288 bool APPSPACK::Parameter::List::isParameterInt(const string& name) const
00289 {
00290   ConstIterator i = params.find(name);
00291 
00292   if (i != params.end())
00293     return (entry(i).isInt());
00294 
00295   return false;
00296 }
00297 
00298 bool APPSPACK::Parameter::List::isParameterDouble(const string& name) const
00299 {
00300   ConstIterator i = params.find(name);
00301 
00302   if (i != params.end())
00303     return (entry(i).isDouble());
00304 
00305   return false;
00306 }
00307 
00308 bool APPSPACK::Parameter::List::isParameterString(const string& name) const
00309 {
00310   ConstIterator i = params.find(name);
00311 
00312   if (i != params.end())
00313     return (entry(i).isString());
00314 
00315   return false;
00316 }
00317 
00318 bool APPSPACK::Parameter::List::isParameterSublist(const string& name) const
00319 {
00320   ConstIterator i = params.find(name);
00321 
00322   if (i != params.end())
00323     return (entry(i).isList());
00324 
00325   return false;
00326 }
00327 
00328 bool APPSPACK::Parameter::List::isParameterVector(const string& name) const
00329 {
00330   ConstIterator i = params.find(name);
00331 
00332   if (i != params.end())
00333     return (entry(i).isVector());
00334 
00335   return false;
00336 }
00337 
00338 bool APPSPACK::Parameter::List::isParameterMatrix(const string& name) const
00339 {
00340   ConstIterator i = params.find(name);
00341 
00342   if (i != params.end())
00343     return (entry(i).isMatrix());
00344 
00345   return false;
00346 }
00347 
00348 bool APPSPACK::Parameter::List::isParameter(const string& name) const
00349 {
00350   return (params.find(name) != params.end());
00351 }
00352 
00353 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, bool value) const
00354 {
00355   ConstIterator i = params.find(name);
00356   if ((i != params.end()) && (entry(i).isBool()))
00357     return (entry(i).getBoolValue() == value);
00358   return false;
00359 }
00360 
00361 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, int value) const
00362 {
00363   ConstIterator i = params.find(name);
00364   if ((i != params.end()) && (entry(i).isInt()))
00365     return (entry(i).getIntValue() == value);
00366   return false;
00367 }
00368 
00369 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, double value) const
00370 {
00371   ConstIterator i = params.find(name);
00372   if ((i != params.end()) && (entry(i).isDouble()))
00373     return (entry(i).getDoubleValue() == value);
00374   return false;
00375 }
00376 
00377 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, const char* value) const
00378 {
00379   ConstIterator i = params.find(name);
00380   if ((i != params.end()) && (entry(i).isString()))
00381     return (entry(i).getStringValue() == value);
00382   return false;
00383 }
00384 
00385 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, const string& value) const
00386 {
00387   ConstIterator i = params.find(name);
00388   if ((i != params.end()) && (entry(i).isString()))
00389     return (entry(i).getStringValue() == value);
00390   return false;
00391 }
00392 
00393 bool APPSPACK::Parameter::List::isParameterEqual(const string& name, const Vector& value) const
00394 {
00395   ConstIterator i = params.find(name);
00396   if ((i != params.end()) && (entry(i).isVector()))
00397     return (entry(i).getVectorValue() == value);
00398   return false;
00399 }
00400 
00401 APPSPACK::Parameter::List& APPSPACK::Parameter::List::sublist(const string& name)
00402 {
00403   // Find name in list, if it exists.
00404   Iterator i = params.find(name);
00405 
00406   // If it does exist and is a list, return the list value.
00407   // Otherwise, throw an error.
00408   if (i != params.end()) {
00409     if (entry(i).isList()) 
00410       return (entry(i).getListValue());
00411     else
00412       cerr << "ERROR: Parameter " << name << " is not a list." << endl;
00413       throw "NOX Error";
00414   }
00415 
00416   // If it does not exist, create a new empty list and return a reference
00417   return params[name].setList(true);
00418 }
00419 
00420 const APPSPACK::Parameter::List& APPSPACK::Parameter::List::sublist(const string& name) const
00421 {
00422   // Find name in list, if it exists.
00423   ConstIterator i = params.find(name);
00424 
00425   // If it does not exist, throw an error
00426   if (i == params.end()) {
00427     cerr << "ERROR: Parameter " << name << " is not a valid list." << endl;
00428     throw "NOX Error";
00429   }
00430 
00431   // If it does exist and is a list, return the list value.
00432   if (entry(i).isList()) 
00433     return (entry(i).getListValue());
00434 
00435   // Otherwise, the parameter exists but is not a list. Throw an error.
00436   cerr << "ERROR: Parameter " << name << " is not a list." << endl;
00437   throw "NOX Error";
00438 }
00439   
00440 ostream& APPSPACK::Parameter::List::print(ostream& stream, int indent) const
00441 {
00442   if (params.begin() == params.end()) 
00443   {
00444     for (int j = 0; j < indent; j ++)
00445       stream << ' ';
00446     stream << "[empty list]" << endl;
00447   }
00448   else 
00449     for (ConstIterator i = params.begin(); i != params.end(); ++i) 
00450     {
00451       for (int j = 0; j < indent; j ++)
00452         stream << ' ';
00453       if (entry(i).isList()) 
00454       {
00455         stream << name(i) << " -> " << endl;
00456         entry(i).getListValue().print(stream, indent + 2);
00457       }
00458       else
00459         stream << name(i) << " = " << entry(i) << endl;
00460     }
00461   return stream;
00462 }
00463 
00464 void APPSPACK::Parameter::List::pack() const
00465 {
00466   for (ConstIterator i = params.begin(); i != params.end(); ++i) 
00467   {
00468     GCI::pack(NEW_ENTRY);
00469     GCI::pack(name(i));
00470     entry(i).pack();
00471   }
00472   GCI::pack(END_OF_LIST);
00473 }
00474 
00475 void APPSPACK::Parameter::List::unpack()
00476 {
00477   int code;
00478   string name;
00479   GCI::unpack(code);
00480 
00481   while (code != END_OF_LIST)
00482   {
00483     GCI::unpack(name);
00484     params[name].unpack();
00485     GCI::unpack(code);
00486   }
00487 
00488 }
00489 
00490 
00491 #ifdef SNL_TFLOPS_ENV
00492 
00493 const string& APPSPACK::Parameter::List::name(ConstIterator i) const
00494 {
00495   return ((*i).first);
00496 }
00497 
00498 APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(Iterator i)
00499 {
00500   return ((*i).second);
00501 }
00502 
00503 const APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(ConstIterator i) const
00504 {
00505   return ((*i).second);
00506 }
00507 
00508 #else
00509 
00510 const string& APPSPACK::Parameter::List::name(ConstIterator i) const
00511 {
00512   return (i->first);
00513 }
00514 
00515 APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(Iterator i)
00516 {
00517   return (i->second);
00518 }
00519 
00520 const APPSPACK::Parameter::Entry& APPSPACK::Parameter::List::entry(ConstIterator i) const
00521 {
00522   return (i->second);
00523 }
00524 
00525 #endif
00526 
00527 

 

© Sandia Corporation | Site Contact | Privacy and Security

Generated on Fri Feb 16 10:33:35 2007 for APPSPACK 5.0.1 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2002