Line data Source code
1 : #ifndef _ATM_LENGTH_H 2 : #define _ATM_LENGTH_H 3 : /******************************************************************************* 4 : * ALMA - Atacama Large Millimiter Array 5 : * (c) Instituto de Estructura de la Materia, 2009 6 : * 7 : * This library is free software; you can redistribute it and/or 8 : * modify it under the terms of the GNU Lesser General Public 9 : * License as published by the Free Software Foundation; either 10 : * version 2.1 of the License, or (at your option) any later version. 11 : * 12 : * This library is distributed in the hope that it will be useful, 13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 : * Lesser General Public License for more details. 16 : * 17 : * You should have received a copy of the GNU Lesser General Public 18 : * License along with this library; if not, write to the Free Software 19 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 : * 21 : * "@(#) $Id: ATMLength.h Exp $" 22 : * 23 : * who when what 24 : * -------- -------- ---------------------------------------------- 25 : * pardo 24/03/09 created 26 : */ 27 : 28 : #ifndef __cplusplus 29 : #error "This is a C++ include file and cannot be used from plain C" 30 : #endif 31 : 32 : #include "ATMCommon.h" 33 : #include <string> 34 : 35 : 36 : 37 : ATM_NAMESPACE_BEGIN 38 : 39 : /*! \brief Class for those physical parameters having dimensions of Length [L] 40 : * 41 : * This class is defined for those physical parameters that have units of Length, for example 42 : * the water vapor scale height. Default units are m (International System). 43 : */ 44 : class Length 45 : { 46 : public: 47 : enum Units { 48 : UnitKiloMeter, 49 : UnitMeter, 50 : UnitMilliMeter, 51 : UnitMicron, 52 : UnitMicrons, 53 : UnitNanoMeter, 54 : NumLengthUnits 55 : }; 56 : 57 : /** Default constructor: Length value set to 0 m */ 58 : Length(); 59 : /** A full constructor: value in default units (m) */ 60 : Length(double length); 61 : /** A full constructor: value + units. Valid units are: km [KM], m [M], mm [MM], micron [MICRON], nm [NM]. */ 62 : Length(double length, const std::string &units); 63 : Length(double length, Units units); 64 : /** Copy constructor */ 65 : Length(const Length &length); 66 : 67 : /** Destructor */ 68 : virtual ~Length(); 69 : 70 : /** Accessor to get the numerical value of length (in International System units: m) */ 71 507337138 : inline double get() const { return valueIS_; } 72 : /** Accessor to the length value in specified units. Implemented units are km [KM], m [M], mm [MM], micron [MICRON], nm [NM]. 73 : * If none of these implemented units is given, the SI value will be returned. */ 74 239 : inline double get(const std::string &units) const { return sget(valueIS_, units); } 75 76425 : inline double get(const Units units) const { return sget(valueIS_, units); } 76 : /** Accessor to the length in specified units as a formatted std::string. 77 : * Implemented units are km [KM], m [M], mm [MM], micron [MICRON], nm [NM]. 78 : * If none of these implemented units is given, the SI value will be returned. */ 79 : std::string get(const std::string &form, const std::string &units) const; 80 : 81 : /** Operator "equal to a Length" */ 82 26599 : inline Length& operator=(const Length &rhs) { if(&rhs != this) valueIS_ = rhs.valueIS_; return *this; } 83 : /** Operator "equal to a double converted to Length in m" */ 84 1 : inline Length& operator=(double rhs) { valueIS_ = rhs; return *this; } 85 : /** Operator "addition of lengths" */ 86 1687 : inline Length operator+(const Length &rhs) { return Length(valueIS_ + rhs.get()); } 87 : /** Operator "substraction of lengths" */ 88 3 : inline Length operator-(const Length &rhs) { return Length(valueIS_ - rhs.get()); } 89 : /** Operator "multiplication of a length by a double" */ 90 3 : inline Length operator*(double scf) { return Length(valueIS_ * scf); } 91 : /** Operator "multiplication of a length by a float" */ 92 : inline Length operator*(float scf) { return Length(valueIS_ * (double) scf); } 93 : /** Operator "multiplication of a length by an int" */ 94 1 : inline Length operator*(int scf) { return Length(valueIS_ * (double) scf); } 95 : /** Operator "multiplication of a length by an unsigned int" */ 96 : inline Length operator*(unsigned int scf) { return Length(valueIS_ * (double) scf); } 97 : /** Operator "division of a length by a double" */ 98 2 : inline Length operator/(double scf) { return Length(valueIS_ / scf); } 99 : /** Operator "division of a length by a float" */ 100 : inline Length operator/(float scf) { return Length(valueIS_ / (double) scf); } 101 : /** Operator "division of a length by an int" */ 102 : inline Length operator/(int scf) { return Length(valueIS_ / (double) scf); } 103 : /** Operator "division of a length by an unsigned int" */ 104 : inline Length operator/(unsigned int scf) { return Length(valueIS_ / (double) scf); } 105 : /** Operator "comparator < for two lengths" */ 106 2 : inline bool operator<(const Length &rhs) const { return (valueIS_ < rhs.get()); } 107 : /** Operator "comparator > for two lengths" */ 108 : inline bool operator>(const Length &rhs) const { return (valueIS_ > rhs.get()); } 109 : /** Operator "comparator <= for two lengths" */ 110 1 : inline bool operator<=(const Length &rhs) const { return (valueIS_ <= rhs.get()); } 111 : /** Operator "comparator >= for two lengths" */ 112 1 : inline bool operator>=(const Length &rhs) const { return (valueIS_ >= rhs.get()); } 113 : /** Operator "comparator == for two lengths" */ 114 1 : inline bool operator==(const Length &rhs) const { return (valueIS_ == rhs.get()); } 115 : /** Operator "comparator != for two lengths" */ 116 1 : inline bool operator!=(const Length &rhs) const { return (valueIS_ != rhs.get()); } 117 : 118 : private: 119 : static double sget(double value, const std::string &units); 120 : static double sput(double value, const std::string &units); 121 : static double sget(double value, Units units); 122 : static double sput(double value, Units units); 123 : 124 : private: 125 : double valueIS_; 126 : }; // class Length 127 : 128 : ATM_NAMESPACE_END 129 : 130 : #endif /*!_ATM_LENGTH_H*/