Changeset 612 for XIOS/branchs/xios-1.0/src/duration.cpp
- Timestamp:
- 06/10/15 15:11:22 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/branchs/xios-1.0/src/duration.cpp
r579 r612 27 27 StdOStream & operator<<(StdOStream & out, const CDuration & duration) 28 28 { 29 StdOStringStream sout; 30 bool testValue = true; 31 if(duration.year != 0.0) { testValue = false; sout << duration.year << "y "; } 32 if(duration.month != 0.0) { testValue = false; sout << duration.month << "mo "; } 33 if(duration.day != 0.0) { testValue = false; sout << duration.day << "d "; } 34 if(duration.hour != 0.0) { testValue = false; sout << duration.hour << "h "; } 35 if(duration.minute != 0.0) { testValue = false; sout << duration.minute << "mi "; } 36 if(duration.second != 0.0) { testValue = false; sout << duration.second << "s "; } 37 if(duration.timestep != 0.0 || testValue) { sout << duration.timestep << "ts "; } 38 39 // << suppression de l'espace en fin de chaîne. 40 out << (sout.str().substr(0, sout.str().size()-1)); 29 out << duration.toString(); 41 30 return out; 42 31 } … … 145 134 StdString CDuration::toString(void) const 146 135 { 147 const CDuration & own = *this; 148 StdOStringStream oss; oss << own; 149 return oss.str(); 136 StdOStringStream sout; 137 bool forceOutput = true; 138 139 if (year != 0.0) { forceOutput = false; sout << year << "y "; } 140 if (month != 0.0) { forceOutput = false; sout << month << "mo "; } 141 if (day != 0.0) { forceOutput = false; sout << day << "d "; } 142 if (hour != 0.0) { forceOutput = false; sout << hour << "h "; } 143 if (minute != 0.0) { forceOutput = false; sout << minute << "mi "; } 144 if (second != 0.0) { forceOutput = false; sout << second << "s "; } 145 if (timestep != 0.0 || forceOutput) { sout << timestep << "ts "; } 146 147 // Remove the trailing space 148 StdString strOut = sout.str(); 149 return strOut.erase(strOut.size() - 1); 150 } 151 152 StdString CDuration::toStringUDUnits(void) const 153 { 154 if (timestep != 0.0) 155 ERROR("StdString CDuration::toStringUDUnits(void) const", 156 "Impossible to convert a duration to string using UDUnits when a timestep is set."); 157 158 StdOStringStream sout; 159 bool forceOutput = true; 160 161 if (year != 0.0) { forceOutput = false; sout << year << " yr "; } 162 if (month != 0.0) { forceOutput = false; sout << month << " month "; } 163 if (day != 0.0) { forceOutput = false; sout << day << " d "; } 164 if (hour != 0.0) { forceOutput = false; sout << hour << " h "; } 165 if (minute != 0.0) { forceOutput = false; sout << minute << " min "; } 166 if (second != 0.0 || forceOutput) { sout << second << " s "; } 167 168 // Remove the trailing space 169 StdString strOut = sout.str(); 170 return strOut.erase(strOut.size() - 1); 150 171 } 151 172
Note: See TracChangeset
for help on using the changeset viewer.