From 1464d778e405f0882c996a90b93072b8a6d490e1 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Fri, 8 Nov 2024 15:40:24 +0200 Subject: [PATCH] Using lots of macros to define operators for both int24 and int types --- openVulkanoCpp/Math/Int24.hpp | 169 ++++++---------------------------- 1 file changed, 26 insertions(+), 143 deletions(-) diff --git a/openVulkanoCpp/Math/Int24.hpp b/openVulkanoCpp/Math/Int24.hpp index 5676084..e30510a 100644 --- a/openVulkanoCpp/Math/Int24.hpp +++ b/openVulkanoCpp/Math/Int24.hpp @@ -57,94 +57,25 @@ namespace OpenVulkano return *this; } - int24 operator +(const int24& val) const - { - return int24( (int)*this + (int)val ); - } +#define INT24_OPERATORS(op) \ + int24 operator op(const int24& val) const { return int24( (int)*this op (int)val ); } \ + int24 operator op(const int val) const { return int24( (int)*this op val ); } - int24 operator -(const int24& val) const - { - return int24( (int)*this - (int)val ); - } + INT24_OPERATORS(+) + INT24_OPERATORS(-) + INT24_OPERATORS(*) + INT24_OPERATORS(/) +#undef INT24_OPERATORS - int24 operator *(const int24& val) const - { - return int24( (int)*this * (int)val ); - } +#define INT24_OPERATORS(op) \ + int24& operator op##=(const int24& val ) { *this = *this op val; return *this; } \ + int24& operator op##=(const int val ) { *this = *this op val; return *this; } - int24 operator /(const int24& val) const - { - return int24( (int)*this / (int)val ); - } - - int24 operator +(const int val) const - { - return int24( (int)*this + val ); - } - - int24 operator -(const int val) const - { - return int24( (int)*this - val ); - } - - int24 operator *(const int val) const - { - return int24( (int)*this * val ); - } - - int24 operator /(const int val) const - { - return int24( (int)*this / val ); - } - - - int24& operator +=(const int24& val ) - { - *this = *this + val; - return *this; - } - - int24& operator -=(const int24& val ) - { - *this = *this - val; - return *this; - } - - int24& operator *=(const int24& val ) - { - *this = *this * val; - return *this; - } - - int24& operator /=(const int24& val ) - { - *this = *this / val; - return *this; - } - - int24& operator +=(const int val ) - { - *this = *this + val; - return *this; - } - - int24& operator -=(const int val ) - { - *this = *this - val; - return *this; - } - - int24& operator *=(const int val ) - { - *this = *this * val; - return *this; - } - - int24& operator /=(const int val ) - { - *this = *this / val; - return *this; - } + INT24_OPERATORS(+) + INT24_OPERATORS(-) + INT24_OPERATORS(*) + INT24_OPERATORS(/) +#undef INT24_OPERATORS int24 operator >>(const int val) const { @@ -183,64 +114,16 @@ namespace OpenVulkano return int24( -(int)*this ); } - bool operator ==(const int24& val) const - { - return (int)*this == (int)val; - } +#define INT24_OPERATORS(op) \ + bool operator op(const int24& val) const { return (int)*this op (int)val; } \ + bool operator op(const int val) const { return (int)*this op val; } - bool operator !=(const int24& val) const - { - return (int)*this != (int)val; - } - - bool operator >=(const int24& val) const - { - return (int)*this >= (int)val; - } - - bool operator <=(const int24& val) const - { - return (int)*this <= (int)val; - } - - bool operator >(const int24& val) const - { - return (int)*this > (int)val; - } - - bool operator <(const int24& val) const - { - return (int)*this < (int)val; - } - - bool operator ==(const int val) const - { - return (int)*this == val; - } - - bool operator !=(const int val) const - { - return (int)*this != val; - } - - bool operator >=(const int val) const - { - return (int)*this >= val; - } - - bool operator <=(const int val) const - { - return (int)*this <= val; - } - - bool operator >(const int val) const - { - return ((int)*this) > val; - } - - bool operator <(const int val) const - { - return (int)*this < val; - } + INT24_OPERATORS(==) + INT24_OPERATORS(!=) + INT24_OPERATORS(>=) + INT24_OPERATORS(<=) + INT24_OPERATORS(>) + INT24_OPERATORS(<) +#undef INT24_OPERATORS }; } \ No newline at end of file