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

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