mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
45 lines
691 B
C++
45 lines
691 B
C++
|
#pragma once
|
||
|
|
||
|
#include <mutex>
|
||
|
|
||
|
template <typename T>
|
||
|
class ReceivedMessage
|
||
|
{
|
||
|
mutable std::mutex mutex;
|
||
|
|
||
|
bool isSet{false};
|
||
|
T t;
|
||
|
|
||
|
public:
|
||
|
ReceivedMessage() = default;
|
||
|
|
||
|
explicit operator bool() const
|
||
|
{
|
||
|
std::unique_lock lock(this->mutex);
|
||
|
|
||
|
return this->isSet;
|
||
|
}
|
||
|
|
||
|
ReceivedMessage &operator=(const T &newT)
|
||
|
{
|
||
|
std::unique_lock lock(this->mutex);
|
||
|
|
||
|
this->isSet = true;
|
||
|
this->t = newT;
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
bool operator==(const T &otherT) const
|
||
|
{
|
||
|
std::unique_lock lock(this->mutex);
|
||
|
|
||
|
return this->t == otherT;
|
||
|
}
|
||
|
|
||
|
const T *operator->() const
|
||
|
{
|
||
|
return &this->t;
|
||
|
}
|
||
|
};
|