Changeset 119 for XMLIO_V2/dev/dev_rv/src/XMLIO/duration.hpp
- Timestamp:
- 07/20/10 16:20:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/duration.hpp
r118 r119 10 10 typedef struct _duration 11 11 { 12 friend std::ostream& operator<<(std::ostream& out, const struct _duration& d) 13 { 14 out << d.year << "y. " << d.month << "mo. " << d.day << "d. " 15 << d.hour << "h. " << d.minute << "min. " << d.second << "sec. "; 16 return (out); 17 } 12 public : 18 13 19 struct _duration& resolve(const AbstractCalendar&); 14 friend std::ostream& operator<<(std::ostream& out, const struct _duration& d) 15 { 16 bool testValue = true; 17 if(d.year != 0.0) { testValue = false; out << d.year << "y " ; } 18 if(d.month != 0.0) { testValue = false; out << d.month << "mo "; } 19 if(d.day != 0.0) { testValue = false; out << d.day << "d " ; } 20 if(d.hour != 0.0) { testValue = false; out << d.hour << "h " ; } 21 if(d.minute != 0.0) { testValue = false; out << d.minute << "mi "; } 22 if(d.second != 0.0 || testValue) { out << d.second << "s " ; } 23 return (out); 24 } 20 25 21 double year, month, day, hour, minute, second; 26 friend std::istream& operator>>(std::istream& in, struct _duration& d) 27 { 28 double v = 1.0; 29 char c = '/'; 30 while (!in.eof()) 31 { 32 in >> v >> c; 33 switch (c) 34 { 35 case 'y': d.year = v; continue; 36 case 'd': d.day = v; continue; 37 case 'h': d.hour = v; continue; 38 case 's': d.second = v; continue; 39 case 'm': 40 in >> c; 41 if (c == 'i') d.minute = v; 42 else if(c == 'o') d.month = v; 43 else 44 { 45 string valc("m"); valc.append(1, c); 46 WARNING("La chaine \""+valc+"\" ne permet pas de définir une unité de durée."); 47 continue; 48 } 49 continue; 50 default: 51 string valc; valc.append(1, c); 52 WARNING("La chaine \""+valc+"\" ne permet pas de définir une unité de durée."); 53 continue; 54 } 55 } 56 return (in); 57 } 58 59 static struct _duration FromString(const string& str) 60 { 61 struct _duration dr = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; 62 std::istringstream iss(str); 63 iss >> dr; return dr; 64 } 65 66 struct _duration& resolve(const AbstractCalendar&); 67 68 double year, month, day, hour, minute, second; 22 69 23 70 } Duration; … … 26 73 static const Duration Year = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 27 74 Month = {0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, 75 Week = {0.0, 0.0, 7.0, 0.0, 0.0, 0.0}, 28 76 Day = {0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, 29 77 Hour = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0},
Note: See TracChangeset
for help on using the changeset viewer.