diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2017-10-24 11:11:07 +0200 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-10-27 16:42:58 +0200 | 
| commit | 6d7679cf7c997237805022f828846164ff947a40 (patch) | |
| tree | bfcee7a55e18412629034ffd01d3dfd7cbade9c9 | |
| parent | 0a0000a6c4ca5ebfffd33d70f7b7963473be1471 (diff) | |
compat/mutex: split from header
| -rw-r--r-- | compat/qcopyable-mutex.cpp | 36 | ||||
| -rw-r--r-- | compat/qcopyable-mutex.hpp | 44 | 
2 files changed, 53 insertions, 27 deletions
| 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<QMutex>(datum->isRecursive() +                                     ? QMutex::Recursive +                                     : QMutex::NonRecursive); +    return *this; +} + +mutex::mutex(const mutex& datum) +{ +    *this = datum; +} + +mutex::mutex(mutex::mode m) : +    inner(std::make_unique<QMutex>(static_cast<QMutex::RecursionMode>(int(m)))) +{ +} + +QMutex* mutex::operator&() const +{ +    return *this; +} + +QMutex* mutex::operator->() const +{ +    return *this; +} + +mutex::operator QMutex*() const +{ +    return const_cast<QMutex*>(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 <QMutex> - -class MyMutex { -private: -    QMutex inner; +#include <memory> -public: -    QMutex* operator->() { return &inner; } -    QMutex* operator->() const { return &const_cast<MyMutex*>(this)->inner; } +#include <QMutex> -    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<QMutex> 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<QMutex*>(&inner); -    } +    QMutex* operator&() const; +    operator QMutex*() const; +    QMutex* operator->() const;  }; | 
