Interval.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 Interval.h 00025 */ 00026 00027 #ifndef Interval_CLASS 00028 #define Interval_CLASS 00029 00030 #include <vector> 00031 #include <iostream> 00032 #include <string> 00033 using namespace std; 00034 00035 #ifndef WITHOUT_ACS 00036 #include <asdmIDLTypesC.h> 00037 using asdmIDLTypes::IDLInterval; 00038 #endif 00039 00040 #include <StringTokenizer.h> 00041 #include <NumberFormatException.h> 00042 using asdm::StringTokenizer; 00043 using asdm::NumberFormatException; 00044 00045 #include <EndianStream.h> 00046 using asdm::EndianOSStream; 00047 using asdm::EndianISStream; 00048 00049 namespace asdm { 00050 00051 class Interval; 00052 Interval operator * ( long long , const Interval & ); 00053 ostream & operator << ( ostream &, const Interval & ); 00054 istream & operator >> ( istream &, Interval&); 00055 00063 class Interval { 00064 friend Interval operator * ( long long , const Interval & ); 00065 friend ostream & operator << ( ostream &, const Interval & ); 00066 friend istream & operator >> ( istream &, Interval&); 00067 00068 public: 00069 static long long fromString(const string&); 00070 static string toString(long long); 00071 static Interval getInterval(StringTokenizer &t) throw(NumberFormatException); 00072 00073 Interval(); // default constructor 00074 Interval(const Interval &); // X const X& constructor 00075 Interval(const string &s); 00076 #ifndef WITHOUT_ACS 00077 Interval(const IDLInterval &); 00078 #endif 00079 Interval(long long value); 00080 virtual ~Interval(); // destructor 00081 00082 Interval& operator = (const Interval&); // assignment operator 00083 Interval& operator = (const long long); // assignment operator 00084 00085 Interval& operator += (const Interval&); // assignment with arithmetic 00086 Interval& operator -= (const Interval&); // operators 00087 Interval& operator *= (const long long); 00088 Interval& operator /= (const long long); 00089 00090 Interval operator + (const Interval&) const; // arithmetic operators 00091 Interval operator - (const Interval&) const; 00092 Interval operator * (const long long) const; 00093 Interval operator / (const long long) const; 00094 00095 bool operator < (const Interval&) const; // comparison operators 00096 bool operator > (const Interval&) const; 00097 bool operator <= (const Interval&) const; 00098 bool operator >= (const Interval&) const; 00099 bool operator == (const Interval&) const; 00100 bool equals(const Interval&) const; 00101 bool operator != (const Interval&) const; 00102 00103 bool isZero() const; 00104 00105 Interval operator - () const; // unary minus 00106 Interval operator + () const; // unary plus 00107 00108 string toString() const; 00109 string toStringI() const; 00110 00116 void toBin(EndianOSStream& eoss) ; 00117 00123 static void toBin(vector<Interval> interval, EndianOSStream& eoss) ; 00124 00130 static void toBin(vector<vector<Interval> > interval, EndianOSStream& eoss) ; 00131 00138 static Interval fromBin(EndianISStream& eiss); 00139 00146 static vector<Interval> from1DBin(EndianISStream& eiss); 00147 00154 static vector<vector<Interval> >from2DBin(EndianISStream& eiss); 00155 00156 operator string () const; 00157 long long get() const; 00158 #ifndef WITHOUT_ACS 00159 IDLInterval toIDLInterval() const; 00160 #endif 00161 static string unit(); 00162 00163 private: 00164 long long value; 00165 00166 }; 00167 00168 // Interval constructors 00169 inline Interval::Interval() : value(0L) { 00170 } 00171 00172 inline Interval::Interval(const Interval &t) : value(t.value) { 00173 } 00174 00175 #ifndef WITHOUT_ACS 00176 inline Interval::Interval(const IDLInterval &l) : value(l.value) { 00177 } 00178 #endif 00179 00180 inline Interval::Interval(const string &s) : value(fromString(s)) { 00181 } 00182 00183 inline Interval::Interval(long long v) : value(v) { 00184 } 00185 00186 // Interval destructor 00187 inline Interval::~Interval() { } 00188 00189 // assignment operator 00190 inline Interval& Interval::operator = ( const Interval &t ) { 00191 value = t.value; 00192 return *this; 00193 } 00194 00195 // assignment operator 00196 inline Interval& Interval::operator = ( const long long v ) { 00197 value = v; 00198 return *this; 00199 } 00200 00201 // assignment with arithmetic operators 00202 inline Interval& Interval::operator += ( const Interval& t) { 00203 value += t.value; 00204 return *this; 00205 } 00206 00207 inline Interval& Interval::operator -= ( const Interval& t) { 00208 value -= t.value; 00209 return *this; 00210 } 00211 00212 inline Interval& Interval::operator *= ( const long long n) { 00213 value *= n; 00214 return *this; 00215 } 00216 00217 inline Interval& Interval::operator /= ( const long long n) { 00218 value /= n; 00219 return *this; 00220 } 00221 00222 // arithmetic functions 00223 inline Interval Interval::operator + ( const Interval &t2 ) const { 00224 Interval tmp; 00225 tmp.value = value + t2.value; 00226 return tmp; 00227 } 00228 00229 inline Interval Interval::operator - ( const Interval &t2 ) const { 00230 Interval tmp; 00231 tmp.value = value - t2.value; 00232 return tmp; 00233 } 00234 inline Interval Interval::operator * ( const long long n) const { 00235 Interval tmp; 00236 tmp.value = value * n; 00237 return tmp; 00238 } 00239 00240 inline Interval Interval::operator / ( const long long n) const { 00241 Interval tmp; 00242 tmp.value = value / n; 00243 return tmp; 00244 } 00245 00246 // comparison operators 00247 inline bool Interval::operator < (const Interval& x) const { 00248 return (value < x.value); 00249 } 00250 00251 inline bool Interval::operator > (const Interval& x) const { 00252 return (value > x.value); 00253 } 00254 00255 inline bool Interval::operator <= (const Interval& x) const { 00256 return (value <= x.value); 00257 } 00258 00259 inline bool Interval::operator >= (const Interval& x) const { 00260 return (value >= x.value); 00261 } 00262 00263 inline bool Interval::operator == (const Interval& x) const { 00264 return (value == x.value); 00265 } 00266 inline bool Interval::equals(const Interval& x) const { 00267 return (value == x.value); 00268 } 00269 00270 inline bool Interval::operator != (const Interval& x) const { 00271 return (value != x.value); 00272 } 00273 00274 // unary - and + operators 00275 inline Interval Interval::operator - () const { 00276 Interval tmp; 00277 tmp.value = -value; 00278 return tmp; 00279 } 00280 00281 inline Interval Interval::operator + () const { 00282 Interval tmp; 00283 tmp.value = value; 00284 return tmp; 00285 } 00286 00287 // Conversion functions 00288 inline Interval::operator string () const { 00289 return toString(); 00290 } 00291 00292 inline string Interval::toString() const { 00293 return toString(value); 00294 } 00295 00296 inline string Interval::toStringI() const { 00297 return toString(value); 00298 } 00299 00300 inline long long Interval::get() const { 00301 return value; 00302 } 00303 00304 #ifndef WITHOUT_ACS 00305 inline IDLInterval Interval::toIDLInterval() const { 00306 IDLInterval tmp; 00307 tmp.value = value; 00308 return tmp; 00309 } 00310 #endif 00311 00312 // Friend functions 00313 00314 inline Interval operator * ( long long n, const Interval &x) { 00315 Interval tmp; 00316 tmp.value = x.value * n; 00317 return tmp; 00318 } 00319 00320 inline ostream & operator << ( ostream &o, const Interval &x ) { 00321 o << x.value; 00322 return o; 00323 } 00324 00325 inline istream & operator >> ( istream &i, Interval &x ) { 00326 i >> x.value; 00327 return i; 00328 } 00329 00330 inline string Interval::unit() { 00331 return string ("nanosec"); 00332 } 00333 00334 } // End namespace asdm 00335 00336 #endif /* Interval_CLASS */

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