mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
60 lines
870 B
C++
60 lines
870 B
C++
#pragma once
|
|
|
|
namespace chatterino {
|
|
|
|
template <typename T>
|
|
class NullablePtr
|
|
{
|
|
public:
|
|
NullablePtr()
|
|
: element_(nullptr)
|
|
{
|
|
}
|
|
|
|
NullablePtr(T *element)
|
|
: element_(element)
|
|
{
|
|
}
|
|
|
|
T *operator->() const
|
|
{
|
|
assert(this->hasElement());
|
|
|
|
return element_;
|
|
}
|
|
|
|
T &operator*() const
|
|
{
|
|
assert(this->hasElement());
|
|
|
|
return *element_;
|
|
}
|
|
|
|
T *get() const
|
|
{
|
|
assert(this->hasElement());
|
|
|
|
return this->element_;
|
|
}
|
|
|
|
bool isNull() const
|
|
{
|
|
return this->element_ == nullptr;
|
|
}
|
|
|
|
bool hasElement() const
|
|
{
|
|
return this->element_ != nullptr;
|
|
}
|
|
|
|
operator bool() const
|
|
{
|
|
return this->hasElement();
|
|
}
|
|
|
|
private:
|
|
T *element_;
|
|
};
|
|
|
|
} // namespace chatterino
|