ArrayTimeInterval.h

00001 /* 00002 * ALMA - Atacama Large Millimeter Array 00003 * (c) European Southern Observatory, 2002 00004 * (c) Associated Universities Inc., 2002 00005 * Copyright by ESO (in the framework of the ALMA collaboration), 00006 * Copyright by AUI (in the framework of the ALMA collaboration), 00007 * All rights reserved. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY, without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00022 * MA 02111-1307 USA 00023 * 00024 * File ArrayTimeInterval.h 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 // Constructors 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 // Setters 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 // Getters 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 // Checkers 00101 bool equals(ArrayTimeInterval ati); 00102 bool overlaps(ArrayTimeInterval ati); 00103 bool contains(ArrayTimeInterval ati); 00104 bool contains(ArrayTime at); 00105 00106 // Operators 00107 bool operator == (ArrayTimeInterval&); 00108 bool operator != (ArrayTimeInterval&); 00109 00110 #ifndef WITHOUT_ACS 00111 // To IDL conversion 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 // inline constructors 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 // Inline setters 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 // inline getters 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 // inline checkers 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 } // End namespace asdm 00308 } // ArrayTimeInterval_CLASS 00309 #endif

Generated on Tue Nov 18 17:43:40 2008 for ASDM C++ Implementation by doxygen 1.3.8