Changeset 1080 in Sophya for trunk/SophyaLib/BaseTools/dvlist.cc
- Timestamp:
- Jul 24, 2000, 2:49:24 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/dvlist.cc
r913 r1080 38 38 //-- 39 39 40 char MuTyV::myStrBuf[64]; // Declare static ds le .h41 40 42 41 static MuTyV ddvdum(-9.e19); 43 42 44 /*!45 \class SOPHYA::MuTyV46 \ingroup SysTools47 Simple utility class which can be used to hold values of type48 string, integer (\b int_8) or float (\b r_8) and providing49 easy conversion methods between these types.50 */51 43 52 44 /*! … … 61 53 used to represent FITS headers. The class \b SOPHYA::ObjFileIO<DVList> 62 54 handles serialisation for DVList. (See SOPHYA::PPersist ). 63 An 64 \code 65 // ------- Using MuTyV objects ------- 66 MuTyV mvu; // MuTyV variable declaration 67 mvu = 60; // mvu contains the integer value 60 68 mvu = 66.6; // and now the double value 66.6 69 string ds = mvu; // ds contains the string "66.6" 70 MuTyV mvi(14); // New MuTyV variable containing integer value 14 71 r_4 x = mvi; // x has the value 14.0 72 MuTyV mvs("Bonjour !"); // mvs contains the string "Bonjour !" 73 string s = mvs; // s vaut "Bonjour, Ca va ?" 55 74 56 // ------- Using DVList objects ------ 75 57 DVList dvl; … … 179 161 { 180 162 case 'I' : 181 SetI((*it).first, (*it).second.elval. mtv.iv);163 SetI((*it).first, (*it).second.elval.iv); 182 164 break; 183 165 case 'D' : 184 SetD((*it).first, (*it).second.elval.mtv.dv); 166 SetD((*it).first, (*it).second.elval.dv); 167 break; 168 case 'Z' : 169 SetZ((*it).first, complex<r_8>((*it).second.elval.dv, (*it).second.elval.dv_im)); 185 170 break; 186 171 case 'S' : 187 SetS((*it).first, (*it).second.elval.mtv.strv);172 SetS((*it).first, *((*it).second.elval.strv)); 188 173 break; 189 174 default : … … 214 199 ValList::iterator it = mvlist.find(key); 215 200 if (it == mvlist.end()) return(def); 216 if ( (*it).second.elval.typ != 'I') return(def); 217 return((*it).second.elval.mtv.iv); 201 return((*it).second.elval.iv); 218 202 } 219 203 … … 225 209 ValList::iterator it = mvlist.find(key); 226 210 if (it == mvlist.end()) return(def); 227 if ( (*it).second.elval.typ != 'D') return(def); 228 return((*it).second.elval.mtv.dv); 211 return((*it).second.elval.dv); 212 } 213 214 /* --Methode-- */ 215 /*! Returns the value corresponding to name \b key, converted to complex 216 Default value \b def is returned if name \b key not found */ 217 complex<r_8> DVList::GetZ(string const& key, complex<r_8> def) 218 { 219 ValList::iterator it = mvlist.find(key); 220 if (it == mvlist.end()) return(def); 221 return((*it).second.elval.dv); 229 222 } 230 223 … … 236 229 ValList::iterator it = mvlist.find(key); 237 230 if (it == mvlist.end()) return(def); 238 if ( (*it).second.elval.typ != 'S') return(def); 239 return((*it).second.elval.mtv.strv); 231 return(*((*it).second.elval.strv)); 240 232 } 241 233 … … 252 244 // void SetI(string const& key, int_8 val) 253 245 // void SetD(string const& key, r_8 val) 246 // void SetZ(string const& key, complex<r_8> val) 254 247 // void SetS(string const& key, char* val) 255 248 // void SetS(string const& key, string val) 256 // Crée la variable de nom "key", de type entier, double, string et249 // Crée la variable de nom "key", de type entier, double, complexe, string et 257 250 // lui attribue la valeur "val". Si une variable du même nom existe, 258 251 // sa valeur et eventuellement son type sont modifiés. Les noms de … … 280 273 281 274 /* --Methode-- */ 275 void DVList::SetZ(string const& key, complex<r_8> val) 276 /*! Appends or sets the complex value \b val in the list with name \b key */ 277 { 278 Get(key) = val; 279 } 280 281 /* --Methode-- */ 282 282 /*! Appends or sets the string value \b val in the list with name \b key */ 283 283 void DVList::SetS(string const& key, char const* val) … … 289 289 /* --Methode-- */ 290 290 /*! Appends or sets the string value \b val in the list with name \b key */ 291 void DVList::SetS(string const& key, string val)291 void DVList::SetS(string const& key, string const& val) 292 292 { 293 293 MuTyV div(val); … … 367 367 case 'I' : 368 368 sprintf(buff, "%s = %ld (int) %s\n", (*it).first.substr(0,64).c_str(), 369 (long)((*it).second.elval. mtv.iv), (*it).second.elcomm.substr(0,128).c_str());369 (long)((*it).second.elval.iv), (*it).second.elcomm.substr(0,128).c_str()); 370 370 break; 371 371 case 'D' : 372 372 sprintf(buff, "%s = %.20g (double) %s\n", (*it).first.substr(0,64).c_str(), 373 (*it).second.elval.mtv.dv, (*it).second.elcomm.substr(0,128).c_str()); 373 (*it).second.elval.dv, (*it).second.elcomm.substr(0,128).c_str()); 374 break; 375 case 'Z' : 376 sprintf(buff, "%s = %.20g %.20g i (complex) %s\n", (*it).first.substr(0,64).c_str(), 377 (*it).second.elval.dv, (*it).second.elval.dv_im, (*it).second.elcomm.substr(0,128).c_str()); 374 378 break; 375 379 case 'S' : 376 380 sprintf(buff, "%s = %s (string) %s\n", (*it).first.substr(0,64).c_str(), 377 (*it).second.elval. mtv.strv, (*it).second.elcomm.substr(0,128).c_str());381 (*it).second.elval.strv->c_str(), (*it).second.elcomm.substr(0,128).c_str()); 378 382 break; 379 383 default : … … 441 445 switch ((*it).second.elval.typ) { 442 446 case 'I' : 443 sprintf(buf,"I %s %ld", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval. mtv.iv) );447 sprintf(buf,"I %s %ld", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval.iv) ); 444 448 sfw = buf; s.PutStr(sfw); 445 449 break; 446 450 case 'D' : 447 sprintf(buf,"D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval. mtv.dv );451 sprintf(buf,"D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv ); 448 452 sfw = buf; s.PutStr(sfw); 449 453 break; 454 case 'Z' : 455 sprintf(buf,"Z %s %.20g %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv, 456 (*it).second.elval.dv_im); 457 sfw = buf; s.PutStr(sfw); 458 break; 450 459 case 'S' : 451 sprintf(buf,"S %s %s", (*it).first.substr(0,64).c_str(), (*it).second.elval. mtv.strv);460 sprintf(buf,"S %s %s", (*it).first.substr(0,64).c_str(), (*it).second.elval.strv->c_str() ); 452 461 sfw = buf; s.PutStr(sfw); 453 462 break; … … 470 479 char buf[512]; 471 480 string sfr; 472 int_8 j,iv; 473 r_8 dv; 481 int_8 j,iv,k; 482 r_8 dv, dvi; 483 complex<r_8> z; 474 484 bool ok=true; 475 485 buf[0] = '\0'; … … 505 515 dobj->SetD(key, dv); 506 516 break; 517 case 'Z' : 518 k = posc(buf+j+1, ' ')+j+1; 519 buf[k] = '\0'; 520 dv = atof(buf+j+1); 521 dvi = atof(buf+k+1); 522 key = buf+2; 523 z = complex<r_8>(dv, dvi); 524 dobj->SetZ(key, z); 525 break; 507 526 case 'S' : 508 527 key = buf+2;
Note:
See TracChangeset
for help on using the changeset viewer.