From 6d7679cf7c997237805022f828846164ff947a40 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 24 Oct 2017 11:11:07 +0200 Subject: compat/mutex: split from header --- compat/qcopyable-mutex.cpp | 36 ++++++++++++++++++++++++++++++++++++ compat/qcopyable-mutex.hpp | 44 +++++++++++++++++--------------------------- 2 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 compat/qcopyable-mutex.cpp diff --git a/compat/qcopyable-mutex.cpp b/compat/qcopyable-mutex.cpp new file mode 100644 index 00000000..71720f17 --- /dev/null +++ b/compat/qcopyable-mutex.cpp @@ -0,0 +1,36 @@ +#include "qcopyable-mutex.hpp" + +mutex& mutex::operator=(const mutex& datum) +{ + inner = nullptr; + inner = std::make_unique(datum->isRecursive() + ? QMutex::Recursive + : QMutex::NonRecursive); + return *this; +} + +mutex::mutex(const mutex& datum) +{ + *this = datum; +} + +mutex::mutex(mutex::mode m) : + inner(std::make_unique(static_cast(int(m)))) +{ +} + +QMutex* mutex::operator&() const +{ + return *this; +} + +QMutex* mutex::operator->() const +{ + return *this; +} + +mutex::operator QMutex*() const +{ + return const_cast(inner.get()); +} + diff --git a/compat/qcopyable-mutex.hpp b/compat/qcopyable-mutex.hpp index 57b0030d..af82876d 100644 --- a/compat/qcopyable-mutex.hpp +++ b/compat/qcopyable-mutex.hpp @@ -1,37 +1,27 @@ #pragma once -#include - -class MyMutex { -private: - QMutex inner; +#include -public: - QMutex* operator->() { return &inner; } - QMutex* operator->() const { return &const_cast(this)->inner; } +#include - MyMutex operator=(const MyMutex& datum) - { - auto mode = - datum->isRecursive() - ? QMutex::Recursive - : QMutex::NonRecursive; +#include "export.hpp" - return MyMutex(mode); - } +class OTR_COMPAT_EXPORT mutex +{ + std::unique_ptr inner; - MyMutex(const MyMutex& datum) +public: + enum mode { - *this = datum; - } + recursive = QMutex::Recursive, + normal = QMutex::NonRecursive, + }; - MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) : - inner(mode) - { - } + mutex& operator=(const mutex& datum); + mutex(const mutex& datum); + mutex(mode m = normal); - QMutex* operator&() const - { - return const_cast(&inner); - } + QMutex* operator&() const; + operator QMutex*() const; + QMutex* operator->() const; }; -- cgit v1.2.3