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

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