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_), duration(duration_){}
00180         
00181 inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD, double durationInDays) :
00182         start(startInMJD), 
00183         duration((long long) (ArrayTime::unitsInADay * durationInDays)){}
00184 
00185 inline ArrayTimeInterval::ArrayTimeInterval(long long startInNanoSeconds,
00186                                                                                 long long durationInNanoSeconds):
00187                                                                                 start(startInNanoSeconds),
00188                                                                                 duration(durationInNanoSeconds) {}                              
00189 
00190 inline ArrayTimeInterval::ArrayTimeInterval(ArrayTime  start_):
00191         start(start_) {
00192         duration = Interval(Long::MAX_VALUE - start.get());
00193 }
00194 
00195 inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD):
00196         start(startInMJD) {
00197         this->duration = Interval(Long::MAX_VALUE - start.get());
00198 }
00199 
00200 inline  ArrayTimeInterval::ArrayTimeInterval(long long startInNanoSeconds):
00201         start(startInNanoSeconds) {
00202                 this->duration = Interval(Long::MAX_VALUE - start.get());
00203         };
00204         
00205 // Inline setters
00206 inline void ArrayTimeInterval::setStart(ArrayTime start) {
00207         this->start = ArrayTime(start);
00208 }
00209 
00210 inline void ArrayTimeInterval::setStart(double start) {
00211         this->start = ArrayTime(start);
00212 }
00213 
00214 inline void ArrayTimeInterval::setStart(long long start) {
00215         this->start = ArrayTime(start);
00216 }
00217 
00218 inline void ArrayTimeInterval::setDuration(Interval duration) {
00219         this->duration = Interval(duration);    
00220 }
00221 
00222 
00223 inline void ArrayTimeInterval::setDuration(double duration) {
00224         this->duration = Interval((long long) (ArrayTime::unitsInADay * duration));     
00225 }
00226 
00227 inline void ArrayTimeInterval::setDuration(long long duration) {
00228         this->duration = Interval(duration);    
00229 }
00230 
00231 // inline getters
00232 inline ArrayTime ArrayTimeInterval::getStart() const {
00233         return start;   
00234 }
00235 
00236 inline double ArrayTimeInterval::getStartInMJD() const {
00237         return start.getMJD();  
00238 }
00239 
00240 inline long long ArrayTimeInterval::getStartInNanoSeconds() const  {
00241         return start.get();     
00242 }
00243 
00244 inline Interval ArrayTimeInterval::getDuration() const {
00245         return duration;        
00246 }
00247 
00248 inline double ArrayTimeInterval::getDurationInDays() const {
00249         return (((double) duration.get()) / ArrayTime::unitsInADay);    
00250 }
00251 
00252 inline long long ArrayTimeInterval::getDurationInNanoSeconds() const {
00253         return duration.get();  
00254 }
00255 
00256 // inline checkers
00257 inline bool ArrayTimeInterval::equals(ArrayTimeInterval ati) {
00258         return ((start.get() == ati.getStart().get()) && 
00259                 (duration.get() == ati.getDuration().get()));
00260 }
00261 
00262 inline bool ArrayTimeInterval::overlaps(ArrayTimeInterval ati) {
00263         long long start1 = start.get();
00264         long long end1 = start1 + duration.get();
00265         
00266         
00267         long long start2 = ati.getStart().get();
00268         long long end2   = start2 + ati.getDuration().get();
00269         
00270         return (start2 <= start1 && end2 >= start1) ||
00271                (start2 >= start1 && start2 <= end1);
00272 }
00273                
00274 inline bool ArrayTimeInterval::contains(ArrayTimeInterval ati) {
00275         long long start1 = start.get();;
00276         long long end1 = start1 + duration.get();
00277         
00278         long long start2 = ati.getStart().get();
00279         long long end2   = start2 + ati.getDuration().get();
00280 
00281         return (start2>=start1 && end2<=end1);
00282 }
00283 
00284 inline bool ArrayTimeInterval::contains(ArrayTime ati) {
00285         long long start1 = start.get();
00286         long long end1 = start1 + duration.get();
00287         
00288         long long time = ati.get();
00289         return (time >= start1 && time <= end1);
00290 }
00291 
00292 inline bool ArrayTimeInterval::operator == (ArrayTimeInterval &ati){
00293         return (start == ati.start) && (duration == ati.duration);
00294 }
00295 
00296 inline bool ArrayTimeInterval::operator != (ArrayTimeInterval &ati){
00297         return (start != ati.start) || (duration != ati.duration);
00298 }
00299 
00300 inline ostream & operator << ( ostream &o, ArrayTimeInterval &ati ) {
00301         o << "(start=" << ati.getStart().get() << ",duration=" << ati.getDuration().get() << ")";
00302         return o;
00303         
00304 } // End namespace asdm
00305 } // ArrayTimeInterval_CLASS
00306 #endif

Generated on Thu Nov 29 16:46:45 2007 for ASDM C++ Implementation by  doxygen 1.5.1