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

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

 

© 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