Temperature.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 Temperature.h
00025  */
00026 
00027 #ifndef Temperature_CLASS
00028 #define Temperature_CLASS
00029 
00030 #include <iostream>
00031 #include <string>
00032 using namespace std;
00033 
00034 #ifndef WITHOUT_ACS
00035 #include <asdmIDLTypesC.h>
00036 using asdmIDLTypes::IDLTemperature;
00037 #endif
00038 
00039 #include <StringTokenizer.h>
00040 #include <NumberFormatException.h>
00041 using asdm::StringTokenizer;
00042 using asdm::NumberFormatException;
00043 
00044 namespace asdm {
00045 
00046 class Temperature;
00047 Temperature operator * ( double , const Temperature & );
00048 ostream & operator << ( ostream &, const Temperature & );
00049 istream & operator >> ( istream &, Temperature&);
00050 
00057 class Temperature {
00058         friend Temperature operator * ( double , const Temperature & );
00059     friend ostream & operator << ( ostream &, const Temperature & );
00060         friend istream & operator >> ( istream &, Temperature&);
00061 
00062 public:
00063         static double fromString(const string&);
00064         static string toString(double);
00065         static Temperature getTemperature(StringTokenizer &t) throw(NumberFormatException);
00066 
00067         Temperature();                                          // default constructor
00068         Temperature(const Temperature &);                                               // X const X& constructor
00069         Temperature(const string &s);
00070 #ifndef WITHOUT_ACS
00071         Temperature(const IDLTemperature &);
00072 #endif
00073         Temperature(double value);
00074         virtual ~Temperature();                                                 // destructor
00075 
00076         Temperature& operator = (const Temperature&);                   // assignment operator
00077         Temperature& operator = (const double);                 // assignment operator
00078 
00079         Temperature& operator += (const Temperature&);          // assignment with arithmetic
00080         Temperature& operator -= (const Temperature&);          //      operators
00081         Temperature& operator *= (const double);
00082         Temperature& operator /= (const double);
00083 
00084         Temperature operator + (const Temperature&) const;      // arithmetic operators
00085         Temperature operator - (const Temperature&) const;
00086         Temperature operator * (const double) const;
00087         Temperature operator / (const double) const;
00088 
00089         bool operator < (const Temperature&) const;             // comparison operators
00090         bool operator > (const Temperature&) const;
00091         bool operator <= (const Temperature&) const;
00092         bool operator >= (const Temperature&) const;
00093         bool operator == (const Temperature&) const;
00094         bool equals(const Temperature&) const;
00095         bool operator != (const Temperature&) const;
00096 
00097         bool isZero() const;
00098 
00099         Temperature operator - () const;                                        // unary minus
00100         Temperature operator + () const;                                // unary plus
00101 
00102         string toString() const;
00103         string toStringI() const;
00104 
00105         operator string () const;
00106         double get() const;
00107 #ifndef WITHOUT_ACS
00108         IDLTemperature toIDLTemperature() const;
00109 #endif
00110         static string unit();
00111 
00112 private:
00113         double value;
00114 
00115 };
00116 
00117 // Temperature constructors
00118 inline Temperature::Temperature() : value(0.0) {
00119 }
00120 
00121 inline Temperature::Temperature(const Temperature &t) : value(t.value) {
00122 }
00123 
00124 #ifndef WITHOUT_ACS
00125 inline Temperature::Temperature(const IDLTemperature &l) : value(l.value) {
00126 }
00127 #endif
00128 
00129 inline Temperature::Temperature(const string &s) : value(fromString(s)) {
00130 }
00131 
00132 inline Temperature::Temperature(double v) : value(v) {
00133 }
00134 
00135 // Temperature destructor
00136 inline Temperature::~Temperature() { }
00137 
00138 // assignment operator
00139 inline Temperature& Temperature::operator = ( const Temperature &t ) {
00140         value = t.value;
00141         return *this;
00142 }
00143 
00144 // assignment operator
00145 inline Temperature& Temperature::operator = ( const double v ) {
00146         value = v;
00147         return *this;
00148 }
00149 
00150 // assignment with arithmetic operators
00151 inline Temperature& Temperature::operator += ( const Temperature& t) {
00152         value += t.value;
00153         return *this;
00154 }
00155 
00156 inline Temperature& Temperature::operator -= ( const Temperature& t) {
00157         value -= t.value;
00158         return *this;
00159 }
00160 
00161 inline Temperature& Temperature::operator *= ( const double n) {
00162         value *= n;
00163         return *this;
00164 }
00165 
00166 inline Temperature& Temperature::operator /= ( const double n) {
00167         value /= n;
00168         return *this;
00169 }
00170 
00171 // arithmetic functions
00172 inline Temperature Temperature::operator + ( const Temperature &t2 ) const {
00173         Temperature tmp;
00174         tmp.value = value + t2.value;
00175         return tmp;
00176 }
00177 
00178 inline Temperature Temperature::operator - ( const Temperature &t2 ) const {
00179         Temperature tmp;
00180         tmp.value = value - t2.value;
00181         return tmp;
00182 }
00183 inline Temperature Temperature::operator * ( const double n) const {
00184         Temperature tmp;
00185         tmp.value = value * n;
00186         return tmp;
00187 }
00188 
00189 inline Temperature Temperature::operator / ( const double n) const {
00190         Temperature tmp;
00191         tmp.value = value / n;
00192         return tmp;
00193 }
00194 
00195 // comparison operators
00196 inline bool Temperature::operator < (const Temperature& x) const {
00197         return (value < x.value);
00198 }
00199 
00200 inline bool Temperature::operator > (const Temperature& x) const {
00201         return (value > x.value);
00202 }
00203 
00204 inline bool Temperature::operator <= (const Temperature& x) const {
00205         return (value <= x.value);
00206 }
00207 
00208 inline bool Temperature::operator >= (const Temperature& x) const {
00209         return (value >= x.value);
00210 }
00211 
00212 inline bool Temperature::operator == (const Temperature& x) const {
00213         return (value == x.value);
00214 }
00215 inline bool Temperature::equals(const Temperature& x) const {
00216         return (value == x.value);
00217 }
00218 
00219 inline bool Temperature::operator != (const Temperature& x) const {
00220         return (value != x.value);
00221 }
00222 
00223 // unary - and + operators
00224 inline Temperature Temperature::operator - () const {
00225         Temperature tmp;
00226         tmp.value = -value;
00227         return tmp;
00228 }
00229 
00230 inline Temperature Temperature::operator + () const {
00231         Temperature tmp;
00232     tmp.value = value;
00233         return tmp;
00234 }
00235 
00236 // Conversion functions
00237 inline Temperature::operator string () const {
00238         return toString();
00239 }
00240 
00241 inline string Temperature::toString() const {
00242         return toString(value);
00243 }
00244 
00245 inline string Temperature::toStringI() const {
00246         return toString(value);
00247 }
00248 
00249 inline double Temperature::get() const {
00250         return value;
00251 }
00252 
00253 #ifndef WITHOUT_ACS
00254 inline IDLTemperature Temperature::toIDLTemperature() const {
00255         IDLTemperature tmp;
00256         tmp.value = value;
00257         return tmp;
00258 }
00259 #endif
00260 
00261 // Friend functions
00262 
00263 inline Temperature operator * ( double n, const Temperature &x) {
00264         Temperature tmp;
00265         tmp.value = x.value * n;
00266         return tmp;
00267 }
00268 
00269 inline ostream & operator << ( ostream &o, const Temperature &x ) {
00270         o << x.value;
00271         return o;
00272 }
00273 
00274 inline istream & operator >> ( istream &i, Temperature &x ) {
00275         i >> x.value;
00276         return i;
00277 }
00278 
00279 inline string Temperature::unit() {
00280         return string ("degC");
00281 }
00282 
00283 } // End namespace asdm
00284 
00285 #endif /* Temperature_CLASS */

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