Line data Source code
1 : /******************************************************************************* 2 : * ALMA - Atacama Large Millimiter Array 3 : * (c) Instituto de Estructura de la Materia, 2009 4 : * 5 : * This library is free software; you can redistribute it and/or 6 : * modify it under the terms of the GNU Lesser General Public 7 : * License as published by the Free Software Foundation; either 8 : * version 2.1 of the License, or (at your option) any later version. 9 : * 10 : * This library is distributed in the hope that it will be useful, 11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 : * Lesser General Public License for more details. 14 : * 15 : * You should have received a copy of the GNU Lesser General Public 16 : * License along with this library; if not, write to the Free Software 17 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 : * 19 : * "@(#) $Id: ATMPercent.cpp Exp $" 20 : * 21 : * who when what 22 : * -------- -------- ---------------------------------------------- 23 : * pardo 24/03/09 created 24 : */ 25 : 26 : #include "ATMPercent.h" 27 : 28 : 29 : 30 : ATM_NAMESPACE_BEGIN 31 : 32 : // Constructors 33 : 34 4797 : Percent::Percent() : valueIS_(0.001){} // Default humidity 0.1 % 35 : 36 : // Percent::Percent(double percent) : valueIS_(percent){} 37 : 38 0 : Percent::Percent(double percent){ 39 0 : if(percent <= 0.0){ 40 0 : valueIS_=0.001; 41 : }else{ 42 0 : valueIS_=percent/100.0; 43 : } 44 0 : } 45 : 46 0 : Percent::Percent(double percent, const std::string &units){ 47 0 : if(units == "%" || units == "percent" || units == "PERCENT"){ 48 0 : valueIS_ = percent / 100.0; 49 : } else { 50 : // Exception: Unknown percent unit 51 0 : valueIS_ = percent; 52 : } 53 : 54 0 : if(valueIS_ <= 0.0){valueIS_=0.001;} // default humidity 0.1 % 55 : 56 0 : } 57 : 58 2658 : Percent::Percent(double percent, Percent::Units units) { 59 2658 : if (units == Percent::UnitPercent) { 60 2658 : valueIS_ = percent / 100.0; 61 : } else { 62 : // Exception: Unknown percent unit 63 0 : valueIS_ = percent; 64 : } 65 : 66 2658 : if(valueIS_ <= 0.0){valueIS_=0.001;} // default humidity 0.1 % 67 2658 : } 68 : 69 : // Destructor 70 8386 : Percent::~Percent(){} 71 : 72 : // Accessors 73 129 : double Percent::get()const{return valueIS_;} 74 0 : double Percent::get(const std::string &units)const{ 75 0 : if(units == "%" || units == "percent" || units == "PERCENT"){ 76 0 : return valueIS_ * 100.0; 77 : } else { 78 : // Exception: Unknown percent unit 79 0 : return valueIS_; 80 : } 81 : } 82 2681 : double Percent::get(Percent::Units units)const{ 83 2681 : if(units == Percent::UnitPercent){ 84 2681 : return valueIS_ * 100.0; 85 : } else { 86 : // Exception: Unknown percent unit 87 0 : return valueIS_; 88 : } 89 : } 90 : 91 : ATM_NAMESPACE_END