Changeset 1310 in Sophya for trunk/SophyaLib
- Timestamp:
- Nov 9, 2000, 4:39:19 PM (25 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/dvlist.cc
r1245 r1310 158 158 for(it = dvl.mvlist.begin(); it != dvl.mvlist.end(); it++) 159 159 { 160 switch ((*it).second.elval. typ)160 switch ((*it).second.elval.Type()) 161 161 { 162 case 'I':162 case MuTyV::MTVInteger : 163 163 SetI((*it).first, (*it).second.elval.iv); 164 164 break; 165 case 'D':165 case MuTyV::MTVFloat : 166 166 SetD((*it).first, (*it).second.elval.dv); 167 167 break; 168 case 'Z':168 case MuTyV::MTVComplex : 169 169 SetZ((*it).first, complex<r_8>((*it).second.elval.dv, (*it).second.elval.dv_im)); 170 170 break; 171 case 'S':171 case MuTyV::MTVString : 172 172 SetS((*it).first, *((*it).second.elval.strv)); 173 173 break; … … 398 398 os << "DVList::Print() - NVar= " << (int)mvlist.size() << "\n"; 399 399 if (comment.length() > 0) os << comment << endl; 400 char buff[ 256];400 char buff[1024]; 401 401 ValList::const_iterator it; 402 402 for(it = mvlist.begin(); it != mvlist.end(); it++) { 403 switch ((*it).second.elval. typ)403 switch ((*it).second.elval.Type()) 404 404 { 405 case 'I':405 case MuTyV::MTVInteger : 406 406 sprintf(buff, "%s = %ld (int) %s\n", (*it).first.substr(0,64).c_str(), 407 407 (long)((*it).second.elval.iv), (*it).second.elcomm.substr(0,128).c_str()); 408 408 break; 409 case 'D':409 case MuTyV::MTVFloat : 410 410 sprintf(buff, "%s = %.20g (double) %s\n", (*it).first.substr(0,64).c_str(), 411 411 (*it).second.elval.dv, (*it).second.elcomm.substr(0,128).c_str()); 412 412 break; 413 case 'Z':413 case MuTyV::MTVComplex : 414 414 sprintf(buff, "%s = %.20g %.20g i (complex) %s\n", (*it).first.substr(0,64).c_str(), 415 415 (*it).second.elval.dv, (*it).second.elval.dv_im, (*it).second.elcomm.substr(0,128).c_str()); 416 416 break; 417 case 'S':417 case MuTyV::MTVString : 418 418 sprintf(buff, "%s = %s (string) %s\n", (*it).first.substr(0,64).c_str(), 419 (*it).second.elval.strv-> c_str(), (*it).second.elcomm.substr(0,128).c_str());419 (*it).second.elval.strv->substr(0,800).c_str(), (*it).second.elcomm.substr(0,128).c_str()); 420 420 break; 421 421 default : … … 469 469 void ObjFileIO<DVList>::WriteSelf(POutPersist& s) const 470 470 { 471 char buf[ 512];471 char buf[1024]; 472 472 string sfw; 473 474 473 int lc = dobj->Comment().length(); 475 if (lc > 0) { 476 sprintf(buf,"Comment: ( %6d ) ", lc); 477 sfw = buf; s.PutStr(sfw); 478 s.PutStr(dobj->Comment()); 479 } 480 sfw = "----Variable-List---------------"; s.PutStr(sfw); 474 // itab - 0 : Version, 1 : NVar, 2 : Comment length, 3 reserved 475 uint_4 itab[4]; 476 itab[0] = 2; // Version number = 2 477 itab[1] = dobj->Size(); 478 itab[2] = lc; 479 itab[3] = 0; 480 s.Put(itab, 4); 481 482 if (lc > 0) s.PutStr(dobj->Comment()); 483 sfw = "\n----Variable-List---------------\n"; 484 s.PutStr(sfw); 485 481 486 DVList::ValList::const_iterator it; 482 487 for(it = dobj->Begin(); it != dobj->End(); it++) { 483 switch ((*it).second.elval. typ) {484 case 'I':485 sprintf(buf,"I %s %ld ", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval.iv) );488 switch ((*it).second.elval.Type()) { 489 case MuTyV::MTVInteger : 490 sprintf(buf,"I %s %ld\n", (*it).first.substr(0,64).c_str(), (long)((*it).second.elval.iv) ); 486 491 sfw = buf; s.PutStr(sfw); 487 492 break; 488 case 'D':489 sprintf(buf," D %s %.20g", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv );493 case MuTyV::MTVFloat : 494 sprintf(buf,"F %s %.20g\n", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv ); 490 495 sfw = buf; s.PutStr(sfw); 491 496 break; 492 case 'Z':493 sprintf(buf,"Z %s %.20g %.20g ", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv,497 case MuTyV::MTVComplex : 498 sprintf(buf,"Z %s %.20g %.20g\n", (*it).first.substr(0,64).c_str(), (*it).second.elval.dv, 494 499 (*it).second.elval.dv_im); 495 500 sfw = buf; s.PutStr(sfw); 496 501 break; 497 case 'S':498 sprintf(buf,"S %s %s ", (*it).first.substr(0,64).c_str(), (*it).second.elval.strv->c_str() );502 case MuTyV::MTVString : 503 sprintf(buf,"S %s %s\n", (*it).first.substr(0,64).c_str(), (*it).second.elval.strv->substr(0,960).c_str() ); 499 504 sfw = buf; s.PutStr(sfw); 500 505 break; … … 515 520 void ObjFileIO<DVList>::ReadSelf(PInPersist& s) 516 521 { 517 char buf[ 512];522 char buf[1024]; 518 523 string sfr; 519 524 int_8 j,iv,k; … … 524 529 dobj->Clear(); 525 530 526 s.GetStr(sfr); // Pour lire les "------- " 527 if (sfr[0] != '-') { // Il y a un champ commentaire a lire 531 // itab - 0 : Version, 1 : NVar, 2 : Comment length, 3 reserved 532 uint_4 itab[4]; 533 s.Get(itab, 4); 534 if (itab[2] > 0) { // Il y a un champ commentaire a lire 528 535 s.GetStr(sfr); 529 536 dobj->Comment() = sfr; 530 537 } 538 539 s.GetStr(sfr); // Pour lire les "------- " 531 540 532 541 string key=""; 533 542 while(ok) { 534 543 s.GetStr(sfr); 535 strncpy(buf, sfr.c_str(), 512); 536 buf[511] = '\0'; 544 strncpy(buf, sfr.c_str(), 1024); 545 buf[1023] = '\0'; 546 j = strlen(buf)-1; 547 if ( (j >= 0) && (buf[j] == '\n') ) buf[j] = '\0'; 537 548 if (strncmp(buf,"ZZZZZ",5) == 0) { ok=false; break; } 538 549 if (buf[0] == '#') { … … 548 559 dobj->SetI(key, iv); 549 560 break; 550 case ' D' :561 case 'F' : 551 562 dv = atof(buf+j+1); 552 563 key = buf+2; … … 562 573 dobj->SetZ(key, z); 563 574 break; 564 case 'S' :575 case 'S' : 565 576 key = buf+2; 566 577 dobj->SetS(key, buf+j+1); … … 569 580 break; 570 581 } 571 } 582 } 583 if (dobj->Size() != itab[1]) // Probleme !!! 584 throw FileFormatExc("ObjFileIO<DVList>::ReadSelf() Error in Nb. Variables !"); 572 585 } 573 586 -
trunk/SophyaLib/BaseTools/dvlist.h
r1157 r1310 33 33 void Clear(); 34 34 DVList& Merge(const DVList&); 35 36 //! Returns the number of elements (variables) in DVList object 37 inline int Size() { return(mvlist.size()); } 38 //! Returns the number of elements (variables) in DVList object 39 inline int NVar() { return(mvlist.size()); } 35 40 36 41 int_8 GetI(string const& key, int_8 def=-1) const; -
trunk/SophyaLib/BaseTools/mutyv.cc
r1225 r1310 38 38 { 39 39 typ = a.typ; iv = a.iv; dv = a.dv; dv_im = a.dv_im; 40 if (typ == 'S') strv = new string(*(a.strv));40 if (typ == MTVString) strv = new string(*(a.strv)); 41 41 else strv = NULL; 42 42 } … … 51 51 MuTyV::MuTyV(char const* s) 52 52 { 53 typ = 'S';53 typ = MTVString; 54 54 strv = new string(s); 55 55 mutyv_decodestr(s, dv, dv_im); … … 60 60 MuTyV::MuTyV(string const& s) 61 61 { 62 typ = 'S';62 typ = MTVString; 63 63 strv = new string(s); 64 64 mutyv_decodestr(s.c_str(), dv, dv_im); … … 70 70 { 71 71 typ = a.typ; iv = a.iv; dv = a.dv; dv_im = a.dv_im; 72 if (typ == 'S') {72 if (typ == MTVString) { 73 73 if (strv) *strv = *(a.strv); 74 74 else strv = new string(*(a.strv)); … … 80 80 char * MuTyV::operator= (char* s) 81 81 { 82 typ = 'S';82 typ = MTVString; 83 83 if (strv) *strv = s; 84 84 else strv = new string(s); … … 91 91 string & MuTyV::operator= (string& s) 92 92 { 93 typ = 'S';93 typ = MTVString; 94 94 if (strv) *strv = s; 95 95 else strv = new string(s); … … 102 102 MuTyV::operator string() const 103 103 { 104 if (typ == 'S') return(*strv);104 if (typ == MTVString) return(*strv); 105 105 else { 106 106 char buff[96]; 107 if (typ == 'I') sprintf(buff,"%ld", (long)iv);108 else if (typ == 'D') sprintf(buff,"%.20g", dv);109 else if (typ == 'Z') sprintf(buff,"(%.20g , %.20g)", dv, dv_im);107 if (typ == MTVInteger) sprintf(buff,"%ld", (long)iv); 108 else if (typ == MTVFloat) sprintf(buff,"%.20g", dv); 109 else if (typ == MTVComplex) sprintf(buff,"(%.20g , %.20g)", dv, dv_im); 110 110 else buff[0] = '\0'; 111 111 return(string(buff)); -
trunk/SophyaLib/BaseTools/mutyv.h
r1290 r1310 20 20 public: 21 21 22 inline MuTyV() { typ = 'I'; iv = 0; dv = dv_im = 0.; strv = NULL; } 22 enum MTVType { 23 MTVInteger, 24 MTVFloat, 25 MTVComplex, 26 MTVString 27 }; 28 29 inline MuTyV() { typ = MTVInteger; iv = 0; dv = dv_im = 0.; strv = NULL; } 23 30 MuTyV(MuTyV const & a); 24 inline MuTyV(uint_2 i) { typ = 'I'; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; }25 inline MuTyV(int_4 i) { typ = 'I'; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; }26 inline MuTyV(int_8 i) { typ = 'I'; iv = i; dv = (r_8)i; dv_im = 0.; strv = NULL; }27 inline MuTyV(r_4 f) { typ = 'D'; dv = (r_8)f; iv = (int_8)f; dv_im = 0.; strv = NULL; }28 inline MuTyV(r_8 d) { typ = 'D'; dv = d; iv = (int_8)d; dv_im = 0.; strv = NULL; }29 inline MuTyV(complex<r_4> z) { typ = 'Z'; dv = (r_8)z.real(); dv_im = z.imag();31 inline MuTyV(uint_2 i) { typ = MTVInteger; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; } 32 inline MuTyV(int_4 i) { typ = MTVInteger; iv = (int_8)i; dv = (r_8)i; dv_im = 0.; strv = NULL; } 33 inline MuTyV(int_8 i) { typ = MTVInteger; iv = i; dv = (r_8)i; dv_im = 0.; strv = NULL; } 34 inline MuTyV(r_4 f) { typ = MTVFloat; dv = (r_8)f; iv = (int_8)f; dv_im = 0.; strv = NULL; } 35 inline MuTyV(r_8 d) { typ = MTVFloat; dv = d; iv = (int_8)d; dv_im = 0.; strv = NULL; } 36 inline MuTyV(complex<r_4> z) { typ = MTVComplex; dv = (r_8)z.real(); dv_im = z.imag(); 30 37 iv = (int_8)dv; strv = NULL; } 31 inline MuTyV(complex<r_8> z) { typ = 'Z'; dv = z.real(); dv_im = z.imag();38 inline MuTyV(complex<r_8> z) { typ = MTVComplex; dv = z.real(); dv_im = z.imag(); 32 39 iv = (int_8)dv; strv = NULL; } 33 40 … … 37 44 ~MuTyV(); 38 45 39 inline charType() const { return typ; }46 inline MTVType Type() const { return typ; } 40 47 41 48 MuTyV & operator= (MuTyV const & a); 42 inline uint_2 operator= (uint_2 v) { typ = 'I'; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); }43 inline int_4 operator= (int_4 v) { typ = 'I'; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); }44 inline int_8 operator= (int_8 v) { typ = 'I'; iv = v; dv = (r_8)v; dv_im = 0.; return(v); }45 inline r_4 operator= (r_4 v) { typ = 'D'; dv = (r_8)v; iv = (int_8)v; dv_im = 0.; return(v); }46 inline r_8 operator= (r_8 v) { typ = 'D'; dv = v; iv = (int_8)v; dv_im = 0.; return(v); }47 inline complex<r_4> operator= (complex<r_4> v) { typ = 'Z'; dv = (r_8)v.real(); dv_im = v.imag();49 inline uint_2 operator= (uint_2 v) { typ = MTVInteger; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); } 50 inline int_4 operator= (int_4 v) { typ = MTVInteger; iv = (int_8)v; dv = (r_8)v; dv_im = 0.; return(v); } 51 inline int_8 operator= (int_8 v) { typ = MTVInteger; iv = v; dv = (r_8)v; dv_im = 0.; return(v); } 52 inline r_4 operator= (r_4 v) { typ = MTVFloat; dv = (r_8)v; iv = (int_8)v; dv_im = 0.; return(v); } 53 inline r_8 operator= (r_8 v) { typ = MTVFloat; dv = v; iv = (int_8)v; dv_im = 0.; return(v); } 54 inline complex<r_4> operator= (complex<r_4> v) { typ = MTVComplex; dv = (r_8)v.real(); dv_im = v.imag(); 48 55 iv = (int_8)dv; return(v); } 49 inline complex<r_8> operator= (complex<r_8> v) { typ = 'Z'; dv = (r_8)v.real(); dv_im = v.imag();56 inline complex<r_8> operator= (complex<r_8> v) { typ = MTVComplex; dv = (r_8)v.real(); dv_im = v.imag(); 50 57 iv = (int_8)dv; return(v); } 51 58 char* operator= (char* s); … … 66 73 r_8 dv_im; /* for holding imaginary part of a complex */ 67 74 string * strv; 68 chartyp;75 MTVType typ; 69 76 70 77 }; -
trunk/SophyaLib/BaseTools/sversion.h
r1283 r1310 3 3 4 4 #define SOPHYA_VERSION 0.9 5 #define SOPHYA_REVISION 9 65 #define SOPHYA_REVISION 97 6 6 #define SOPHYA_TAG "V_Oct2000" 7 7
Note:
See TracChangeset
for help on using the changeset viewer.