Commit 0272a400 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Prepare for removal of boost from kdepimlibs

We still need boost in itempayloadinternals_p.h for shared_pointer_trait
and for topological_sort in typepluginloader.cpp.

I guess we can't remove the topological_sort, but that's internal. To
remove from itempayloadinternals, we need to come up with a clever
way to generate the trait only when boost is available.
parent 3e02ed50
......@@ -24,8 +24,6 @@
#include <qtest.h>
#include <QDebug>
#include <QSharedPointer>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
using namespace Akonadi;
......@@ -38,7 +36,7 @@ struct Volker {
virtual Volker *clone() const = 0;
QString who;
};
typedef boost::shared_ptr<Volker> VolkerPtr;
typedef std::shared_ptr<Volker> VolkerPtr;
typedef QSharedPointer<Volker> VolkerQPtr;
struct Rudi: public Volker {
......@@ -53,7 +51,7 @@ struct Rudi: public Volker {
}
};
typedef boost::shared_ptr<Rudi> RudiPtr;
typedef std::shared_ptr<Rudi> RudiPtr;
typedef QSharedPointer<Rudi> RudiQPtr;
struct Gerd: public Volker {
......@@ -188,7 +186,7 @@ void ItemHydra::testPointerPayload()
{
Rudi *r = new Rudi;
RudiPtr p(r);
boost::weak_ptr<Rudi> w(p);
std::weak_ptr<Rudi> w(p);
QCOMPARE(p.use_count(), (long)1);
{
......@@ -229,7 +227,7 @@ void ItemHydra::testPolymorphicPayload()
QVERIFY(!i1.hasPayload<GerdPtr>());
QCOMPARE(p.use_count(), (long)2);
{
RudiPtr p2 = boost::dynamic_pointer_cast<Rudi, Volker>(i1.payload< VolkerPtr >());
RudiPtr p2 = std::dynamic_pointer_cast<Rudi, Volker>(i1.payload< VolkerPtr >());
QCOMPARE(p.use_count(), (long)3);
QCOMPARE(p2->who, QStringLiteral("Rudi"));
}
......@@ -261,7 +259,7 @@ void ItemHydra::testNullPointerPayload()
QVERIFY(i.hasPayload());
QVERIFY(i.hasPayload<RudiPtr>());
QVERIFY(i.hasPayload<VolkerPtr>());
// Fails, because GerdPtr is std::shared_ptr, while RudiPtr is boost::shared_ptr
// Fails, because GerdPtr is std::shared_ptr, while RudiPtr is std::shared_ptr
// and we cannot do sharedptr casting for null pointers
QVERIFY(!i.hasPayload<GerdPtr>());
QCOMPARE(i.payload<RudiPtr>().get(), (Rudi *)0);
......
......@@ -26,14 +26,12 @@
#include <QtCore/QSharedPointer>
#include <QtCore/QMetaType>
#include <boost/shared_ptr.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <type_traits>
#include <typeinfo>
#include <memory>
#include <boost/shared_ptr.hpp>
#include "exception.h"
//@cond PRIVATE Doxygen 1.7.1 hangs processing this file. so skip it.
......@@ -44,6 +42,15 @@
* considered public API, and subject to change without notice
*/
// Forward-declare boost::shared_ptr so that we don't have to explicitly include
// it. Caller that tries to use it will aready have it included anyway
namespace boost
{
template<typename T> class shared_ptr;
template<typename T, typename U>
shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const &ptr) noexcept;
}
namespace Akonadi
{
namespace Internal
......@@ -132,6 +139,11 @@ struct is_shared_pointer {
static const bool value = shared_pointer_traits<T>::defined;
};
template <typename T>
struct identity {
typedef T type;
};
template <typename T>
struct get_hierarchy_root;
......@@ -142,7 +154,7 @@ struct get_hierarchy_root_recurse
template <typename T>
struct get_hierarchy_root_recurse<T, T>
: boost::mpl::identity<T> {
: identity<T> {
};
template <typename T>
......
......@@ -28,13 +28,13 @@
#include <QtCore/QMimeDatabase>
#include <QtCore/QMimeType>
#include <boost/static_assert.hpp>
using namespace Akonadi;
// ensure the role numbers are equivalent for both source models
BOOST_STATIC_ASSERT((int)AgentTypeModel::CapabilitiesRole == (int)AgentInstanceModel::CapabilitiesRole);
BOOST_STATIC_ASSERT((int)AgentTypeModel::MimeTypesRole == (int)AgentInstanceModel::MimeTypesRole);
static_assert((int)AgentTypeModel::CapabilitiesRole == (int)AgentInstanceModel::CapabilitiesRole,
"AgentTypeModel::CapabilitiesRole does not match AgentInstanceModel::CapabilitiesRole");
static_assert((int)AgentTypeModel::MimeTypesRole == (int)AgentInstanceModel::MimeTypesRole,
"AgentTypeModel::MimeTypesRole does not match AgentInstanceModel::MimeTypesRole");
/**
* @internal
......
......@@ -40,7 +40,7 @@
#include <QtCore/QStringList>
#include <QtCore/QMutexLocker>
#include <boost/bind.hpp>
#include <functional>
using namespace Akonadi;
......@@ -86,11 +86,12 @@ PasteHelperJob::PasteHelperJob(Qt::DropAction action, const Item::List &items,
setProperty("transactionsDisabled", true);
Collection dragSourceCollection;
using namespace std::placeholders;
if (!items.isEmpty() && items.first().parentCollection().isValid()) {
// Check if all items have the same parent collection ID
const Collection parent = items.first().parentCollection();
if (std::find_if(items.constBegin(), items.constEnd(),
boost::bind(&Entity::operator!=, boost::bind(static_cast<Collection(Item::*)() const>(&Item::parentCollection), _1), parent))
std::bind(&Entity::operator!=, std::bind(static_cast<Collection(Item::*)() const>(&Item::parentCollection), _1), parent))
== items.constEnd()) {
dragSourceCollection = parent;
}
......
......@@ -36,10 +36,10 @@
#include <QString>
#include <boost/bind.hpp>
#include <algorithm>
#include <type_traits>
#include <functional>
#include <cassert>
namespace Akonadi
{
......@@ -140,8 +140,11 @@ public:
}
Container<T> objects(_objects);
std::sort(objects.begin(), objects.end(), boost::bind(&T::id, _1) < boost::bind(&T::id, _2));
using namespace std::placeholders;
std::sort(objects.begin(), objects.end(),
std::bind([](Entity::Id a, Entity::Id b) -> bool { return a < b; },
std::bind(&T::id, _1),
std::bind(&T::id, _1)));
if (objects.at(0).isValid()) {
QVector<typename T::Id> uids;
uids.reserve(objects.size());
......@@ -262,10 +265,10 @@ private:
inline static
bool entitySetHasRemoteIdentifier(const Container<T> &objects, const RIDFunc &ridFunc)
{
typedef typename RIDFunc::result_type RetType;
return std::find_if(objects.constBegin(), objects.constEnd(),
boost::bind(&RetType::isEmpty, boost::bind(ridFunc, _1)))
[=](const T &obj) {
return ridFunc(obj).isEmpty();
})
== objects.constEnd();
}
......@@ -277,7 +280,9 @@ private:
QStringList rids;
rids.reserve(objects.size());
std::transform(objects.cbegin(), objects.cend(),
std::back_inserter(rids), boost::bind(ridFunc, _1));
std::back_inserter(rids), [=](const T &obj) -> QString {
return ridFunc(obj);
});
return Scope(scope, rids);
}
......@@ -289,18 +294,22 @@ private:
QStringList rids;
rids.reserve(objects.size());
std::transform(objects.cbegin(), objects.cend(),
std::back_inserter(rids), boost::bind(&QString::fromLatin1, boost::bind(ridFunc, _1)));
std::back_inserter(rids), [=](const T &obj) -> QString {
return QString::fromLatin1(ridFunc(obj));
});
return Scope(scope, rids);
}
template<typename T, template<typename> class Container>
inline static
typename std::enable_if < !std::is_same<T, Tag>::value, bool >::type
typename std::enable_if<!std::is_same<T, Tag>::value, bool>::type
entitySetHasHRID(const Container<T> &objects)
{
return objects.size() == 1 &&
std::find_if(objects.constBegin(), objects.constEnd(),
!boost::bind(static_cast<bool (*)(const T &)>(&CollectionUtils::hasValidHierarchicalRID), _1))
[](const T &obj) -> bool {
return !CollectionUtils::hasValidHierarchicalRID(obj);
})
== objects.constEnd(); // ### HRID sets are not yet specified
}
......
......@@ -35,8 +35,7 @@
#include <QtDBus>
#include <QTimer>
#include <boost/scoped_ptr.hpp>
#include <QScopedPointer>
using namespace Akonadi;
......@@ -52,7 +51,7 @@ public:
mState = instance->state();
mSafetyTimer->setSingleShot(true);
mSafetyTimer->setInterval(30000);
QObject::connect(mSafetyTimer.get(), SIGNAL(timeout()), instance, SLOT(timeout()));
QObject::connect(mSafetyTimer.data(), SIGNAL(timeout()), instance, SLOT(timeout()));
if (mState == ServerManager::Running && Internal::clientType() == Internal::User && !ServerManager::hasInstanceIdentifier()) {
mFirstRunner = new Firstrun(instance);
}
......@@ -101,9 +100,9 @@ public:
}
if (state == ServerManager::Starting || state == ServerManager::Stopping) {
QMetaObject::invokeMethod(mSafetyTimer.get(), "start", Qt::QueuedConnection); // in case we are in a different thread
QMetaObject::invokeMethod(mSafetyTimer.data(), "start", Qt::QueuedConnection); // in case we are in a different thread
} else {
QMetaObject::invokeMethod(mSafetyTimer.get(), "stop", Qt::QueuedConnection); // in case we are in a different thread
QMetaObject::invokeMethod(mSafetyTimer.data(), "stop", Qt::QueuedConnection); // in case we are in a different thread
}
}
}
......@@ -118,7 +117,7 @@ public:
ServerManager *instance;
static int serverProtocolVersion;
ServerManager::State mState;
boost::scoped_ptr<QTimer> mSafetyTimer;
QScopedPointer<QTimer> mSafetyTimer;
Firstrun *mFirstRunner;
static Internal::ClientType clientType;
};
......
......@@ -20,7 +20,6 @@
#ifndef AKONADI_SHAREDVALUEPOOL_P_H
#define AKONADI_SHAREDVALUEPOOL_P_H
#include <boost/utility/enable_if.hpp>
#include <algorithm>
namespace Akonadi
......@@ -28,22 +27,6 @@ namespace Akonadi
namespace Internal
{
/*template <typename T> class container_traits
{
private:
typedef char sizeOne;
typedef struct
{
char a[2];
} sizeTwo;
template <typename C> static sizeOne testForKeyType( typename C::key_type const* );
template <typename C> static sizeTwo testForKeyType( ... );
public:
enum {
isAssociative=sizeof(container_traits<T>::testForKeyType<T>(0))==1
};
};*/
/**
* Pool of implicitly shared values, use for optimizing memory use
* when having a large amount of copies from a small set of different values.
......@@ -53,18 +36,6 @@ class SharedValuePool
{
public:
/** Returns the shared value equal to @p value .*/
/*template <typename C>
typename boost::enable_if_c<container_traits<Container<C> >::isAssociative, C>::type sharedValue( const C &value, const int * = 0 )
{
typename Container<T>::const_iterator it = m_pool.constFind( value );
if ( it != m_pool.constEnd() )
return *it;
m_pool.insert( value );
return value;
}
template <typename C>
typename boost::disable_if_c<container_traits<Container<C> >::isAssociative, C>::type sharedValue( const C &value )*/
T sharedValue(const T &value)
{
// for small pool sizes this is actually faster than using lower_bound and a sorted vector
......
......@@ -35,8 +35,6 @@
#include <QItemSelectionModel>
#include <QPointer>
#include <boost/static_assert.hpp>
using namespace Akonadi;
//@cond PRIVATE
......@@ -63,7 +61,8 @@ static const struct {
};
static const int numAgentActionData = sizeof agentActionData / sizeof * agentActionData;
BOOST_STATIC_ASSERT(numAgentActionData == AgentActionManager::LastType);
static_assert(numAgentActionData == AgentActionManager::LastType,
"agentActionData table does not match AgentActionManager types");
/**
* @internal
......
......@@ -25,8 +25,6 @@
#include <QtCore/QPointer>
#include <QWidget>
#include <boost/scoped_ptr.hpp>
namespace Ui
{
class ErrorOverlay;
......@@ -71,7 +69,7 @@ private:
bool mPreviousState;
bool mOverlayActive;
bool mBaseWidgetIsParent;
boost::scoped_ptr<Ui::ErrorOverlay> ui;
QScopedPointer<Ui::ErrorOverlay> ui;
};
}
......
......@@ -61,7 +61,6 @@
#include <QPointer>
#include <QWeakPointer>
#include <QInputDialog>
#include <boost/static_assert.hpp>
using namespace Akonadi;
......@@ -126,7 +125,8 @@ static const struct {
};
static const int numStandardActionData = sizeof standardActionData / sizeof * standardActionData;
BOOST_STATIC_ASSERT(numStandardActionData == StandardActionManager::LastType);
static_assert(numStandardActionData == StandardActionManager::LastType,
"StandardActionData table does not match StandardActionManager types");
static bool canCreateCollection(const Akonadi::Collection &collection)
{
......
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