StormByte C++ Library 0.0.9999
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
arithmetic_mutexed.hxx
1#pragma once
2
3#include <StormByte/visibility.h>
4#include <StormByte/mutexed.hxx>
5
13namespace StormByte {
14 template<typename T>
15 class STORMBYTE_PUBLIC ArithmeticMutexed final: public Mutexed<T> {
16 public:
20 ArithmeticMutexed() noexcept = default;
21
26 ArithmeticMutexed(const T& value) noexcept {
27 std::lock_guard<std::mutex> lock(this->m_mutex);
28 this->m_value = value;
29 }
30
35 ArithmeticMutexed(T&& value) noexcept {
36 std::lock_guard<std::mutex> lock(this->m_mutex);
37 this->m_value = std::move(value);
38 }
39
44 ArithmeticMutexed(const ArithmeticMutexed& other) noexcept = default;
45
50 ArithmeticMutexed(ArithmeticMutexed&& other) noexcept = default;
51
56 ArithmeticMutexed& operator=(const ArithmeticMutexed& other) noexcept = default;
57
62 ArithmeticMutexed& operator=(ArithmeticMutexed&& other) noexcept = default;
63
68 ArithmeticMutexed& operator=(const T& value) noexcept override {
69 std::lock_guard<std::mutex> lock(this->m_mutex);
70 this->m_value = value;
71 return *this;
72 }
73
78 ArithmeticMutexed& operator=(T&& value) noexcept override {
79 std::lock_guard<std::mutex> lock(this->m_mutex);
80 this->m_value = std::move(value);
81 return *this;
82 }
83
89 std::strong_ordering operator<=>(const ArithmeticMutexed& other) const noexcept {
90 return Mutexed<T>::operator<=>(other);
91 }
92
98 bool operator!=(const ArithmeticMutexed& other) const noexcept {
99 return operator<=>(other) != std::strong_ordering::equal;
100 }
101
107 ArithmeticMutexed operator+(const ArithmeticMutexed& value) const noexcept {
108 std::lock_guard<std::mutex> lock(this->m_mutex);
109 std::lock_guard<std::mutex> lock_other(value.m_mutex);
110 return ArithmeticMutexed(this->m_value + value.m_value);
111 }
112
119 std::lock_guard<std::mutex> lock(this->m_mutex);
120 std::lock_guard<std::mutex> lock_other(value.m_mutex);
121 return ArithmeticMutexed(this->m_value + std::move(value.m_value));
122 }
123
130 std::lock_guard<std::mutex> lock(this->m_mutex);
131 std::lock_guard<std::mutex> lock_other(value.m_mutex);
132 this->m_value += value.m_value;
133 return *this;
134 }
135
142 std::lock_guard<std::mutex> lock(this->m_mutex);
143 std::lock_guard<std::mutex> lock_other(value.m_mutex);
144 this->m_value += std::move(value.m_value);
145 return *this;
146 }
147
153 T operator+(const T& value) const noexcept {
154 std::lock_guard<std::mutex> lock(this->m_mutex);
155 return this->m_value + value;
156 }
157
163 T operator+(T&& value) const noexcept {
164 std::lock_guard<std::mutex> lock(this->m_mutex);
165 return this->m_value + std::move(value);
166 }
167
173 T& operator+=(T& value) noexcept {
174 std::lock_guard<std::mutex> lock(this->m_mutex);
175 this->m_value += value;
176 return this->m_value;
177 }
178
184 T& operator+=(T&& value) noexcept {
185 std::lock_guard<std::mutex> lock(this->m_mutex);
186 this->m_value += std::move(value);
187 return this->m_value;
188 }
189 };
190}
Definition arithmetic_mutexed.hxx:15
ArithmeticMutexed operator+(const ArithmeticMutexed &value) const noexcept
Definition arithmetic_mutexed.hxx:107
std::strong_ordering operator<=>(const ArithmeticMutexed &other) const noexcept
Definition arithmetic_mutexed.hxx:89
ArithmeticMutexed & operator=(ArithmeticMutexed &&other) noexcept=default
ArithmeticMutexed & operator=(const T &value) noexcept override
Definition arithmetic_mutexed.hxx:68
bool operator!=(const ArithmeticMutexed &other) const noexcept
Definition arithmetic_mutexed.hxx:98
T operator+(const T &value) const noexcept
Definition arithmetic_mutexed.hxx:153
ArithmeticMutexed & operator=(T &&value) noexcept override
Definition arithmetic_mutexed.hxx:78
T operator+(T &&value) const noexcept
Definition arithmetic_mutexed.hxx:163
ArithmeticMutexed & operator=(const ArithmeticMutexed &other) noexcept=default
ArithmeticMutexed operator+(ArithmeticMutexed &&value) const noexcept
Definition arithmetic_mutexed.hxx:118
ArithmeticMutexed & operator+=(ArithmeticMutexed &value) noexcept
Definition arithmetic_mutexed.hxx:129
ArithmeticMutexed(T &&value) noexcept
Definition arithmetic_mutexed.hxx:35
T & operator+=(T &&value) noexcept
Definition arithmetic_mutexed.hxx:184
ArithmeticMutexed(ArithmeticMutexed &&other) noexcept=default
ArithmeticMutexed & operator+=(ArithmeticMutexed &&value) noexcept
Definition arithmetic_mutexed.hxx:141
T & operator+=(T &value) noexcept
Definition arithmetic_mutexed.hxx:173
ArithmeticMutexed(const ArithmeticMutexed &other) noexcept=default
ArithmeticMutexed() noexcept=default
Definition mutexed.hxx:14
Main namespace for the StormByte library.