summaryrefslogtreecommitdiff
path: root/modules/core/c++/abstract/data.hpp
blob: 327fb63e7037f30a4ce466afb385c575ef2ed410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once

#include "schema.hpp"
#include "encode.hpp"

namespace kel {
namespace lbm {
template<typename Schema, typename Encode = enc::Native>
class data final {};

template<typename T, uint64_t N>
class data<sch::Primitive<T,N>,Encode> final {
public:
	using Schema = sch::Primitive<T,N>;
	using Encode = Encode;
private:
	native_data_type<Schema>::type value_;
public:
	data():
		value_{}
	{}

	data(native_data_type<Schema>::type value__):
		value_{value__}
	{}

	constexpr auto get() const {
		return value_;
	}

	void set(native_data_type value__){
		value_ = value__;
	}

	constexpr bool operator==(const data<Schema,Encode>& rhs) const {
		return value_ == rhs.value_;
	}
	
	constexpr bool operator!=(const data<Schema,Encode>& rhs) const {
		return value_ != rhs.value_;
	}
	
	constexpr bool operator>(const data<Schema,Encode>& rhs) const {
		return value_ > rhs.value_;
	}
	
	constexpr bool operator<(const data<Schema,Encode>& rhs) const {
		return value_ < rhs.value_;
	}
	
	constexpr bool operator>=(const data<Schema,Encode>& rhs) const {
		return value_ >= rhs.value_;
	}
	
	constexpr bool operator<=(const data<Schema,Encode>& rhs) const {
		return value_ >= rhs.value_;
	}
	
	constexpr bool equals(const data<Schema,Encode>& rhs) const {
		return (*this) == rhs;
	}

	data<Schema,Encode> operator+(const data<Schema,Encode>& rhs) const {
		return {value_ + rhs.value_};
	}
	
	data<Schema,Encode> operator-(const data<Schema,Encode>& rhs) const {
		return {value_ - rhs.value_};
	}
	
	data<Schema,Encode> operator*(const data<Schema,Encode>& rhs) const {
		return {value_ * rhs.value_};
	}
	
	data<Schema,Encode> operator/(const data<Schema,Encode>& rhs) const {
		return {value_ / rhs.value_};
	}
	
	data<Schema,Encode>& operator+=(const data<Schema,Encode>& rhs) {
		value_ += rhs.value_;
		return *this
	}
	
	data<Schema,Encode>& operator-=(const data<Schema,Encode>& rhs) {
		value_ -= rhs.value_;
		return *this
	}
	
	data<Schema,Encode>& operator*=(const data<Schema,Encode>& rhs) {
		value_ *= rhs.value_;
		return *this
	}
	
	data<Schema,Encode>& operator/=(const data<Schema,Encode>& rhs) {
		value_ /= rhs.value_;
		return *this
	}

	template<typename T>
	data<T,Encode> cast_to() const {
		data<T,Encode> val{static_cast<typename native_data_type<T>::type>(value_)};
		return val;
	}
};


}
}