worked on Image

This commit is contained in:
fourtf
2018-08-06 18:25:47 +02:00
parent c2e2dfb577
commit 35d462d1f1
15 changed files with 284 additions and 302 deletions
-8
View File
@@ -37,12 +37,4 @@ std::weak_ptr<T> weakOf(T *element)
return element->shared_from_this();
}
template <class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts>
overloaded(Ts...)->overloaded<Ts...>;
} // namespace chatterino
+1 -1
View File
@@ -25,7 +25,7 @@ public:
return element_;
}
typename std::add_lvalue_reference<T>::type &operator*() const
typename std::add_lvalue_reference<T>::type operator*() const
{
assert(this->hasElement());
+25 -11
View File
@@ -1,47 +1,61 @@
#pragma once
#include <boost/noncopyable.hpp>
#include <mutex>
#include <type_traits>
namespace chatterino {
template <typename T>
class AccessGuard : boost::noncopyable
class AccessGuard
{
public:
AccessGuard(T &element, std::mutex &mutex)
: element_(element)
, mutex_(mutex)
: element_(&element)
, mutex_(&mutex)
{
this->mutex_.lock();
this->mutex_->lock();
}
AccessGuard(AccessGuard<T> &&other)
: element_(other.element_)
, mutex_(other.mutex_)
{
other.isValid_ = false;
}
AccessGuard<T> &operator=(AccessGuard<T> &&other)
{
other.isValid_ = false;
this->element_ = other.element_;
this->mutex_ = other.element_;
}
~AccessGuard()
{
this->mutex_.unlock();
if (this->isValid_) this->mutex_->unlock();
}
T *operator->() const
{
return &this->element_;
return this->element_;
}
T &operator*() const
{
return this->element_;
return *this->element_;
}
private:
T &element_;
std::mutex &mutex_;
T *element_;
std::mutex *mutex_;
bool isValid_ = true;
};
template <typename T>
class UniqueAccess
{
public:
// template <typename X = decltype(T())>
// template <typename X = decltype(T())>
UniqueAccess()
: element_(T())
{