Angle.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 Angle.h 00025 */ 00026 00027 #ifndef Angle_CLASS 00028 #define Angle_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::IDLAngle; 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 00055 namespace asdm { 00056 00057 class Angle; 00058 Angle operator * ( double , const Angle & ); 00059 ostream & operator << ( ostream &, const Angle & ); 00060 istream & operator >> ( istream &, Angle&); 00061 00072 class Angle { 00073 friend Angle operator * ( double , const Angle & ); 00074 friend ostream & operator << ( ostream &, const Angle & ); 00075 friend istream & operator >> ( istream &, Angle&); 00076 00077 public: 00078 Angle(); // default constructor 00079 Angle(const Angle &); // X const X& constructor 00080 Angle(const string &s); 00081 #ifndef WITHOUT_ACS 00082 Angle(const IDLAngle &); 00083 #endif 00084 Angle(double value); 00085 virtual ~Angle(); // destructor 00086 static double fromString(const string&); 00087 static string toString(double); 00088 static Angle getAngle(StringTokenizer &t) throw(NumberFormatException); 00089 00093 void toBin(EndianOSStream& eoss); 00094 00100 static void toBin(const vector<Angle>& angle, EndianOSStream& eoss); 00101 00107 static void toBin(const vector<vector<Angle> >& angle, EndianOSStream& eoss); 00108 00114 static void toBin(const vector<vector<vector<Angle> > >& angle, EndianOSStream& eoss); 00115 00122 static Angle fromBin(EndianISStream& eiss); 00123 00130 static vector<Angle> from1DBin(EndianISStream & eiss); 00131 00138 static vector<vector<Angle> > from2DBin(EndianISStream & eiss); 00139 00146 static vector<vector<vector<Angle> > > from3DBin(EndianISStream & eiss); 00147 00148 Angle& operator = (const Angle&); // assignment operator 00149 Angle& operator = (const double); // assignment operator 00150 00151 Angle& operator += (const Angle&); // assignment with arithmetic 00152 Angle& operator -= (const Angle&); // operators 00153 Angle& operator *= (const double); 00154 Angle& operator /= (const double); 00155 00156 Angle operator + (const Angle&) const; // arithmetic operators 00157 Angle operator - (const Angle&) const; 00158 Angle operator * (const double) const; 00159 Angle operator / (const double) const; 00160 00161 bool operator < (const Angle&) const; // comparison operators 00162 bool operator > (const Angle&) const; 00163 bool operator <= (const Angle&) const; 00164 bool operator >= (const Angle&) const; 00165 bool operator == (const Angle&) const; 00166 bool equals(const Angle&) const; 00167 bool operator != (const Angle&) const; 00168 00169 bool isZero() const; 00170 00171 Angle operator - () const; // unary minus 00172 Angle operator + () const; // unary plus 00173 00174 string toString() const; 00175 string toStringI() const; 00176 00177 operator string () const; 00178 double get() const; 00179 #ifndef WITHOUT_ACS 00180 IDLAngle toIDLAngle() const; 00181 #endif 00182 static string unit(); 00183 00184 private: 00185 double value; 00186 00187 }; 00188 00189 // Angle constructors 00190 inline Angle::Angle() : value(0.0) { 00191 } 00192 00193 inline Angle::Angle(const Angle &t) : value(t.value) { 00194 } 00195 00196 #ifndef WITHOUT_ACS 00197 inline Angle::Angle(const IDLAngle &l) : value(l.value) { 00198 } 00199 #endif 00200 00201 inline Angle::Angle(const string &s) : value(fromString(s)) { 00202 } 00203 00204 inline Angle::Angle(double v) : value(v) { 00205 } 00206 00207 // Angle destructor 00208 inline Angle::~Angle() { } 00209 00210 // assignment operator 00211 inline Angle& Angle::operator = ( const Angle &t ) { 00212 value = t.value; 00213 return *this; 00214 } 00215 00216 // assignment operator 00217 inline Angle& Angle::operator = ( const double v ) { 00218 value = v; 00219 return *this; 00220 } 00221 00222 // assignment with arithmetic operators 00223 inline Angle& Angle::operator += ( const Angle& t) { 00224 value += t.value; 00225 return *this; 00226 } 00227 00228 inline Angle& Angle::operator -= ( const Angle& t) { 00229 value -= t.value; 00230 return *this; 00231 } 00232 00233 inline Angle& Angle::operator *= ( const double n) { 00234 value *= n; 00235 return *this; 00236 } 00237 00238 inline Angle& Angle::operator /= ( const double n) { 00239 value /= n; 00240 return *this; 00241 } 00242 00243 // arithmetic functions 00244 inline Angle Angle::operator + ( const Angle &t2 ) const { 00245 Angle tmp; 00246 tmp.value = value + t2.value; 00247 return tmp; 00248 } 00249 00250 inline Angle Angle::operator - ( const Angle &t2 ) const { 00251 Angle tmp; 00252 tmp.value = value - t2.value; 00253 return tmp; 00254 } 00255 inline Angle Angle::operator * ( const double n) const { 00256 Angle tmp; 00257 tmp.value = value * n; 00258 return tmp; 00259 } 00260 00261 inline Angle Angle::operator / ( const double n) const { 00262 Angle tmp; 00263 tmp.value = value / n; 00264 return tmp; 00265 } 00266 00267 // comparison operators 00268 inline bool Angle::operator < (const Angle& x) const { 00269 return (value < x.value); 00270 } 00271 00272 inline bool Angle::operator > (const Angle& x) const { 00273 return (value > x.value); 00274 } 00275 00276 inline bool Angle::operator <= (const Angle& x) const { 00277 return (value <= x.value); 00278 } 00279 00280 inline bool Angle::operator >= (const Angle& x) const { 00281 return (value >= x.value); 00282 } 00283 00284 inline bool Angle::equals(const Angle& x) const { 00285 return (value == x.value); 00286 } 00287 00288 00289 inline bool Angle::operator == (const Angle& x) const { 00290 return (value == x.value); 00291 } 00292 00293 inline bool Angle::operator != (const Angle& x) const { 00294 return (value != x.value); 00295 } 00296 00297 // unary - and + operators 00298 inline Angle Angle::operator - () const { 00299 Angle tmp; 00300 tmp.value = -value; 00301 return tmp; 00302 } 00303 00304 inline Angle Angle::operator + () const { 00305 Angle tmp; 00306 tmp.value = value; 00307 return tmp; 00308 } 00309 00310 // Conversion functions 00311 inline Angle::operator string () const { 00312 return toString(); 00313 } 00314 00315 inline string Angle::toString() const { 00316 return toString(value); 00317 } 00318 00319 inline string Angle::toStringI() const { 00320 return toString(value); 00321 } 00322 00323 inline double Angle::get() const { 00324 return value; 00325 } 00326 00327 #ifndef WITHOUT_ACS 00328 inline IDLAngle Angle::toIDLAngle() const { 00329 IDLAngle tmp; 00330 tmp.value = value; 00331 return tmp; 00332 } 00333 #endif 00334 00335 // Friend functions 00336 00337 inline Angle operator * ( double n, const Angle &x) { 00338 Angle tmp; 00339 tmp.value = x.value * n; 00340 return tmp; 00341 } 00342 00343 inline ostream & operator << ( ostream &o, const Angle &x ) { 00344 o << x.value; 00345 return o; 00346 } 00347 00348 inline istream & operator >> ( istream &i, Angle &x ) { 00349 i >> x.value; 00350 return i; 00351 } 00352 00353 inline string Angle::unit() { 00354 return string ("rad"); 00355 } 00356 00357 } // End namespace asdm 00358 00359 #endif /* Angle_CLASS */

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