From c1d352270add2f205d038d7e4f69c1b4f35f014d Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 19 Jun 2024 11:59:04 +0200 Subject: Added operators to MixedPrecision native class --- modules/codec/c++/data.hpp | 80 ++++++++++++++++++++++++++++++++++++++------ modules/codec/c++/schema.hpp | 3 ++ 2 files changed, 73 insertions(+), 10 deletions(-) (limited to 'modules/codec/c++') diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp index 79f5264..8e0e029 100644 --- a/modules/codec/c++/data.hpp +++ b/modules/codec/c++/data.hpp @@ -88,46 +88,58 @@ private: template class data, encode::Native, storage::Default> { +public: + using Schema = schema::Primitive; private: - typename native_data_type>::type value_; + typename native_data_type::type value_; public: data():value_{}{} SAW_DEFAULT_COPY(data); SAW_DEFAULT_MOVE(data); - data(typename native_data_type>::type value__): + data(typename native_data_type::type value__): value_{std::move(value__)}{} - void set(typename native_data_type>::type val){ + void set(typename native_data_type::type val){ value_ = val; } - typename native_data_type>::type get() const {return value_;} + typename native_data_type::type get() const {return value_;} - data, encode::Native, storage::Default> operator*(const data, encode::Native, storage::Default>& rhs)const{ + data operator*(const data& rhs)const{ return {get() * rhs.get()}; } - data, encode::Native, storage::Default> operator/(const data, encode::Native, storage::Default>& rhs)const{ + data operator/(const data& rhs)const{ return {get() / rhs.get()}; } - data, encode::Native, storage::Default> operator+(const data, encode::Native, storage::Default>& rhs)const{ + data operator+(const data& rhs)const{ return {get() + rhs.get()}; } + + data& operator+=(const data& rhs)const{ + value_ += rhs.get(); + return *this; + } + + data& operator-=(const data& rhs)const{ + value_ -= rhs.get(); + return *this; + } - data, encode::Native, storage::Default> operator-(const data, encode::Native, storage::Default>& rhs)const{ + data operator-(const data& rhs)const{ return {get() - rhs.get()}; } template - bool operator==(const data, Enc>& rhs)const{ + bool operator==(const data& rhs)const{ return get() == rhs.get(); } template - bool operator<(const data, Enc>& rhs) const { + bool operator<(const data& rhs) const { return get() < rhs.get(); } @@ -162,6 +174,54 @@ public: void set(typename saw::native_data_type::type val){ value_.set(val.template cast_to().get()); } + + data operator*(const data& rhs) const { + using CalcType = typename native_data_type::type; + CalcType left = static_cast(value_.get()); + CalcType right = static_cast(rhs.get()); + return {left * right}; + } + + data operator/(const data& rhs)const{ + using CalcType = typename native_data_type::type; + CalcType left = static_cast(value_.get()); + CalcType right = static_cast(rhs.get()); + return {left / right}; + } + + data operator+(const data& rhs)const{ + using CalcType = typename native_data_type::type; + CalcType left = static_cast(value_.get()); + CalcType right = static_cast(rhs.get()); + return {left + right}; + } + + data& operator+=(const data& rhs)const{ + *this = *this + rhs.get(); + return *this; + } + + data operator-(const data& rhs)const{ + using CalcType = typename native_data_type::type; + CalcType left = static_cast(value_.get()); + CalcType right = static_cast(rhs.get()); + return {left - right}; + } + + data& operator-=(const data& rhs) const { + *this = *this - rhs.get(); + return *this; + } + + template + bool operator==(const data& rhs)const{ + return get() == rhs.get(); + } + + template + bool operator<(const data& rhs) const { + return get() < rhs.get(); + } }; /** diff --git a/modules/codec/c++/schema.hpp b/modules/codec/c++/schema.hpp index 5a2f440..2ef7c77 100644 --- a/modules/codec/c++/schema.hpp +++ b/modules/codec/c++/schema.hpp @@ -88,6 +88,9 @@ template struct Primitive { (std::is_same_v && (N == 4 || N == 8)), "Primitive Type is not supported"); static constexpr string_literal name = "Primitive"; + + using InterfaceSchema = Primitive; + using StorageSchema = Primitive; }; using Int8 = Primitive; -- cgit v1.2.3