From b1d1243eaeff286cbc6f0e05cdcba9dd0ddf93ca Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 13 Apr 2023 17:50:49 +0000 Subject: [PATCH] refactor: Change lib::domain::Book qty type to float --- src/lib/domain/Quantity.h | 60 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/lib/domain/Quantity.h b/src/lib/domain/Quantity.h index b42423a10..75bfdb029 100644 --- a/src/lib/domain/Quantity.h +++ b/src/lib/domain/Quantity.h @@ -1,47 +1,47 @@ #pragma once +#include "lib/io/JsonReader.h" #include "lib/logging/logging.h" #include "lib/utils/ValueWrapper.h" -#include "lib/io/JsonReader.h" #include #include namespace bts::domain { -using Quantity = utils::ValueWrapper; +using Quantity = utils::ValueWrapper; constexpr Quantity operator+(Quantity, Quantity); constexpr Quantity operator-(Quantity, Quantity); constexpr Quantity operator*(Quantity, Quantity); constexpr Quantity operator/(Quantity, Quantity); -constexpr Quantity operator%(Quantity, Quantity); +// constexpr Quantity operator%(Quantity, Quantity); constexpr Quantity &operator+=(Quantity &, Quantity); constexpr Quantity &operator-=(Quantity &, Quantity); constexpr Quantity &operator*=(Quantity &, Quantity); constexpr Quantity &operator/=(Quantity &, Quantity); -constexpr Quantity &operator%=(Quantity &, Quantity); +// constexpr Quantity &operator%=(Quantity &, Quantity); -constexpr bool operator==(Quantity, std::uint32_t); -constexpr bool operator!=(Quantity, std::uint32_t); -constexpr bool operator<(Quantity, std::uint32_t); -constexpr bool operator<=(Quantity, std::uint32_t); -constexpr bool operator>(Quantity, std::uint32_t); -constexpr bool operator>=(Quantity, std::uint32_t); +constexpr bool operator==(Quantity, Quantity::Value); +constexpr bool operator!=(Quantity, Quantity::Value); +constexpr bool operator<(Quantity, Quantity::Value); +constexpr bool operator<=(Quantity, Quantity::Value); +constexpr bool operator>(Quantity, Quantity::Value); +constexpr bool operator>=(Quantity, Quantity::Value); -constexpr Quantity operator+(Quantity, std::uint32_t); -constexpr Quantity operator-(Quantity, std::uint32_t); -constexpr Quantity operator*(Quantity, std::uint32_t); -constexpr Quantity operator/(Quantity, std::uint32_t); +constexpr Quantity operator+(Quantity, Quantity::Value); +constexpr Quantity operator-(Quantity, Quantity::Value); +constexpr Quantity operator*(Quantity, Quantity::Value); +constexpr Quantity operator/(Quantity, Quantity::Value); -Quantity &operator+=(Quantity &, std::uint32_t); -Quantity &operator-=(Quantity &, std::uint32_t); -Quantity &operator*=(Quantity &, std::uint32_t); -Quantity &operator/=(Quantity &, std::uint32_t); +Quantity &operator+=(Quantity &, Quantity::Value); +Quantity &operator-=(Quantity &, Quantity::Value); +Quantity &operator*=(Quantity &, Quantity::Value); +Quantity &operator/=(Quantity &, Quantity::Value); -std::uint32_t &operator+=(std::uint32_t &, Quantity); -std::uint32_t &operator-=(std::uint32_t &, Quantity); -std::uint32_t &operator*=(std::uint32_t &, Quantity); -std::uint32_t &operator/=(std::uint32_t &, Quantity); +Quantity::Value &operator+=(Quantity::Value &, Quantity); +Quantity::Value &operator-=(Quantity::Value &, Quantity); +Quantity::Value &operator*=(Quantity::Value &, Quantity); +Quantity::Value &operator/=(Quantity::Value &, Quantity); ////////////////////////////////////////////////// // Definition @@ -75,19 +75,19 @@ inline void to_json(nlohmann::json &j, const Quantity &sec_id) { } #define QTY_UINT32_BIN_OP(result_t, op) \ - constexpr result_t operator op(Quantity lhs, std::uint32_t rhs) { \ + constexpr result_t operator op(Quantity lhs, Quantity::Value rhs) { \ return result_t(lhs.value() op rhs); /*NOLINT*/ \ } \ - constexpr result_t operator op(std::uint32_t lhs, Quantity rhs) { \ + constexpr result_t operator op(Quantity::Value lhs, Quantity rhs) { \ return result_t(lhs op rhs.value()); \ } #define QTY_UINT32_BIN_REF_OP(op) \ - inline Quantity &operator op(Quantity &lhs, std::uint32_t rhs) { \ + inline Quantity &operator op(Quantity &lhs, Quantity::Value rhs) { \ lhs.value() op rhs; \ return lhs; \ } \ - inline std::uint32_t &operator op(std::uint32_t &lhs, Quantity rhs) { \ + inline Quantity::Value &operator op(Quantity::Value &lhs, Quantity rhs) { \ lhs op rhs.value(); \ return lhs; \ } @@ -96,13 +96,13 @@ QTY_QTY_BIN_OP(Quantity, +) QTY_QTY_BIN_OP(Quantity, -) QTY_QTY_BIN_OP(Quantity, *) QTY_QTY_BIN_OP(Quantity, /) -QTY_QTY_BIN_OP(Quantity, %) +// QTY_QTY_BIN_OP(Quantity, %) QTY_QTY_BIN_REF_OP(+=) QTY_QTY_BIN_REF_OP(-=) QTY_QTY_BIN_REF_OP(*=) QTY_QTY_BIN_REF_OP(/=) -QTY_QTY_BIN_REF_OP(%=) +// QTY_QTY_BIN_REF_OP(%=) QTY_UINT32_BIN_OP(bool, !=) QTY_UINT32_BIN_OP(bool, ==) @@ -115,13 +115,13 @@ QTY_UINT32_BIN_OP(Quantity, +) QTY_UINT32_BIN_OP(Quantity, -) QTY_UINT32_BIN_OP(Quantity, *) QTY_UINT32_BIN_OP(Quantity, /) -QTY_UINT32_BIN_OP(Quantity, %) +// QTY_UINT32_BIN_OP(Quantity, %) QTY_UINT32_BIN_REF_OP(+=) QTY_UINT32_BIN_REF_OP(-=) QTY_UINT32_BIN_REF_OP(*=) QTY_UINT32_BIN_REF_OP(/=) -QTY_UINT32_BIN_REF_OP(%=) +// QTY_UINT32_BIN_REF_OP(%=) #undef QTY_QTY_BIN_OP #undef QTY_QTY_BIN_REF_OP