refactor: Change lib::domain::Book qty type to float
This commit is contained in:
1 parent
72edd99cb0
commit
b1d1243eae
1 file changed
+30
-30
+30
-30
@@ -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 <cstdint>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace bts::domain {
|
||||
|
||||
using Quantity = utils::ValueWrapper<struct QuantityTag, std::uint32_t>;
|
||||
using Quantity = utils::ValueWrapper<struct QuantityTag, float>;
|
||||
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user