LCOV - code coverage report
Current view: top level - atmosphere/ATM - ATMPercent.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 19 28 67.9 %
Date: 2024-10-10 11:40:37 Functions: 7 8 87.5 %

          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          21 :   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           5 :   Percent::Percent(double percent, const std::string &units){
      47           5 :     if(units == "%" || units == "percent" || units == "PERCENT"){
      48           5 :       valueIS_ = percent / 100.0;
      49             :     } else {
      50             :       // Exception: Unknown percent unit
      51           0 :       valueIS_ = percent;
      52             :     }
      53             : 
      54           5 :     if(valueIS_ <= 0.0){valueIS_=0.001;}    // default humidity 0.1 %
      55             : 
      56           5 :   }
      57             : 
      58         130 :   Percent::Percent(double percent, Percent::Units units) {
      59         130 :     if (units == Percent::UnitPercent) {
      60         130 :       valueIS_ = percent / 100.0;
      61             :     } else {
      62             :       // Exception: Unknown percent unit
      63           0 :       valueIS_ = percent;
      64             :     }
      65             : 
      66         130 :     if(valueIS_ <= 0.0){valueIS_=0.001;}    // default humidity 0.1 %
      67         130 :   }
      68             : 
      69             :   // Destructor
      70         161 :   Percent::~Percent(){}
      71             : 
      72             :   // Accessors
      73         360 :   double Percent::get()const{return valueIS_;}
      74           4 :   double Percent::get(const std::string &units)const{
      75           4 :     if(units == "%" || units == "percent" || units == "PERCENT"){
      76           4 :       return valueIS_ * 100.0;
      77             :     } else {
      78             :       // Exception: Unknown percent unit
      79           0 :       return valueIS_;
      80             :     }
      81             :   }
      82         250 :   double Percent::get(Percent::Units units)const{
      83         250 :     if(units == Percent::UnitPercent){
      84         250 :       return valueIS_ * 100.0;
      85             :     } else {
      86             :       // Exception: Unknown percent unit
      87           0 :       return valueIS_;
      88             :     }
      89             :   }
      90             : 
      91             : ATM_NAMESPACE_END

Generated by: LCOV version 1.16