casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ATMPercent.h
Go to the documentation of this file.
1 #ifndef _ATM_PERCENT_H
2 #define _ATM_PERCENT_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: ATMPercent.h Exp $"
22 *
23 * who when what
24 * -------- -------- ----------------------------------------------
25 * pardo 2009-03-24 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 
38 
44 class Percent
45 {
46 public:
48  Percent();
50  Percent(double percent);
52  Percent(double percent, const std::string &units);
53 
54  ~Percent();
55 
57 
58  double get()const;
60  double get(const std::string &units)const;
62 
64  inline Percent& operator=(const Percent &rhs) { if(&rhs != this) valueIS_ = rhs.valueIS_; return *this; }
66  inline Percent& operator=(double rhs) { valueIS_ = rhs; return *this; }
68  inline Percent operator+(const Percent &rhs) { return Percent(valueIS_ + rhs.get()); }
70  inline Percent operator-(const Percent &rhs) { return Percent(valueIS_ - rhs.get()); }
72  inline Percent operator*(double scf) { return Percent(valueIS_ * scf); }
74  inline Percent operator*(float scf) { return Percent(valueIS_ * (double) scf); }
76  inline Percent operator*(int scf) { return Percent(valueIS_ * (double) scf); }
78  inline Percent operator*(unsigned int scf) { return Percent(valueIS_ * (double) scf); }
80  inline Percent operator/(double scf) { return Percent(valueIS_ / scf); }
82  inline Percent operator/(float scf) { return Percent(valueIS_ / (double) scf); }
84  inline Percent operator/(int scf) { return Percent(valueIS_ / (double) scf); }
86  inline Percent operator/(unsigned int scf) { return Percent(valueIS_ / (double) scf); }
88  inline bool operator<(const Percent &rhs) const { return (valueIS_ < rhs.get()); }
90  inline bool operator>(const Percent &rhs) const { return (valueIS_ > rhs.get()); }
92  inline bool operator<=(const Percent &rhs) const { return (valueIS_ <= rhs.get()); }
94  inline bool operator>=(const Percent &rhs) const { return (valueIS_ >= rhs.get()); }
96  inline bool operator==(const Percent &rhs) const { return (valueIS_ == rhs.get()); }
98  inline bool operator!=(const Percent &rhs) const { return (valueIS_ != rhs.get()); }
99 
100 private:
101  double valueIS_;
102 }; // class Percent
103 
105 
106 #endif
#define ATM_NAMESPACE_END
Definition: ATMCommon.h:38
Percent operator*(double scf)
Operator &quot;multiplication of a percent by a double&quot;.
Definition: ATMPercent.h:72
bool operator>=(const Percent &rhs) const
Operator &quot;comparator &gt;= for two percentages&quot;.
Definition: ATMPercent.h:94
bool operator<(const Percent &rhs) const
Operator &quot;comparator &lt; for two percentages&quot;.
Definition: ATMPercent.h:88
bool operator!=(const Percent &rhs) const
Operator &quot;comparator != for two percentages&quot;.
Definition: ATMPercent.h:98
double valueIS_
Definition: ATMPercent.h:101
Percent operator/(unsigned int scf)
Operator &quot;division of a percent by an unsigned int&quot;.
Definition: ATMPercent.h:86
Percent operator*(float scf)
Operator &quot;multiplication of a percent by a float&quot;.
Definition: ATMPercent.h:74
Percent operator*(int scf)
Operator &quot;multiplication of a percent by an int&quot;.
Definition: ATMPercent.h:76
Percent operator/(int scf)
Operator &quot;division of a percent by an int&quot;.
Definition: ATMPercent.h:84
Percent & operator=(double rhs)
Operator &quot;equal to a double converted to Percent in %&quot;.
Definition: ATMPercent.h:66
#define ATM_NAMESPACE_BEGIN
Definition: ATMCommon.h:37
Percent operator/(float scf)
Operator &quot;division of a percent by a float&quot;.
Definition: ATMPercent.h:82
Percent operator+(const Percent &rhs)
Operator &quot;addition of percentages&quot;.
Definition: ATMPercent.h:68
bool operator<=(const Percent &rhs) const
Operator &quot;comparator &lt;= for two percentages&quot;.
Definition: ATMPercent.h:92
bool operator==(const Percent &rhs) const
Operator &quot;comparator == for two percentages&quot;.
Definition: ATMPercent.h:96
Percent & operator=(const Percent &rhs)
Operator &quot;equal to a Percent&quot;.
Definition: ATMPercent.h:64
Percent operator/(double scf)
Operator &quot;division of a percent by a double&quot;.
Definition: ATMPercent.h:80
Percent()
Default constructor.
Percent operator*(unsigned int scf)
Operator &quot;multiplication of a percent by an unsigned int&quot;.
Definition: ATMPercent.h:78
bool operator>(const Percent &rhs) const
Operator &quot;comparator &gt; for two percentages&quot;.
Definition: ATMPercent.h:90
Percent operator-(const Percent &rhs)
Operator &quot;substraction of percentages&quot;.
Definition: ATMPercent.h:70
double get() const
Accessor to the percent value in International System units.
Defines a class for quantities that may be expressed in percent.
Definition: ATMPercent.h:44