00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ArrayTimeInterval_CLASS
00028 #define ArrayTimeInterval_CLASS
00029
00030 #include <Long.h>
00031 #include <ArrayTime.h>
00032 #include <Interval.h>
00033
00034 #ifndef WITHOUT_ACS
00035 #include <asdmIDLTypesC.h>
00036 #endif
00037
00038 using asdm::Long;
00039 using asdm::Interval;
00040 using asdm::ArrayTime;
00041
00042 #ifndef WITHOUT_ACS
00043 using asdmIDLTypes::IDLArrayTimeInterval;
00044 #endif
00045
00046 namespace asdm {
00047
00054 class ArrayTimeInterval {
00055 friend ostream & operator << ( ostream &, ArrayTimeInterval& );
00056
00057 private:
00058 ArrayTime start;
00059 Interval duration;
00060
00061 public:
00062
00063
00064
00065 ArrayTimeInterval();
00066 ArrayTimeInterval(ArrayTime start,
00067 Interval duration);
00068
00069 ArrayTimeInterval(double startInMJD,
00070 double durationInDays);
00071
00072 ArrayTimeInterval(long long startInNanoSeconds,
00073 long long durationInNanoSeconds);
00074
00075 ArrayTimeInterval(ArrayTime start);
00076 ArrayTimeInterval(double startInMJD);
00077 ArrayTimeInterval(long long startInNanoSeconds);
00078
00079 #ifndef WITHOUT_ACS
00080 ArrayTimeInterval (IDLArrayTimeInterval t);
00081 #endif
00082
00083 void setStart(ArrayTime start);
00084 void setStart(double start);
00085 void setStart(long long start);
00086
00087 void setDuration(Interval duration);
00088 void setDuration(long long nanoSeconds);
00089 void setDuration(double days);
00090
00091
00092 ArrayTime getStart() const ;
00093 double getStartInMJD() const ;
00094 long long getStartInNanoSeconds() const ;
00095
00096 Interval getDuration() const ;
00097 long long getDurationInNanoSeconds() const ;
00098 double getDurationInDays() const ;
00099
00100
00101 bool equals(ArrayTimeInterval ati);
00102 bool overlaps(ArrayTimeInterval ati);
00103 bool contains(ArrayTimeInterval ati);
00104 bool contains(ArrayTime at);
00105
00106
00107 bool operator == (ArrayTimeInterval&);
00108 bool operator != (ArrayTimeInterval&);
00109
00110 #ifndef WITHOUT_ACS
00111
00112 const asdmIDLTypes::IDLArrayTimeInterval toIDLArrayTimeInterval() const;
00113 #endif
00114
00118 void toBin(EndianOSStream& eoss);
00119
00125 static void toBin(const vector<ArrayTimeInterval>& arrayTimeInterval, EndianOSStream& eoss);
00126
00132 static void toBin(const vector<vector<ArrayTimeInterval> >& arrayTimeInterval, EndianOSStream& eoss);
00133
00139 static void toBin(const vector<vector<vector<ArrayTimeInterval> > >& arrayTimeInterval, EndianOSStream& eoss);
00140
00147 static ArrayTimeInterval fromBin(EndianISStream& eiss);
00148
00155 static vector<ArrayTimeInterval> from1DBin(EndianISStream & eiss);
00156
00163 static vector<vector<ArrayTimeInterval> > from2DBin(EndianISStream & eiss);
00164
00171 static vector<vector<vector<ArrayTimeInterval> > > from3DBin(EndianISStream & eiss);
00172 };
00173
00174
00175
00176
00177 inline ArrayTimeInterval::ArrayTimeInterval(): start((long long)0), duration(0) {}
00178 inline ArrayTimeInterval::ArrayTimeInterval(ArrayTime start_, Interval duration_) {
00179 start = start_;
00180 duration = Interval(min(duration_.get(), Long::MAX_VALUE - start.get()));
00181 }
00182
00183 inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD, double durationInDays) :
00184 start(startInMJD),
00185 duration((long long) (ArrayTime::unitsInADay * durationInDays)){}
00186
00187 inline ArrayTimeInterval::ArrayTimeInterval(long long startInNanoSeconds,
00188 long long durationInNanoSeconds){
00189 start = startInNanoSeconds;
00190 duration = min(durationInNanoSeconds, Long::MAX_VALUE - startInNanoSeconds);
00191 }
00192
00193 inline ArrayTimeInterval::ArrayTimeInterval(ArrayTime start_):
00194 start(start_) {
00195 duration = Interval(Long::MAX_VALUE - start.get());
00196 }
00197
00198 inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD):
00199 start(startInMJD) {
00200 this->duration = Interval(Long::MAX_VALUE - start.get());
00201 }
00202
00203 inline ArrayTimeInterval::ArrayTimeInterval(long long startInNanoSeconds):
00204 start(startInNanoSeconds) {
00205 this->duration = Interval(Long::MAX_VALUE - start.get());
00206 }
00207
00208
00209 inline void ArrayTimeInterval::setStart(ArrayTime start) {
00210 this->start = ArrayTime(start);
00211 }
00212
00213 inline void ArrayTimeInterval::setStart(double start) {
00214 this->start = ArrayTime(start);
00215 }
00216
00217 inline void ArrayTimeInterval::setStart(long long start) {
00218 this->start = ArrayTime(start);
00219 }
00220
00221 inline void ArrayTimeInterval::setDuration(Interval duration) {
00222 this->duration = Interval(duration);
00223 }
00224
00225
00226 inline void ArrayTimeInterval::setDuration(double duration) {
00227 this->duration = Interval((long long) (ArrayTime::unitsInADay * duration));
00228 }
00229
00230 inline void ArrayTimeInterval::setDuration(long long duration) {
00231 this->duration = Interval(duration);
00232 }
00233
00234
00235 inline ArrayTime ArrayTimeInterval::getStart() const {
00236 return start;
00237 }
00238
00239 inline double ArrayTimeInterval::getStartInMJD() const {
00240 return start.getMJD();
00241 }
00242
00243 inline long long ArrayTimeInterval::getStartInNanoSeconds() const {
00244 return start.get();
00245 }
00246
00247 inline Interval ArrayTimeInterval::getDuration() const {
00248 return duration;
00249 }
00250
00251 inline double ArrayTimeInterval::getDurationInDays() const {
00252 return (((double) duration.get()) / ArrayTime::unitsInADay);
00253 }
00254
00255 inline long long ArrayTimeInterval::getDurationInNanoSeconds() const {
00256 return duration.get();
00257 }
00258
00259
00260 inline bool ArrayTimeInterval::equals(ArrayTimeInterval ati) {
00261 return ((start.get() == ati.getStart().get()) &&
00262 (duration.get() == ati.getDuration().get()));
00263 }
00264
00265 inline bool ArrayTimeInterval::overlaps(ArrayTimeInterval ati) {
00266 long long start1 = start.get();
00267 long long end1 = start1 + duration.get();
00268
00269
00270 long long start2 = ati.getStart().get();
00271 long long end2 = start2 + ati.getDuration().get();
00272
00273 return (start2 <= start1 && end2 >= start1) ||
00274 (start2 >= start1 && start2 <= end1);
00275 }
00276
00277 inline bool ArrayTimeInterval::contains(ArrayTimeInterval ati) {
00278 long long start1 = start.get();;
00279 long long end1 = start1 + duration.get();
00280
00281 long long start2 = ati.getStart().get();
00282 long long end2 = start2 + ati.getDuration().get();
00283
00284 return (start2>=start1 && end2<=end1);
00285 }
00286
00287 inline bool ArrayTimeInterval::contains(ArrayTime ati) {
00288 long long start1 = start.get();
00289 long long end1 = start1 + duration.get();
00290
00291 long long time = ati.get();
00292 return (time >= start1 && time < end1);
00293 }
00294
00295 inline bool ArrayTimeInterval::operator == (ArrayTimeInterval &ati){
00296 return (start == ati.start) && (duration == ati.duration);
00297 }
00298
00299 inline bool ArrayTimeInterval::operator != (ArrayTimeInterval &ati){
00300 return (start != ati.start) || (duration != ati.duration);
00301 }
00302
00303 inline ostream & operator << ( ostream &o, ArrayTimeInterval &ati ) {
00304 o << "(start=" << ati.getStart().get() << ",duration=" << ati.getDuration().get() << ")";
00305 return o;
00306
00307 }
00308 }
00309 #endif