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_Entry.cpp

Go to the documentation of this file.
00001 // $Id: APPSPACK_Parameter_Entry.cpp,v 1.5.2.1 2005/06/29 17:07:42 tgkolda Exp $ 00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/src/APPSPACK_Parameter_Entry.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_Entry.hpp" 00039 #include "APPSPACK_Parameter_List.hpp" 00040 #include "APPSPACK_GCI.hpp" 00041 00042 using namespace APPSPACK::Parameter; 00043 00044 Entry::Entry() : 00045 type(APPSPACK_NONE), 00046 bval(false), 00047 ival(0), 00048 dval(0), 00049 sval(""), 00050 lval(NULL), 00051 valueval(), 00052 vectorval(), 00053 isGotten(false), 00054 isSetByGet(false) 00055 { 00056 } 00057 00058 Entry::Entry(const Entry& source) : 00059 type(APPSPACK_NONE), 00060 bval(false), 00061 ival(0), 00062 dval(0), 00063 sval(""), 00064 lval(NULL), 00065 valueval(), 00066 vectorval(), 00067 isGotten(false), 00068 isSetByGet(false) 00069 { 00070 operator=(source); 00071 } 00072 00073 Entry& Entry::operator=(const Entry& source) 00074 { 00075 if (&source == this) 00076 return *this; 00077 00078 reset(); 00079 00080 type = source.type; 00081 bval = source.bval; 00082 ival = source.ival; 00083 dval = source.dval; 00084 sval = source.sval; 00085 00086 if ((type == APPSPACK_LIST) && (source.lval != NULL)) 00087 { 00088 lval = new List(*source.lval); 00089 } 00090 00091 valueval = source.valueval; 00092 vectorval = source.vectorval; 00093 00094 isGotten = source.isGotten; 00095 isSetByGet = source.isSetByGet; 00096 00097 return *this; 00098 } 00099 00100 Entry::Entry(bool value, bool isCreatedByGet) : 00101 type(APPSPACK_BOOL), 00102 bval(value), 00103 ival(0), 00104 dval(0), 00105 sval(""), 00106 lval(NULL), 00107 valueval(), 00108 vectorval(), 00109 isGotten(false), 00110 isSetByGet(isCreatedByGet) 00111 { 00112 } 00113 00114 Entry::Entry(int value, bool isCreatedByGet) : 00115 type(APPSPACK_INT), 00116 bval(false), 00117 ival(value), 00118 dval(0), 00119 sval(""), 00120 lval(NULL), 00121 valueval(), 00122 vectorval(), 00123 isGotten(false), 00124 isSetByGet(isCreatedByGet) 00125 { 00126 } 00127 00128 Entry::Entry(double value, bool isCreatedByGet) : 00129 type(APPSPACK_DOUBLE), 00130 bval(false), 00131 ival(0), 00132 dval(value), 00133 sval(""), 00134 lval(NULL), 00135 valueval(), 00136 vectorval(), 00137 isGotten(false), 00138 isSetByGet(isCreatedByGet) 00139 { 00140 } 00141 00142 Entry::Entry(const string& value, bool isCreatedByGet) : 00143 type(APPSPACK_STRING), 00144 bval(false), 00145 ival(0), 00146 dval(0), 00147 sval(value), 00148 lval(NULL), 00149 valueval(), 00150 vectorval(), 00151 isGotten(false), 00152 isSetByGet(isCreatedByGet) 00153 { 00154 } 00155 00156 Entry::Entry(const Value& value, bool isCreatedByGet) : 00157 type(APPSPACK_VALUE), 00158 bval(false), 00159 ival(0), 00160 dval(0), 00161 sval("" ), 00162 lval(NULL), 00163 valueval(value), 00164 vectorval(), 00165 isGotten(false), 00166 isSetByGet(isCreatedByGet) 00167 { 00168 } 00169 00170 Entry::Entry(const Vector& value, bool isCreatedByGet) : 00171 type(APPSPACK_VECTOR), 00172 bval(false), 00173 ival(0), 00174 dval(0), 00175 sval("" ), 00176 lval(NULL), 00177 valueval(), 00178 vectorval(value), 00179 isGotten(false), 00180 isSetByGet(isCreatedByGet) 00181 { 00182 } 00183 00184 Entry::~Entry() 00185 { 00186 reset(); 00187 } 00188 00189 void Entry::reset() 00190 { 00191 type = APPSPACK_NONE; 00192 00193 delete lval; 00194 lval = NULL; 00195 00196 isGotten = false; 00197 isSetByGet = false; 00198 } 00199 00200 void Entry::setValue(bool value, bool isCreatedByGet) 00201 { 00202 reset(); 00203 type = APPSPACK_BOOL; 00204 bval = value; 00205 isSetByGet = isCreatedByGet; 00206 } 00207 00208 void Entry::setValue(int value, bool isCreatedByGet) 00209 { 00210 reset(); 00211 type = APPSPACK_INT; 00212 ival = value; 00213 isSetByGet = isCreatedByGet; 00214 } 00215 00216 void Entry::setValue(double value, bool isCreatedByGet) 00217 { 00218 reset(); 00219 type = APPSPACK_DOUBLE; 00220 dval = value; 00221 isSetByGet = isCreatedByGet; 00222 } 00223 00224 void Entry::setValue(const char* value, bool isCreatedByGet) 00225 { 00226 reset(); 00227 type = APPSPACK_STRING; 00228 sval = value; 00229 isSetByGet = isCreatedByGet; 00230 } 00231 00232 void Entry::setValue(const string& value, bool isCreatedByGet) 00233 { 00234 reset(); 00235 type = APPSPACK_STRING; 00236 sval = value; 00237 isSetByGet = isCreatedByGet; 00238 } 00239 00240 void Entry::setValue(const Value& value, bool isCreatedByGet) 00241 { 00242 reset(); 00243 type = APPSPACK_VALUE; 00244 valueval = value; 00245 isSetByGet = isCreatedByGet; 00246 } 00247 00248 void Entry::setValue(const Vector& value, bool isCreatedByGet) 00249 { 00250 reset(); 00251 type = APPSPACK_VECTOR; 00252 vectorval = value; 00253 isSetByGet = isCreatedByGet; 00254 } 00255 00256 APPSPACK::Parameter::List& Entry::setList(bool isCreatedByGet) 00257 { 00258 reset(); 00259 type = APPSPACK_LIST; 00260 lval = new List(); 00261 isSetByGet = isCreatedByGet; 00262 isGotten = true; 00263 return *lval; 00264 } 00265 00266 00267 bool Entry::isBool() const 00268 { 00269 return (type == APPSPACK_BOOL); 00270 } 00271 00272 bool Entry::isInt() const 00273 { 00274 return (type == APPSPACK_INT); 00275 } 00276 00277 bool Entry::isDouble() const 00278 { 00279 return (type == APPSPACK_DOUBLE); 00280 } 00281 00282 bool Entry::isString() const 00283 { 00284 return (type == APPSPACK_STRING); 00285 } 00286 00287 bool Entry::isList() const 00288 { 00289 return (type == APPSPACK_LIST); 00290 } 00291 00292 bool Entry::isValue() const 00293 { 00294 return (type == APPSPACK_VALUE); 00295 } 00296 00297 bool Entry::isVector() const 00298 { 00299 return (type == APPSPACK_VECTOR); 00300 } 00301 00302 bool Entry::getBoolValue() const 00303 { 00304 isGotten = true; 00305 return bval; 00306 } 00307 00308 int Entry::getIntValue() const 00309 { 00310 isGotten = true; 00311 return ival; 00312 } 00313 00314 double Entry::getDoubleValue() const 00315 { 00316 isGotten = true; 00317 return dval; 00318 } 00319 00320 const string& Entry::getStringValue() const 00321 { 00322 isGotten = true; 00323 return sval; 00324 } 00325 00326 APPSPACK::Parameter::List& Entry::getListValue() 00327 { 00328 isGotten = true; 00329 return *lval; 00330 } 00331 00332 const APPSPACK::Parameter::List& Entry::getListValue() const 00333 { 00334 isGotten = true; 00335 return *lval; 00336 } 00337 00338 const APPSPACK::Value& Entry::getValueValue() const 00339 { 00340 isGotten = true; 00341 return valueval; 00342 } 00343 00344 const APPSPACK::Vector& Entry::getVectorValue() const 00345 { 00346 isGotten = true; 00347 return vectorval; 00348 } 00349 00350 ostream& Entry::leftshift(ostream& stream) const 00351 { 00352 switch(type) { 00353 case APPSPACK_BOOL: 00354 stream << (bval ? "true" : "false"); 00355 break; 00356 case APPSPACK_INT: 00357 stream << ival; 00358 break; 00359 case APPSPACK_DOUBLE: 00360 stream << dval; 00361 break; 00362 case APPSPACK_STRING: 00363 stream << "\"" << sval << "\""; 00364 break; 00365 case APPSPACK_LIST: 00366 break; 00367 case APPSPACK_VALUE: 00368 stream << valueval; 00369 break; 00370 case APPSPACK_VECTOR: 00371 stream << vectorval; 00372 break; 00373 default: 00374 stream << "(empty non-typed parameter)"; 00375 break; 00376 } 00377 00378 if (isSetByGet) 00379 stream << " [default]"; 00380 else if (!isGotten) 00381 stream << " [unused]"; 00382 00383 00384 return stream; 00385 } 00386 00387 00388 void Entry::pack() const 00389 { 00390 switch(type) { 00391 case APPSPACK_BOOL: 00392 GCI::pack(APPSPACK_BOOL); 00393 GCI::pack(bval); 00394 break; 00395 case APPSPACK_INT: 00396 GCI::pack(APPSPACK_INT); 00397 GCI::pack(ival); 00398 break; 00399 case APPSPACK_DOUBLE: 00400 GCI::pack(APPSPACK_DOUBLE); 00401 GCI::pack(dval); 00402 break; 00403 case APPSPACK_STRING: 00404 GCI::pack(APPSPACK_STRING); 00405 GCI::pack(sval); 00406 break; 00407 case APPSPACK_LIST: 00408 GCI::pack(APPSPACK_LIST); 00409 lval->pack(); 00410 break; 00411 case APPSPACK_VALUE: 00412 { 00413 GCI::pack(APPSPACK_VALUE); 00414 bool isF = valueval.getIsValue(); 00415 double f = valueval.getValue(); 00416 GCI::pack(isF); 00417 GCI::pack(f); 00418 break; 00419 } 00420 case APPSPACK_VECTOR: 00421 GCI::pack(APPSPACK_VECTOR); 00422 GCI::pack(vectorval); 00423 break; 00424 default: 00425 cerr << "APPSPACK::Parameter::Entry::pack - Empty non-typed parameter"; 00426 throw "APPSPACK Error"; 00427 break; 00428 } 00429 00430 GCI::pack(isGotten); 00431 GCI::pack(isSetByGet); 00432 } 00433 00434 void Entry::unpack() 00435 { 00436 int itype; 00437 GCI::unpack(itype); 00438 00439 switch(itype) { 00440 case APPSPACK_BOOL: 00441 type = APPSPACK_BOOL; 00442 GCI::unpack(bval); 00443 break; 00444 case APPSPACK_INT: 00445 type = APPSPACK_INT; 00446 GCI::unpack(ival); 00447 break; 00448 case APPSPACK_DOUBLE: 00449 type = APPSPACK_DOUBLE; 00450 GCI::unpack(dval); 00451 break; 00452 case APPSPACK_STRING: 00453 type = APPSPACK_STRING; 00454 GCI::unpack(sval); 00455 break; 00456 case APPSPACK_LIST: 00457 type = APPSPACK_LIST; 00458 lval = new List(); 00459 lval->unpack(); 00460 break; 00461 case APPSPACK_VALUE: 00462 type = APPSPACK_VALUE; 00463 bool isF; 00464 double f; 00465 GCI::unpack(isF); 00466 GCI::unpack(f); 00467 valueval.setValueTo(isF,f); 00468 break; 00469 case APPSPACK_VECTOR: 00470 type = APPSPACK_VECTOR; 00471 GCI::unpack(vectorval); 00472 break; 00473 default: 00474 cerr << "APPSPACK::Parameter::Entry::pack - Empty non-typed parameter"; 00475 throw "APPSPACK Error"; 00476 break; 00477 } 00478 00479 GCI::unpack(isGotten); 00480 GCI::unpack(isSetByGet); 00481 } 00482 00483 ostream& operator<<(ostream& stream, const Entry& e) 00484 { 00485 return e.leftshift(stream); 00486 } 00487 00488

 

© 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