Changeset 718 in Sophya for trunk/SophyaLib/NTools/dvlist.h
- Timestamp:
- Feb 6, 2000, 4:05:44 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/dvlist.h
r552 r718 23 23 public: 24 24 union { 25 int_ 4iv;26 doubledv;25 int_8 iv; 26 r_8 dv; 27 27 char strv[31]; 28 28 } mtv; … … 32 32 33 33 inline MuTyV() { typ = 'I'; mtv.iv = 0; mtv.dv = 0.; mtv.strv[0] ='\0'; } 34 inline MuTyV(int_4 i) { typ = 'I'; mtv.iv = i; mtv.dv = 0.; mtv.strv[0] ='\0'; } 35 inline MuTyV(float f) { typ = 'D'; mtv.dv = (double)f; mtv.iv = 0; mtv.strv[0] ='\0'; } 36 inline MuTyV(double d) { typ = 'D'; mtv.dv = d; mtv.iv = 0; mtv.strv[0] ='\0'; } 34 inline MuTyV(int_4 i) { typ = 'I'; mtv.iv = (int_8)i; mtv.dv = 0.; mtv.strv[0] ='\0'; } 35 inline MuTyV(int_8 i) { typ = 'I'; mtv.iv = i; mtv.dv = 0.; mtv.strv[0] ='\0'; } 36 inline MuTyV(r_4 f) { typ = 'D'; mtv.dv = (r_8)f; mtv.iv = 0; mtv.strv[0] ='\0'; } 37 inline MuTyV(r_8 d) { typ = 'D'; mtv.dv = d; mtv.iv = 0; mtv.strv[0] ='\0'; } 37 38 inline MuTyV(char const* s) { typ = 'S'; strncpy(mtv.strv, s, 31); mtv.strv[30] = '\0'; } 38 39 inline MuTyV(string const& s) { typ = 'S'; strncpy(mtv.strv, s.c_str(), 31); mtv.strv[30] = '\0'; } 39 inline int_4 operator= (int_4 v) { typ = 'I'; mtv.iv = v; return(v); } 40 inline float operator= (float v) { typ = 'D'; mtv.dv = (double)v; return(v); } 41 inline double operator= (double v) { typ = 'D'; mtv.dv = v; return(v); } 40 inline int_4 operator= (int_4 v) { typ = 'I'; mtv.iv = (int_8)v; return(v); } 41 inline int_8 operator= (int_8 v) { typ = 'I'; mtv.iv = v; return(v); } 42 inline r_4 operator= (r_4 v) { typ = 'D'; mtv.dv = (r_8)v; return(v); } 43 inline r_8 operator= (r_8 v) { typ = 'D'; mtv.dv = v; return(v); } 42 44 inline char* operator= (char* s) { typ = 'S'; strncpy(mtv.strv, s, 31); 43 45 mtv.strv[30] = '\0'; return(s); } … … 45 47 mtv.strv[30] = '\0'; return(s); } 46 48 47 inline operator int_4() { if (typ == 'I') return( mtv.iv);49 inline operator int_4() { if (typ == 'I') return((int_4)mtv.iv); 48 50 else if (typ == 'D') return((int_4)mtv.dv); 49 51 else return(atol(mtv.strv)); } 50 inline operator float() { if (typ == 'I') return((float)mtv.iv); 51 else if (typ == 'D') return((float)mtv.dv); 52 else return((float)atof(mtv.strv)); } 53 inline operator double() { if (typ == 'I') return((double)mtv.iv); 52 inline operator int_8() { if (typ == 'I') return((int_8)mtv.iv); 53 else if (typ == 'D') return((int_8)mtv.dv); 54 else return(atol(mtv.strv)); } 55 inline operator r_4() { if (typ == 'I') return((r_4)mtv.iv); 56 else if (typ == 'D') return((r_4)mtv.dv); 57 else return((r_4)atof(mtv.strv)); } 58 inline operator r_8() { if (typ == 'I') return((r_8)mtv.iv); 54 59 else if (typ == 'D') return(mtv.dv); 55 60 else return(atof(mtv.strv)); } … … 78 83 DVList& Merge(const DVList&); 79 84 80 int_ 4 GetI(string const& key, int_4def=-1);81 double GetD(string const& key, doubledef=-9.e19);85 int_8 GetI(string const& key, int_8 def=-1); 86 r_8 GetD(string const& key, r_8 def=-9.e19); 82 87 string GetS(string const& key, char* def=""); 88 string GetComment(string const& key); 83 89 84 void SetI(string const& key, int_ 4val);85 void SetD(string const& key, doubleval);90 void SetI(string const& key, int_8 val); 91 void SetD(string const& key, r_8 val); 86 92 void SetS(string const& key, char const* val); 87 93 void SetS(string const& key, string val); 94 void SetComment(string const& key, string const& comm); 88 95 89 96 MuTyV& Get(string const& key); … … 95 102 virtual void Print(ostream& os) const; 96 103 97 typedef map<string, MuTyV, less<string> > ValList; 104 // Chaque element dans un DVList est constitue desormais d'un MuTyV 105 // et d'une chaine de caracteres (commentaire) regroupe dans la structure 106 // dvlElement. Ces elements sont associes aux noms de variables dans un 107 // map<...> ValList. Reza 02/2000 108 109 struct dvlElement {MuTyV elval; string elcomm; } ; 110 typedef map<string, dvlElement, less<string> > ValList; 98 111 inline ValList::const_iterator Begin() { return(mvlist.begin()); } 99 112 inline ValList::const_iterator End() { return(mvlist.end()); } 100 113 101 // int_4 ClassId() const { return classId; }102 // static PPersist* Create() { return new DVList;}103 104 // virtual void WriteSelf(POutPersist&) const;105 // virtual void ReadSelf(PInPersist&);106 114 107 115 private:
Note:
See TracChangeset
for help on using the changeset viewer.