Changeset 1158 for XIOS/dev/dev_olga/src/duration.cpp
- Timestamp:
- 06/06/17 17:58:16 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_olga/src/duration.cpp
r612 r1158 26 26 } 27 27 28 /*! 29 This operation may not serve much, it's here because of the need of operator== from generic class CType<T> 30 */ 31 bool CDuration::operator==(const CDuration& duration) 32 { 33 return (year == duration.year && month == duration.month && day == duration.day && 34 hour == duration.hour && minute == duration.minute && second == duration.second && timestep == duration.timestep); 35 } 36 28 37 StdOStream& operator<<(StdOStream& out, const CDuration& duration) 29 38 { … … 38 47 char c = '/'; 39 48 bool invalidUnit = false; 49 CDuration sentinel = NoneDu; 50 51 #define setDuration(unit, value) \ 52 { \ 53 if (sentinel.unit) \ 54 ERROR("StdIStream& operator>>(StdIStream& in , CDuration& duration)", \ 55 << "Bad duration format: " #unit " has already been set."); \ 56 \ 57 duration.unit = value; \ 58 sentinel.unit = 1.0; \ 59 } 40 60 41 61 do … … 48 68 switch (c) 49 69 { 50 case 'y': duration.year = v;break;51 case 'd': duration.day = v;break;52 case 'h': duration.hour = v;break;53 case 's': duration.second = v;break;70 case 'y': setDuration(year, v) break; 71 case 'd': setDuration(day, v) break; 72 case 'h': setDuration(hour, v) break; 73 case 's': setDuration(second, v) break; 54 74 case 'm': 55 75 { 56 76 in >> c; 57 if (c == 'i') duration.minute = v;58 else if (c == 'o') duration.month = v;77 if (c == 'i') setDuration(minute, v) 78 else if (c == 'o') setDuration(month, v) 59 79 else invalidUnit = true; 60 80 break; … … 63 83 { 64 84 in >> c; 65 if (c == 's') duration.timestep = v;85 if (c == 's') setDuration(timestep, v) 66 86 else invalidUnit = true; 67 87 break; … … 76 96 << "Bad duration format: invalid unit, unexpected '" << c << "' character."); 77 97 } while (in.peek() != EOF); // check whether there is a next character to read 98 99 #undef setDuration 78 100 79 101 return in;
Note: See TracChangeset
for help on using the changeset viewer.