LCOV - code coverage report
Current view: top level - atmosphere/ATM - ATMFrequency.h (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 3 4 75.0 %
Date: 2023-11-02 14:27:30 Functions: 3 4 75.0 %

          Line data    Source code
       1             : #ifndef _ATM_FREQUENCY_H
       2             : #define _ATM_FREQUENCY_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: ATMFrequency.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 Defines a frequency value with units
      40             :  *
      41             :  *   Objects of type Frequency has a value in Hz (International System Units). The
      42             :  *   class Frequency allows clients to instantiate or retrieve Frequency objects with
      43             :  *   values specified in any units within a restricted set of predefined units, namely
      44             :  *   in THz, GHz, MHz, kHz or Hz. Hence units are handled only at the interface.
      45             :  *   If the units is not specified at this interface it is assumed to be Hz.
      46             :  */
      47             : 
      48             : class Frequency
      49             : {
      50             : public:
      51             :   enum Units {
      52             :     UnitHertz,
      53             :     UnitKiloHertz,
      54             :     UnitMegaHertz,
      55             :     UnitGigaHertz,
      56             :     UnitTeraHertz,
      57             :     NumFrequencyUnits
      58             :   };
      59             : 
      60             :   /** Default constructor: Frequency value set to 0 Hz */
      61             :   Frequency();
      62             :   /** A full constructor: Frequency value + units. Valid units are THz [THZ] [thz], GHz [GHZ] [ghz], MHz [MHZ] [mhz], Hz [HZ] [hz] */
      63             :   Frequency(double frequency, const std::string &units);
      64             :   Frequency(double frequency, Units units);
      65             :   /** A full constructor: Frequency value in default units (International System: Hz) */
      66             :   Frequency(double frequency);
      67             :   /** Copy constructor */
      68             :   Frequency (const Frequency &frequency);
      69             : 
      70             :   /** Destructor */
      71             :   virtual ~Frequency();
      72             : 
      73             :   /** Accessor to get the numerical value of frequency (in International System units: Hz) */
      74         104 :   inline double get() const { return valueIS_; }
      75             :   /** Accessor to the frequency value in specified units. Implemented units are THz [THZ] [thz], GHz [GHZ] [ghz], MHz [MHZ] [mhz], Hz [HZ] [hz].
      76             :    *  If none of these implemented units is given, the SI value will be returned. */
      77         588 :   inline double get(const std::string &units) const { return sget( valueIS_, units); }
      78          36 :   inline double get(Units units) const {return sget( valueIS_, units); }
      79             : 
      80             :   /** Operator "equal to a Frequency" */
      81             :   inline Frequency& operator=(const Frequency &rhs) { if(&rhs != this) valueIS_ = rhs.valueIS_; return *this; }
      82             :   /** Operator "equal to a double converted to Frequency in Hz" */
      83             :   inline Frequency& operator=(double rhs) { valueIS_ = rhs; return *this; }
      84             :   /** Operator "addition of frequencies" */
      85             :   inline Frequency operator+(const Frequency &rhs) { return Frequency(valueIS_ + rhs.get()); }
      86             :   /** Operator "subtraction of frequencies" */
      87           0 :   inline Frequency operator-(const Frequency &rhs) { return Frequency(valueIS_ - rhs.get()); }
      88             :   /* operator+= operator-= */
      89             :   /** Operator "multiplication of a frequency by a double" */
      90             :   inline Frequency operator*(double scf) { return Frequency(valueIS_ * scf); }
      91             :   /** Operator "multiplication of a frequency by a float" */
      92             :   inline Frequency operator*(float scf) { return Frequency(valueIS_ * (double) scf); }
      93             :   /** Operator "multiplication of a frequency by an int" */
      94             :   inline Frequency operator*(int scf) { return Frequency(valueIS_ * (double) scf); }
      95             :   /** Operator "multiplication of a frequency by an unsigned int" */
      96             :   inline Frequency operator*(unsigned int scf) { return Frequency(valueIS_ * (double) scf); }
      97             :   /** Operator "division of a frequency by a double" */
      98             :   inline Frequency operator/(double scf) { return Frequency(valueIS_ / scf); }
      99             :   /** Operator "division of a frequency by a float" */
     100             :   inline Frequency operator/(float scf) { return Frequency(valueIS_ / (double) scf); }
     101             :   /** Operator "division of a frequency by an int" */
     102             :   inline Frequency operator/(int scf) { return Frequency(valueIS_ / (double) scf); }
     103             :   /** Operator "division of a frequency by an unsigned int" */
     104             :   inline Frequency operator/(unsigned int scf) { return Frequency(valueIS_ / (double) scf); }
     105             :   /** Operator "comparator < for two frequencies" */
     106             :   inline bool operator<(const Frequency &rhs) const {return (valueIS_ < rhs.get()); }
     107             :   /** Operator "comparator > for two frequencies" */
     108             :   inline bool operator> (const Frequency &rhs) const {return (valueIS_ > rhs.get()); }
     109             :   /** Operator "comparator <= for two frequencies" */
     110             :   inline  bool operator<=(const Frequency &rhs) const {return (valueIS_ <= rhs.get()); }
     111             :   /** Operator "comparator >= for two frequencies" */
     112             :   inline bool operator>=(const Frequency &rhs) const {return (valueIS_ >= rhs.get()); }
     113             :   /** Operator "comparator == for two frequencies" */
     114             :   inline bool operator==(const Frequency &rhs) const {return (valueIS_ == rhs.get()); }
     115             :   /** Operator "comparator != for two frequencies" */
     116             :   inline bool operator!=(const Frequency &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 Frequency
     127             : 
     128             : ATM_NAMESPACE_END
     129             : 
     130             : #endif /*!_ATM_FREQUENCY_H*/
     131             : 

Generated by: LCOV version 1.16