[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 5fb74f1 7/7: Prefer cents() to m()
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 5fb74f1 7/7: Prefer cents() to m() |
Date: |
Sun, 20 Sep 2020 18:51:24 -0400 (EDT) |
branch: valyuta/002
commit 5fb74f1b1ac015df0d2e3f58a7c09a7fe173e9e2
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Prefer cents() to m()
"m()" suggests that read access to a private member is being given.
"cents()" suggests that the internal state is returned as cents.
It's just a matter of connotation, but connotations matter.
Incidentally split excessively long lines--those resulting from
s/m/cents/, and one other.
---
currency.hpp | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index 3a38fda..6090009 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -109,10 +109,11 @@ class currency
// highly unlikely to overflow on multiplication by an int.
currency const& operator*=(int z) {m_ *= z; return *this;}
- data_type m() const {return m_;} // restrict to friends?
+ data_type cents() const {return m_;}
private:
- data_type from_int(int i) const {return cents_per_dollar *
bourn_cast<data_type>(i);}
+ data_type from_int(int i) const
+ {return cents_per_dollar * bourn_cast<data_type>(i);}
// Want something just slightly more permissive:
// data_type from_double(double d) const {return bourn_cast<data_type>(100.0
* d);}
// Far too permissive:
@@ -148,12 +149,18 @@ class currency
data_type m_ = {0};
};
-inline bool operator==(currency const& lhs, currency const& rhs){return
lhs.m() == rhs.m();}
-inline bool operator< (currency const& lhs, currency const& rhs){return
lhs.m() < rhs.m();}
-inline bool operator!=(currency const& lhs, currency const& rhs){return
!operator==(lhs,rhs);}
-inline bool operator> (currency const& lhs, currency const& rhs){return
operator< (rhs,lhs);}
-inline bool operator<=(currency const& lhs, currency const& rhs){return
!operator> (lhs,rhs);}
-inline bool operator>=(currency const& lhs, currency const& rhs){return
!operator< (lhs,rhs);}
+inline bool operator==(currency const& lhs, currency const& rhs)
+ {return lhs.cents() == rhs.cents();}
+inline bool operator< (currency const& lhs, currency const& rhs)
+ {return lhs.cents() < rhs.cents();}
+inline bool operator!=(currency const& lhs, currency const& rhs)
+ {return !operator==(lhs,rhs);}
+inline bool operator> (currency const& lhs, currency const& rhs)
+ {return operator< (rhs,lhs);}
+inline bool operator<=(currency const& lhs, currency const& rhs)
+ {return !operator> (lhs,rhs);}
+inline bool operator>=(currency const& lhs, currency const& rhs)
+ {return !operator< (lhs,rhs);}
inline currency operator+(currency lhs, currency rhs) {return lhs += rhs;}
inline currency operator-(currency lhs, currency rhs) {return lhs -= rhs;}
- [lmi-commits] [lmi] valyuta/002 updated (18ab8be -> 5fb74f1), Greg Chicares, 2020/09/20
- [lmi-commits] [lmi] valyuta/002 18e7015 1/7: Do away with unused return value #1, Greg Chicares, 2020/09/20
- [lmi-commits] [lmi] valyuta/002 2f32980 5/7: Do away with unused return value #5, Greg Chicares, 2020/09/20
- [lmi-commits] [lmi] valyuta/002 89b2c7a 6/7: Fix incorrect documentation, Greg Chicares, 2020/09/20
- [lmi-commits] [lmi] valyuta/002 5fb74f1 7/7: Prefer cents() to m(),
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 5447866 2/7: Do away with unused return value #2, Greg Chicares, 2020/09/20
- [lmi-commits] [lmi] valyuta/002 96435be 3/7: Do away with unused return value #3, Greg Chicares, 2020/09/20
- [lmi-commits] [lmi] valyuta/002 9419729 4/7: Do away with unused return value #4, Greg Chicares, 2020/09/20