Verified Commit 0119e48d authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Replace custom code by QScopedValueRollback

parent 72507fe6
......@@ -29,6 +29,7 @@
#include <QStringList>
#include <QReadWriteLock>
#include <QScopedValueRollback>
#include <algorithm>
#include <map>
......@@ -548,28 +549,6 @@ Internal::PayloadBase *Item::payloadBaseV2(int spid, int mtid) const
return d_ptr->payloadBaseImpl(spid, mtid);
}
namespace
{
class ConversionGuard
{
const bool old;
bool &b;
public:
explicit ConversionGuard(bool &b)
: old(b)
, b(b)
{
b = true;
}
~ConversionGuard()
{
b = old;
}
private:
Q_DISABLE_COPY(ConversionGuard)
};
}
bool Item::ensureMetaTypeId(int mtid) const
{
// 0. Nothing there - nothing to convert from, either
......@@ -590,7 +569,7 @@ bool Item::ensureMetaTypeId(int mtid) const
// 2. Try to create one by conversion from a different representation:
try {
const ConversionGuard guard(d_ptr->mConversionInProgress);
const QScopedValueRollback guard(d_ptr->mConversionInProgress, true);
Item converted = ItemSerializer::convert(*this, mtid);
return d_ptr->movePayloadFrom(converted.d_ptr, mtid);
} catch (const std::exception &e) {
......
......@@ -40,24 +40,22 @@ namespace _detail
template <typename T>
class clone_ptr
{
T *t;
std::unique_ptr<T> t;
public:
clone_ptr()
: t(nullptr)
{
}
explicit clone_ptr() = default;
explicit clone_ptr(T *t)
: t(t)
{
}
{}
clone_ptr(const clone_ptr &other)
: t(other.t ? other.t->clone() : nullptr)
{
}
~clone_ptr()
{
delete t;
}
clone_ptr(clone_ptr &&) noexcept = default;
~clone_ptr() = default;
clone_ptr &operator=(const clone_ptr &other)
{
if (this != &other) {
......@@ -66,52 +64,49 @@ public:
}
return *this;
}
clone_ptr &operator=(clone_ptr &&) noexcept = default;
void swap(clone_ptr &other)
{
using std::swap;
swap(t, other.t);
}
T *operator->() const
{
return get();
}
T &operator*() const
{
assert(get() != nullptr);
return *get();
}
T *get() const
{
return t;
return t.get();
}
T *release()
{
T *const r = t;
t = nullptr;
return r;
return t.release();
}
void reset(T *other = nullptr)
{
delete t;
t = other;
t.reset(other);
}
private:
struct _save_bool {
void f()
{
}
};
typedef void (_save_bool::*save_bool)();
public:
operator save_bool() const
explicit operator bool() const noexcept
{
return get() ? &_save_bool::f : nullptr;
return get() != nullptr;
}
};
template <typename T>
inline void swap(clone_ptr<T> &lhs, clone_ptr<T> &rhs)
inline void swap(clone_ptr<T> &lhs, clone_ptr<T> &rhs) noexcept
{
lhs.swap(rhs);
}
......@@ -145,7 +140,7 @@ namespace std
{
template <>
inline void swap<Akonadi::_detail::TypedPayload>(Akonadi::_detail::TypedPayload &lhs,
Akonadi::_detail::TypedPayload &rhs)
Akonadi::_detail::TypedPayload &rhs) noexcept
{
lhs.payload.swap(rhs.payload);
swap(lhs.sharedPointerId, rhs.sharedPointerId);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment