00001
00002 #ifndef FRAMEDIR_HH
00003 #define FRAMEDIR_HH
00004
00005
00006
00007
00008 #include <map>
00009 #include <iosfwd>
00010 #include <iterator>
00011 #include <string>
00012 #include "PConfig.h"
00013 #include "Time.hh"
00014 #include "Interval.hh"
00015 #include "fferrors.hh"
00016
00026 struct ffData {
00027 public:
00030 typedef Time::ulong_t gps_t;
00031
00034 typedef unsigned long count_t;
00035
00039 ffData(void);
00040
00050 ffData(const char* File, const Time& time,
00051 Interval Dt=Interval(1.0), bool DataOK=true);
00052
00062 ffData(const char* Prefix, const char* Suffix, const Time& time,
00063 Interval Dt=Interval(1.0));
00064
00069 Interval getDt(void) const;
00070
00075 const char* getPrefix(void) const;
00076
00081 const char* getSuffix(void) const;
00082
00092 std::string getFile(count_t N = 0) const;
00093
00099 bool advance(int N);
00100
00105 Time getStartTime(void) const;
00106
00111 Time getEndTime(void) const;
00112
00117 bool isFollowed(void) const;
00118
00125 bool isValid(void) const;
00126
00131 gps_t getStartGPS(void) const;
00132
00137 gps_t getEndGPS(void) const;
00138
00139 protected:
00142 std::string mFilePrefix;
00143
00146 std::string mFileSuffix;
00147
00150 Time mStartGPS;
00151
00154 Interval mDt;
00155
00158 bool mNamingOK;
00159
00163 bool mDataOK;
00164 };
00165
00166 inline
00167 ffData::ffData(const char* File, const Time& time,
00168 Interval Dt, bool DataOK)
00169 : mFilePrefix(File), mStartGPS(time), mDt(Dt), mNamingOK(false),
00170 mDataOK(DataOK)
00171 {}
00172
00173 inline
00174 ffData::ffData(const char* Prefix, const char* Suffix, const Time& time,
00175 Interval Dt)
00176 : mFilePrefix(Prefix), mFileSuffix(Suffix), mStartGPS(time),
00177 mDt(Dt), mNamingOK(true), mDataOK(true)
00178 {}
00179
00180 inline
00181 ffData::ffData(void)
00182 : mNamingOK(false), mDataOK(false)
00183 {}
00184
00185 inline Interval
00186 ffData::getDt(void) const {
00187 return mDt;
00188 }
00189
00190 inline const char*
00191 ffData::getPrefix(void) const {
00192 return mFilePrefix.c_str();
00193 }
00194
00195 inline const char*
00196 ffData::getSuffix(void) const {
00197 return mFileSuffix.c_str();
00198 }
00199
00200 inline bool
00201 ffData::isFollowed(void) const {
00202 return mNamingOK;
00203 }
00204
00205 inline bool
00206 ffData::advance (int N)
00207 {
00208 if (!isFollowed()) {
00209 return false;
00210 }
00211 else {
00212 mStartGPS += mDt * double(N);
00213 return true;
00214 }
00215 }
00216
00217 inline bool
00218 ffData::isValid(void) const {
00219 return mDataOK;
00220 }
00221
00222 inline Time
00223 ffData::getStartTime(void) const {
00224 return mStartGPS;
00225 }
00226
00227 inline Time
00228 ffData::getEndTime(void) const {
00229 return mStartGPS + mDt;
00230 }
00231
00232 inline ffData::gps_t
00233 ffData::getStartGPS(void) const {
00234 return mStartGPS.getS();
00235 }
00236
00237 inline ffData::gps_t
00238 ffData::getEndGPS(void) const {
00239 return getEndTime().getS();
00240 }
00241
00249 struct ffDataSeries : public ffData {
00250 public:
00251
00255 ffDataSeries(void) : mNFiles (0) {}
00256
00265 ffDataSeries(const char* File, const Time& time,
00266 Interval Dt=Interval(1.0), bool DataOK=true)
00267 : ffData (File, time, Dt), mNFiles (1)
00268 {}
00269
00279 ffDataSeries(const char* Prefix, const char* Suffix,
00280 const Time& time, Interval Dt=Interval(1.0), count_t N = 1)
00281 : ffData (Prefix, Suffix, time, Dt), mNFiles (N)
00282 {}
00283
00287 ffDataSeries(const ffData& data) : ffData (data), mNFiles (1) {}
00288
00294 bool joinable (const ffDataSeries& series) const;
00295
00296
00302 bool join (const ffDataSeries& series);
00303
00312 bool join (const char* Prefix, const char* Suffix,
00313 const Time& time, Interval Dt);
00314
00319 Time getEndTime(void) const {
00320 return mStartGPS + mDt * double(mNFiles); }
00321
00326 gps_t getEndGPS(void) const {
00327 return getEndTime().getS(); }
00328
00333 Time getTime (count_t n) const {
00334 return mStartGPS + mDt * double(n); }
00335
00340 gps_t getGPS (count_t n) const {
00341 return getTime(n).getS(); }
00342
00347 Interval getLength(void) const {
00348 return mDt * double(mNFiles); }
00349
00354 count_t getNFiles(void) const {
00355 return mNFiles; }
00356
00361 void setNFiles(count_t N) {
00362 mNFiles = N; }
00363
00364 private:
00367 count_t mNFiles;
00368 };
00369
00370
00371 #ifdef __GNU_STDC_OLD
00372 namespace std {
00373 template <class _Category, class _Tp, class _Distance = ptrdiff_t,
00374 class _Pointer = _Tp*, class _Reference = _Tp&>
00375 struct iterator {
00376 typedef _Category iterator_category;
00377 typedef _Tp value_type;
00378 typedef _Distance difference_type;
00379 typedef _Pointer pointer;
00380 typedef _Reference reference;
00381 };
00382 }
00383 #endif
00384
00390 struct ffDataConstIter : public std::iterator
00391 <std::bidirectional_iterator_tag, ffData, int, const ffData*,
00392 const ffData&> {
00393 public:
00396 typedef ffData::gps_t gps_t;
00397
00400 typedef ffData::count_t count_t;
00401
00404 typedef std::map<gps_t, ffDataSeries> dmap_t;
00405
00408 typedef dmap_t::const_iterator dmap_iterator;
00409
00413 ffDataConstIter () : mList(0), mNFiles (0) {
00414 }
00418 ffDataConstIter (const dmap_t& List, const dmap_iterator& Iter,
00419 count_t Index) : mList(&List), mIndex (Iter),
00420 mNFiles (Index) {
00421 set();
00422 }
00426 bool operator== (const ffDataConstIter& i) const {
00427 return ((mList == i.mList) && (mNFiles == i.mNFiles) &&
00428 (mIndex == i.mIndex)); }
00432 bool operator!= (const ffDataConstIter& i) const {
00433 return !(*this == i); }
00434
00438 ffDataConstIter& operator++ () {
00439 add (1);
00440 return *this; }
00444 ffDataConstIter operator++ (int) {
00445 ffDataConstIter i = *this; add (1);
00446 return i; }
00450 ffDataConstIter& operator-- () {
00451 add (-1);
00452 return *this; }
00456 ffDataConstIter operator-- (int) {
00457 ffDataConstIter i = *this; add (-1);
00458 return i; }
00462 ffDataConstIter operator+ (int delta) const {
00463 ffDataConstIter i = *this; i.add (delta);
00464 return i; }
00468 ffDataConstIter operator- (int delta) const {
00469 ffDataConstIter i = *this; i.add (-delta);
00470 return i; }
00474 ffDataConstIter& operator+= (int delta) {
00475 add (delta);
00476 return *this; }
00480 ffDataConstIter& operator-= (int delta) {
00481 add (-delta);
00482 return *this; }
00486 reference operator*() const {
00487 return mData; }
00491 pointer operator->() const {
00492 return &mData; }
00493 protected:
00497 void set (void);
00501 void add (int delta);
00502 private:
00505 ffData mData;
00508 const dmap_t* mList;
00511 dmap_iterator mIndex;
00514 count_t mNFiles;
00515 };
00516
00517
00540 class FrameDir {
00541
00542 public:
00545 typedef Time::ulong_t gps_t;
00546
00549 typedef std::map<gps_t, ffDataSeries> dmap_t;
00550
00555 typedef ffDataConstIter file_iterator;
00556
00560 typedef dmap_t::const_iterator series_iterator;
00561
00562 public:
00566 virtual ~FrameDir(void);
00567
00571 FrameDir();
00572
00581 explicit FrameDir(const char* dir, bool delayed = false);
00582
00583
00587 file_iterator find(const Time& t) const throw(NoData);
00588
00595 file_iterator getStart(gps_t time) const;
00596
00602 file_iterator getLast(gps_t time) const;
00603
00608 int getDebug(void) const;
00609
00615 file_iterator begin(void) const;
00616
00621 file_iterator end(void) const;
00622
00628 series_iterator beginSeries(void) const;
00629
00634 series_iterator endSeries(void) const;
00635
00639 int sizeSeries() const;
00640
00644 int size() const;
00645
00649 bool empty() const {
00650 return mList.empty(); }
00651
00652
00653
00661 void add(const char* dir, bool delayed = false);
00662
00679 void addFile(const char* File, unsigned int Cont = 0) throw(BadFile);
00680
00684 void clear(void);
00685
00690 void erase(gps_t time);
00691
00696 void setDebug(int Level);
00697
00703 bool read (const char* File);
00704
00714 bool write (const char* File, bool Longlist = false,
00715 gps_t Start = 0, gps_t Stop = 0, bool SupHead = false);
00716
00726 bool write (std::ostream& Os, bool Longlist = false,
00727 gps_t Start = 0, gps_t Stop = 0, bool SupHead = false);
00728
00734 std::ostream& operator<< (std::ostream& Os);
00735
00745 static bool parseName (const char* File,
00746 gps_t& time, gps_t& tlen,
00747 char* pre = 0, char* post = 0);
00748
00749 private:
00752 enum CheckLevel {none, gapsOnly, allData};
00753
00760 void checkData(CheckLevel lvl=gapsOnly);
00761 void checkData(CheckLevel lvl=gapsOnly) const;
00762
00766 void join();
00767
00771 ffData getFileData(const char* File) throw(BadFile);
00772
00773 private:
00776 int mDebug;
00779 mutable bool mDirty;
00780
00783 dmap_t mList;
00784
00787 dmap_t::iterator last_insert;
00788 };
00789
00790 inline int
00791 FrameDir::getDebug(void) const {
00792 return mDebug;
00793 }
00794
00795 inline void
00796 FrameDir::setDebug(int Level) {
00797 mDebug = Level;
00798 }
00799
00800 #endif // FRAMEDIR_HH