Changeset 1080 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Jul 24, 2000, 2:49:24 PM (25 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 2 added
- 3 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; -
trunk/SophyaLib/BaseTools/dvlist.h
r913 r1080 9 9 10 10 #include <stdio.h> 11 12 11 #include <iostream.h> 13 12 13 #include "mutyv.h" 14 14 #include <list> 15 15 #include <map> 16 #include <string.h>17 #include <string>18 16 19 17 namespace SOPHYA { 20 21 // Classe utilitaire pour manipuler des variables typees22 //! A simple class for holding string, integer and float type values.23 class MuTyV {24 public:25 union {26 int_8 iv;27 r_8 dv;28 char strv[39];29 } mtv;30 char typ;31 32 static char myStrBuf[64];33 34 inline MuTyV() { typ = 'I'; mtv.iv = 0; mtv.dv = 0.; mtv.strv[0] ='\0'; }35 inline MuTyV(MuTyV const & a) { typ = a.typ; mtv = a.mtv; }36 inline MuTyV(int_4 i) { typ = 'I'; mtv.iv = (int_8)i; mtv.dv = 0.; mtv.strv[0] ='\0'; }37 inline MuTyV(int_8 i) { typ = 'I'; mtv.iv = i; mtv.dv = 0.; mtv.strv[0] ='\0'; }38 inline MuTyV(r_4 f) { typ = 'D'; mtv.dv = (r_8)f; mtv.iv = 0; mtv.strv[0] ='\0'; }39 inline MuTyV(r_8 d) { typ = 'D'; mtv.dv = d; mtv.iv = 0; mtv.strv[0] ='\0'; }40 inline MuTyV(char const* s) { typ = 'S'; strncpy(mtv.strv, s, 39); mtv.strv[38] = '\0'; }41 inline MuTyV(string const& s) { typ = 'S'; strncpy(mtv.strv, s.c_str(), 39); mtv.strv[38] = '\0'; }42 inline MuTyV & operator= (MuTyV const & a) { typ = a.typ; mtv = a.mtv; return(*this); }43 inline int_4 operator= (int_4 v) { typ = 'I'; mtv.iv = (int_8)v; return(v); }44 inline int_8 operator= (int_8 v) { typ = 'I'; mtv.iv = v; return(v); }45 inline r_4 operator= (r_4 v) { typ = 'D'; mtv.dv = (r_8)v; return(v); }46 inline r_8 operator= (r_8 v) { typ = 'D'; mtv.dv = v; return(v); }47 inline char* operator= (char* s) { typ = 'S'; strncpy(mtv.strv, s, 39);48 mtv.strv[38] = '\0'; return(s); }49 inline string& operator= (string& s) { typ = 'S'; strncpy(mtv.strv, s.c_str(), 39);50 mtv.strv[38] = '\0'; return(s); }51 52 inline operator int_4() { if (typ == 'I') return((int_4)mtv.iv);53 else if (typ == 'D') return((int_4)mtv.dv);54 else return(atol(mtv.strv)); }55 inline operator int_8() { if (typ == 'I') return((int_8)mtv.iv);56 else if (typ == 'D') return((int_8)mtv.dv);57 else return(atol(mtv.strv)); }58 inline operator r_4() { if (typ == 'I') return((r_4)mtv.iv);59 else if (typ == 'D') return((r_4)mtv.dv);60 else return((r_4)atof(mtv.strv)); }61 inline operator r_8() { if (typ == 'I') return((r_8)mtv.iv);62 else if (typ == 'D') return(mtv.dv);63 else return(atof(mtv.strv)); }64 inline operator string() { char *ss=myStrBuf;65 if (typ == 'I') sprintf(ss,"%ld", (long)mtv.iv);66 else if (typ == 'D') sprintf(ss,"%.20g", mtv.dv);67 else ss = mtv.strv;68 return(ss); }69 };70 18 71 19 // Classe liste de variables Dynamic Variable List … … 74 22 class DVList : public AnyDataObj { 75 23 public: 76 // enum {classId = ClassId_DVList };77 24 78 25 DVList(); … … 89 36 int_8 GetI(string const& key, int_8 def=-1); 90 37 r_8 GetD(string const& key, r_8 def=-9.e19); 38 complex<r_8> GetZ(string const& key, complex<r_8> def=-9.e19); 91 39 string GetS(string const& key, char* def=""); 92 40 string GetComment(string const& key); … … 94 42 void SetI(string const& key, int_8 val); 95 43 void SetD(string const& key, r_8 val); 44 void SetZ(string const& key, complex<r_8> val); 96 45 void SetS(string const& key, char const* val); 97 void SetS(string const& key, string val);46 void SetS(string const& key, string const& val); 98 47 void SetComment(string const& key, string const& comm); 99 48 -
trunk/SophyaLib/BaseTools/sversion.h
r1078 r1080 3 3 4 4 #define SOPHYA_VERSION 0.9 5 #define SOPHYA_REVISION 715 #define SOPHYA_REVISION 80 6 6 #define SOPHYA_TAG "V_Jul2000" 7 7
Note:
See TracChangeset
for help on using the changeset viewer.