Changeset 2830 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Nov 8, 2005, 5:13:56 PM (20 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/dvlist.cc
r2826 r2830 496 496 void ObjFileIO<DVList>::WriteSelf(POutPersist& s) const 497 497 { 498 if (dobj == NULL) 499 throw NullPtrError("ObjFileIO<DVList>::WriteSelf() dobj=NULL"); 500 498 501 char buf[1024]; 499 502 string sfw; -
trunk/SophyaLib/BaseTools/sophyainit.cc
r2774 r2830 81 81 DObjRegister(FIO_NDataBlock< complex<r_8> >, NDataBlock< complex<r_8> >); 82 82 83 // Enregistrement des handlers PPF pour les TimeStamp 84 PPRegister(ObjFileIO<TimeStamp>); 85 DObjRegister(ObjFileIO<TimeStamp>, TimeStamp); 86 83 87 // Enregistrement des handlers PPF pour les DVList 84 88 PPRegister(ObjFileIO<DVList>); … … 133 137 DObjRegister(PPFWrapperSTLVector< string >, std::vector<string>); 134 138 139 PPRegister(PPFWrapperSTLVector< TimeStamp >); 140 DObjRegister(PPFWrapperSTLVector< TimeStamp >, std::vector<TimeStamp>); 141 135 142 136 143 #if (!defined(__GNUG__) && !defined(__MWERKS__) && !defined(HPUX)) -
trunk/SophyaLib/BaseTools/timestamp.cc
r2826 r2830 74 74 } 75 75 76 TimeStamp::TimeStamp(string & date, string& hour)76 TimeStamp::TimeStamp(string const & date, string const & hour) 77 77 { 78 78 SetDate(date); … … 86 86 } 87 87 88 TimeStamp::TimeStamp(string& datim) 89 { 90 Set(datim); 91 } 92 93 TimeStamp::TimeStamp(const char* datim) 94 { 95 Set(datim); 96 } 88 97 89 98 void TimeStamp::Set(TimeStamp const & ts) … … 96 105 { 97 106 if (days >= 0.) { 98 mDays = trunc(days);107 mDays = (int_8)trunc(days); 99 108 mSeconds = (days-trunc(days))*86400.; 100 109 } 101 110 else { 102 111 if ( (trunc(days)-days) > 0.) { 103 mDays = trunc(days)-1;112 mDays = (int_8)trunc(days)-1; 104 113 mSeconds = (days-mDays)*86400.; 105 114 } 106 115 else { 107 mDays = trunc(days);116 mDays = (int_8)trunc(days); 108 117 mSeconds = 0.; 109 118 } … … 116 125 throw ParmError("TimeStamp::Set(int_8, r_8) seconds<0 or seconds>86400."); 117 126 mDays = days; 118 } 127 mSeconds = seconds; 128 } 129 130 void TimeStamp::Set(const char * datim) 131 { 132 int year, month, day; 133 int hour, min; 134 double sec; 135 sscanf(datim,"%d-%d-%dT%d:%d:%lf", &year, &month, &day, 136 &hour, &min, &sec); 137 SetDate(year, month, day); 138 SetHour(hour, min, sec); 139 } 140 119 141 120 142 void TimeStamp::SetNow() … … 193 215 { 194 216 double seconds = mSeconds; 195 hour = trunc(seconds/3600.);217 hour = (int)trunc(seconds/3600.); 196 218 seconds -= hour*3600; 197 min = trunc(seconds/60.);219 min = (int)trunc(seconds/60.); 198 220 while (min >= 60) { hour++; min -= 60; } 199 221 sec = seconds-min*60; … … 207 229 208 230 /*! 209 \param fgday : if false, ignore the date (dd/mm/yy) part 210 \param fghour : if false, ignore the hour (hh:mm:ss) part 231 \param fmt : String format for the date 232 - FmtPackedDateTime : YYYY-MM-DDThh:mm:ss.s 233 - FmtDateOnly : dd/mm/yyyy 234 - FmtTimeOnly : hh:mm:ss.s 235 - FmtDateTime : dd/mm/yyyy hh:mm:ss.s UT 211 236 */ 212 string TimeStamp::ToString( bool fgday, bool fghour) const237 string TimeStamp::ToString(StrFmt fmt) const 213 238 { 214 239 char buff[128]; … … 218 243 GetDate(aa, mm, jj); 219 244 GetHour(hh, min, sec); 220 if (!fghour) 221 sprintf(buff,"%02d/%02d/%02d ", jj,mm,aa); 222 else if (!fgday) 223 sprintf(buff,"%02d:%02d:%02.3f ", hh,min,sec); 224 else 225 sprintf(buff,"%02d/%02d/%02d %02d:%02d:%02.1f GMT", jj,mm,aa,hh,min,sec); 245 if (fmt == FmtPackedDateTime) 246 sprintf(buff,"%04d-%02d-%02dT%02d:%02d:%02.1f", aa,mm,jj, hh,min,sec); 247 else { 248 if (fmt == FmtDateOnly) 249 sprintf(buff,"%02d/%02d/%04d ", jj,mm,aa); 250 else if (fmt == FmtTimeOnly) 251 sprintf(buff,"%02d:%02d:%02.3f ", hh,min,sec); 252 else 253 sprintf(buff,"%02d/%02d/%04d %02d:%02d:%02.1f UT", jj,mm,aa,hh,min,sec); 254 } 226 255 return buff; 227 256 } 228 257 229 258 /*! 230 \param fgday : if false, ignore the date (dd/mm/yy) part 231 \param fghour : if false, ignore the hour (hh:mm:ss) part 259 \param fmt : String format for the date 260 - FmtPackedDateTime : YYYY-MM-DDThh:mm:ss.s 261 - FmtDateOnly : dd/mm/yyyy 262 - FmtTimeOnly : hh:mm:ss.s 263 - FmtDateTime : dd/mm/yyyy hh:mm:ss.s UT 232 264 */ 233 void TimeStamp::Print(ostream& os, bool fgday, bool fghour) const234 { 235 os << " " << ToString(f gday, fghour) << " ";265 void TimeStamp::Print(ostream& os, StrFmt fmt) const 266 { 267 os << " " << ToString(fmt) << " "; 236 268 } 237 269 … … 280 312 return t; 281 313 } 314 315 //---------------------------------------------------------- 316 // Classe pour la gestion de persistance 317 // ObjFileIO<TimeStamp> 318 //---------------------------------------------------------- 319 320 /* --Methode-- */ 321 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 322 void ObjFileIO<TimeStamp>::WriteSelf(POutPersist& s) const 323 { 324 if (dobj == NULL) 325 throw NullPtrError("ObjFileIO<TimeStamp>::WriteSelf() dobj=NULL"); 326 int_4 ver; 327 ver = 1; 328 s.Put(ver); // Lecture numero de version PPF 329 s.Put(dobj->DaysPart()); 330 s.Put(dobj->SecondsPart()); 331 } 332 333 /* --Methode-- */ 334 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 335 void ObjFileIO<TimeStamp>::ReadSelf(PInPersist& s) 336 { 337 int_4 ver; 338 s.Get(ver); // Lecture numero de version PPF 339 r_8 seconds; 340 int_8 days; 341 s.Get(days); 342 s.Get(seconds); 343 344 if (dobj == NULL) dobj = new TimeStamp(days, seconds); 345 else dobj->Set(days, seconds); 346 } 347 348 349 #ifdef __CXX_PRAGMA_TEMPLATES__ 350 #pragma define_template ObjFileIO<TimeStamp> 351 #endif 352 353 #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) 354 template class ObjFileIO<TimeStamp>; 355 #endif -
trunk/SophyaLib/BaseTools/timestamp.h
r2826 r2830 11 11 12 12 #include "machdefs.h" 13 #include "objfio.h" 13 14 #include <string> 14 15 #include <iostream> … … 17 18 18 19 //! Class representing date and time 19 class TimeStamp {20 class TimeStamp : public AnyDataObj { 20 21 public: 21 22 /* Pour utilisation ulterieure … … 26 27 enum Month {month_January=1, month_February, month_March, month_April, month_May, month_June, month_July, 27 28 month_August, month_September, month_October, month_November, month_December}; 29 30 enum StrFmt { FmtPackedDateTime , FmtDateOnly, FmtTimeOnly, FmtDateTime }; 28 31 29 32 //! Default Constructor : current date and time (GMT) … … 36 39 //! Constructor with specification of day,month,year,hour,minutes,seconds 37 40 TimeStamp(int year, int month, int day, int hour, int min, double sec); 38 //! Constructor with specification of date & time in the format YYYY/MM/DD hh:mm:ss 39 TimeStamp(string& date, string& hour); 41 //! Constructor with specification of date & time in the format YYYY/MM/DD hh:mm:ss 42 TimeStamp(string const & date, string const & hour); 43 //! Constructor with specification of date & time in the format YYYY/MM/DD hh:mm:ss 40 44 TimeStamp(const char* date, const char* hour); 45 //! Constructor with specification of date & time in the format YYYY-MM-DDThh:mm:ss 46 TimeStamp(string& datim); 47 //! Constructor with specification of date & time in the format YYYY-MM-DDThh:mm:ss 48 TimeStamp(const char* datim); 41 49 42 50 //! Set the value of the time stamp copying from "ts" … … 46 54 //! Sets the value of the time stamp from the number of days and seconds 47 55 void Set(int_8 days, r_8 seconds); 56 //! Sets the value of the time stamp from a string in the format YYYY-MM-DDThh:mm:ss 57 void Set(const char * datim); 58 //! Sets the value of the time stamp from a string in the format YYYY-MM-DDThh:mm:ss 59 inline void Set(string const & datim) { Set(datim.c_str()); } 48 60 //! initialize with current date and time (GMT) 49 61 void SetNow(); … … 78 90 79 91 //! Return the timestamp in string format 80 string ToString( bool fgday=true, bool fghour=true) const;92 string ToString(StrFmt fmt=FmtPackedDateTime) const; 81 93 82 94 //! Return the integral number of days since 0 Jan 1901 … … 86 98 87 99 //! Prints the date/time in string format on \b cout 88 inline void Print( bool fgday=true, bool fghour=true) const89 { Print(cout, f gday, fghour); }100 inline void Print(StrFmt fmt=FmtDateTime) const 101 { Print(cout, fmt); } 90 102 //! Prints the date/time in string format on stream \b os 91 virtual void Print(ostream& os, bool fgday=true, bool fghour=true) const;103 virtual void Print(ostream& os, StrFmt fmt=FmtDateTime) const; 92 104 93 105 //! Number of days in a given month … … 108 120 { ts.Print(s); return(s); } 109 121 122 /*! Writes the object in the POutPersist stream \b os */ 123 inline POutPersist& operator << (POutPersist& os, TimeStamp & obj) 124 { ObjFileIO<TimeStamp> fio(&obj); fio.Write(os); return(os); } 125 /*! Reads the object from the PInPersist stream \b is */ 126 inline PInPersist& operator >> (PInPersist& is, TimeStamp & obj) 127 { ObjFileIO<TimeStamp> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); } 128 110 129 } // namespace SOPHYA 111 130
Note:
See TracChangeset
for help on using the changeset viewer.