fix: don't use forward-declared Ptr types in meta/
This would cause ODR violations when those headers were included in other places that also included stuff like "Version.h" (note the "meta/Version.h"), which can cause problems, especially in LTO. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
@ -24,7 +24,7 @@ Index::Index(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
Index::Index(const QVector<VersionListPtr> &lists, QObject *parent)
|
||||
Index::Index(const QVector<VersionList::Ptr> &lists, QObject *parent)
|
||||
: QAbstractListModel(parent), m_lists(lists)
|
||||
{
|
||||
for (int i = 0; i < m_lists.size(); ++i)
|
||||
@ -41,7 +41,7 @@ QVariant Index::data(const QModelIndex &index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
VersionListPtr list = m_lists.at(index.row());
|
||||
VersionList::Ptr list = m_lists.at(index.row());
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
@ -81,9 +81,9 @@ bool Index::hasUid(const QString &uid) const
|
||||
return m_uids.contains(uid);
|
||||
}
|
||||
|
||||
VersionListPtr Index::get(const QString &uid)
|
||||
VersionList::Ptr Index::get(const QString &uid)
|
||||
{
|
||||
VersionListPtr out = m_uids.value(uid, nullptr);
|
||||
VersionList::Ptr out = m_uids.value(uid, nullptr);
|
||||
if(!out)
|
||||
{
|
||||
out = std::make_shared<VersionList>(uid);
|
||||
@ -92,7 +92,7 @@ VersionListPtr Index::get(const QString &uid)
|
||||
return out;
|
||||
}
|
||||
|
||||
VersionPtr Index::get(const QString &uid, const QString &version)
|
||||
Version::Ptr Index::get(const QString &uid, const QString &version)
|
||||
{
|
||||
auto list = get(uid);
|
||||
return list->getVersion(version);
|
||||
@ -105,7 +105,7 @@ void Index::parse(const QJsonObject& obj)
|
||||
|
||||
void Index::merge(const std::shared_ptr<Index> &other)
|
||||
{
|
||||
const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
|
||||
const QVector<VersionList::Ptr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
|
||||
// initial load, no need to merge
|
||||
if (m_lists.isEmpty())
|
||||
{
|
||||
@ -120,7 +120,7 @@ void Index::merge(const std::shared_ptr<Index> &other)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const VersionListPtr &list : lists)
|
||||
for (const VersionList::Ptr &list : lists)
|
||||
{
|
||||
if (m_uids.contains(list->uid()))
|
||||
{
|
||||
@ -138,7 +138,7 @@ void Index::merge(const std::shared_ptr<Index> &other)
|
||||
}
|
||||
}
|
||||
|
||||
void Index::connectVersionList(const int row, const VersionListPtr &list)
|
||||
void Index::connectVersionList(const int row, const VersionList::Ptr &list)
|
||||
{
|
||||
connect(list.get(), &VersionList::nameChanged, this, [this, row]()
|
||||
{
|
||||
|
@ -19,20 +19,19 @@
|
||||
#include <memory>
|
||||
|
||||
#include "BaseEntity.h"
|
||||
#include "meta/VersionList.h"
|
||||
|
||||
class Task;
|
||||
|
||||
namespace Meta
|
||||
{
|
||||
using VersionListPtr = std::shared_ptr<class VersionList>;
|
||||
using VersionPtr = std::shared_ptr<class Version>;
|
||||
|
||||
class Index : public QAbstractListModel, public BaseEntity
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Index(QObject *parent = nullptr);
|
||||
explicit Index(const QVector<VersionListPtr> &lists, QObject *parent = nullptr);
|
||||
explicit Index(const QVector<VersionList::Ptr> &lists, QObject *parent = nullptr);
|
||||
|
||||
enum
|
||||
{
|
||||
@ -49,21 +48,21 @@ public:
|
||||
QString localFilename() const override { return "index.json"; }
|
||||
|
||||
// queries
|
||||
VersionListPtr get(const QString &uid);
|
||||
VersionPtr get(const QString &uid, const QString &version);
|
||||
VersionList::Ptr get(const QString &uid);
|
||||
Version::Ptr get(const QString &uid, const QString &version);
|
||||
bool hasUid(const QString &uid) const;
|
||||
|
||||
QVector<VersionListPtr> lists() const { return m_lists; }
|
||||
QVector<VersionList::Ptr> lists() const { return m_lists; }
|
||||
|
||||
public: // for usage by parsers only
|
||||
void merge(const std::shared_ptr<Index> &other);
|
||||
void parse(const QJsonObject &obj) override;
|
||||
|
||||
private:
|
||||
QVector<VersionListPtr> m_lists;
|
||||
QHash<QString, VersionListPtr> m_uids;
|
||||
QVector<VersionList::Ptr> m_lists;
|
||||
QHash<QString, VersionList::Ptr> m_uids;
|
||||
|
||||
void connectVersionList(const int row, const VersionListPtr &list);
|
||||
void connectVersionList(const int row, const VersionList::Ptr &list);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,11 @@ MetadataVersion currentFormatVersion()
|
||||
static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
|
||||
{
|
||||
const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages");
|
||||
QVector<VersionListPtr> lists;
|
||||
QVector<VersionList::Ptr> lists;
|
||||
lists.reserve(objects.size());
|
||||
std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj)
|
||||
{
|
||||
VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid"));
|
||||
VersionList::Ptr list = std::make_shared<VersionList>(requireString(obj, "uid"));
|
||||
list->setName(ensureString(obj, "name", QString()));
|
||||
return list;
|
||||
});
|
||||
@ -49,9 +49,9 @@ static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
|
||||
}
|
||||
|
||||
// Version
|
||||
static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
|
||||
static Version::Ptr parseCommonVersion(const QString &uid, const QJsonObject &obj)
|
||||
{
|
||||
VersionPtr version = std::make_shared<Version>(uid, requireString(obj, "version"));
|
||||
Version::Ptr version = std::make_shared<Version>(uid, requireString(obj, "version"));
|
||||
version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000);
|
||||
version->setType(ensureString(obj, "type", QString()));
|
||||
version->setRecommended(ensureBoolean(obj, QString("recommended"), false));
|
||||
@ -63,9 +63,9 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
|
||||
return version;
|
||||
}
|
||||
|
||||
static std::shared_ptr<Version> parseVersionInternal(const QJsonObject &obj)
|
||||
static Version::Ptr parseVersionInternal(const QJsonObject &obj)
|
||||
{
|
||||
VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj);
|
||||
Version::Ptr version = parseCommonVersion(requireString(obj, "uid"), obj);
|
||||
|
||||
version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj),
|
||||
QString("%1/%2.json").arg(version->uid(), version->version()),
|
||||
@ -74,12 +74,12 @@ static std::shared_ptr<Version> parseVersionInternal(const QJsonObject &obj)
|
||||
}
|
||||
|
||||
// Version list / package
|
||||
static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &obj)
|
||||
static VersionList::Ptr parseVersionListInternal(const QJsonObject &obj)
|
||||
{
|
||||
const QString uid = requireString(obj, "uid");
|
||||
|
||||
const QVector<QJsonObject> versionsRaw = requireIsArrayOf<QJsonObject>(obj, "versions");
|
||||
QVector<VersionPtr> versions;
|
||||
QVector<Version::Ptr> versions;
|
||||
versions.reserve(versionsRaw.size());
|
||||
std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [uid](const QJsonObject &vObj)
|
||||
{
|
||||
@ -88,7 +88,7 @@ static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &
|
||||
return version;
|
||||
});
|
||||
|
||||
VersionListPtr list = std::make_shared<VersionList>(uid);
|
||||
VersionList::Ptr list = std::make_shared<VersionList>(uid);
|
||||
list->setName(ensureString(obj, "name", QString()));
|
||||
list->setVersions(versions);
|
||||
return list;
|
||||
|
@ -54,7 +54,7 @@ void Meta::Version::parse(const QJsonObject& obj)
|
||||
parseVersion(obj, this);
|
||||
}
|
||||
|
||||
void Meta::Version::mergeFromList(const Meta::VersionPtr& other)
|
||||
void Meta::Version::mergeFromList(const Meta::Version::Ptr& other)
|
||||
{
|
||||
if(other->m_providesRecommendations)
|
||||
{
|
||||
@ -85,7 +85,7 @@ void Meta::Version::mergeFromList(const Meta::VersionPtr& other)
|
||||
}
|
||||
}
|
||||
|
||||
void Meta::Version::merge(const VersionPtr &other)
|
||||
void Meta::Version::merge(const Version::Ptr &other)
|
||||
{
|
||||
mergeFromList(other);
|
||||
if(other->m_data)
|
||||
|
@ -30,13 +30,14 @@
|
||||
|
||||
namespace Meta
|
||||
{
|
||||
using VersionPtr = std::shared_ptr<class Version>;
|
||||
|
||||
class Version : public QObject, public BaseVersion, public BaseEntity
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public: /* con/des */
|
||||
public:
|
||||
using Ptr = std::shared_ptr<Version>;
|
||||
|
||||
explicit Version(const QString &uid, const QString &version);
|
||||
virtual ~Version();
|
||||
|
||||
@ -78,8 +79,8 @@ public: /* con/des */
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
void merge(const VersionPtr &other);
|
||||
void mergeFromList(const VersionPtr &other);
|
||||
void merge(const Version::Ptr &other);
|
||||
void mergeFromList(const Version::Ptr &other);
|
||||
void parse(const QJsonObject &obj) override;
|
||||
|
||||
QString localFilename() const override;
|
||||
@ -113,4 +114,4 @@ private:
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Meta::VersionPtr)
|
||||
Q_DECLARE_METATYPE(Meta::Version::Ptr)
|
||||
|
@ -40,7 +40,7 @@ bool VersionList::isLoaded()
|
||||
return BaseEntity::isLoaded();
|
||||
}
|
||||
|
||||
const BaseVersionPtr VersionList::at(int i) const
|
||||
const BaseVersion::Ptr VersionList::at(int i) const
|
||||
{
|
||||
return m_versions.at(i);
|
||||
}
|
||||
@ -52,7 +52,7 @@ int VersionList::count() const
|
||||
void VersionList::sortVersions()
|
||||
{
|
||||
beginResetModel();
|
||||
std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b)
|
||||
std::sort(m_versions.begin(), m_versions.end(), [](const Version::Ptr &a, const Version::Ptr &b)
|
||||
{
|
||||
return *a.get() < *b.get();
|
||||
});
|
||||
@ -66,7 +66,7 @@ QVariant VersionList::data(const QModelIndex &index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
VersionPtr version = m_versions.at(index.row());
|
||||
Version::Ptr version = m_versions.at(index.row());
|
||||
|
||||
switch (role)
|
||||
{
|
||||
@ -129,9 +129,9 @@ QString VersionList::humanReadable() const
|
||||
return m_name.isEmpty() ? m_uid : m_name;
|
||||
}
|
||||
|
||||
VersionPtr VersionList::getVersion(const QString &version)
|
||||
Version::Ptr VersionList::getVersion(const QString &version)
|
||||
{
|
||||
VersionPtr out = m_lookup.value(version, nullptr);
|
||||
Version::Ptr out = m_lookup.value(version, nullptr);
|
||||
if(!out)
|
||||
{
|
||||
out = std::make_shared<Version>(m_uid, version);
|
||||
@ -143,7 +143,7 @@ VersionPtr VersionList::getVersion(const QString &version)
|
||||
bool VersionList::hasVersion(QString version) const
|
||||
{
|
||||
auto ver = std::find_if(m_versions.constBegin(), m_versions.constEnd(),
|
||||
[&](Meta::VersionPtr const& a){ return a->version() == version; });
|
||||
[&](Meta::Version::Ptr const& a){ return a->version() == version; });
|
||||
return (ver != m_versions.constEnd());
|
||||
}
|
||||
|
||||
@ -153,11 +153,11 @@ void VersionList::setName(const QString &name)
|
||||
emit nameChanged(name);
|
||||
}
|
||||
|
||||
void VersionList::setVersions(const QVector<VersionPtr> &versions)
|
||||
void VersionList::setVersions(const QVector<Version::Ptr> &versions)
|
||||
{
|
||||
beginResetModel();
|
||||
m_versions = versions;
|
||||
std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b)
|
||||
std::sort(m_versions.begin(), m_versions.end(), [](const Version::Ptr &a, const Version::Ptr &b)
|
||||
{
|
||||
return a->rawTime() > b->rawTime();
|
||||
});
|
||||
@ -168,7 +168,7 @@ void VersionList::setVersions(const QVector<VersionPtr> &versions)
|
||||
}
|
||||
|
||||
// FIXME: this is dumb, we have 'recommended' as part of the metadata already...
|
||||
auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const VersionPtr &ptr) { return ptr->type() == "release"; });
|
||||
auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const Version::Ptr &ptr) { return ptr->type() == "release"; });
|
||||
m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt;
|
||||
endResetModel();
|
||||
}
|
||||
@ -179,7 +179,7 @@ void VersionList::parse(const QJsonObject& obj)
|
||||
}
|
||||
|
||||
// FIXME: this is dumb, we have 'recommended' as part of the metadata already...
|
||||
static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const Meta::VersionPtr &b)
|
||||
static const Meta::Version::Ptr &getBetterVersion(const Meta::Version::Ptr &a, const Meta::Version::Ptr &b)
|
||||
{
|
||||
if(!a)
|
||||
return b;
|
||||
@ -194,7 +194,7 @@ static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const
|
||||
return (a->type() == "release" ? a : b);
|
||||
}
|
||||
|
||||
void VersionList::mergeFromIndex(const VersionListPtr &other)
|
||||
void VersionList::mergeFromIndex(const VersionList::Ptr &other)
|
||||
{
|
||||
if (m_name != other->m_name)
|
||||
{
|
||||
@ -202,7 +202,7 @@ void VersionList::mergeFromIndex(const VersionListPtr &other)
|
||||
}
|
||||
}
|
||||
|
||||
void VersionList::merge(const VersionListPtr &other)
|
||||
void VersionList::merge(const VersionList::Ptr &other)
|
||||
{
|
||||
if (m_name != other->m_name)
|
||||
{
|
||||
@ -216,7 +216,7 @@ void VersionList::merge(const VersionListPtr &other)
|
||||
{
|
||||
qWarning() << "Empty list loaded ...";
|
||||
}
|
||||
for (const VersionPtr &version : other->m_versions)
|
||||
for (const Version::Ptr &version : other->m_versions)
|
||||
{
|
||||
// we already have the version. merge the contents
|
||||
if (m_lookup.contains(version->version()))
|
||||
@ -235,7 +235,7 @@ void VersionList::merge(const VersionListPtr &other)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void VersionList::setupAddedVersion(const int row, const VersionPtr &version)
|
||||
void VersionList::setupAddedVersion(const int row, const Version::Ptr &version)
|
||||
{
|
||||
// FIXME: do not disconnect from everythin, disconnect only the lambdas here
|
||||
version->disconnect();
|
||||
@ -244,7 +244,7 @@ void VersionList::setupAddedVersion(const int row, const VersionPtr &version)
|
||||
connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); });
|
||||
}
|
||||
|
||||
BaseVersionPtr VersionList::getRecommended() const
|
||||
BaseVersion::Ptr VersionList::getRecommended() const
|
||||
{
|
||||
return m_recommended;
|
||||
}
|
||||
|
@ -20,10 +20,10 @@
|
||||
#include <QJsonObject>
|
||||
#include <memory>
|
||||
|
||||
#include "meta/Version.h"
|
||||
|
||||
namespace Meta
|
||||
{
|
||||
using VersionPtr = std::shared_ptr<class Version>;
|
||||
using VersionListPtr = std::shared_ptr<class VersionList>;
|
||||
|
||||
class VersionList : public BaseVersionList, public BaseEntity
|
||||
{
|
||||
@ -33,6 +33,8 @@ class VersionList : public BaseVersionList, public BaseEntity
|
||||
public:
|
||||
explicit VersionList(const QString &uid, QObject *parent = nullptr);
|
||||
|
||||
using Ptr = std::shared_ptr<VersionList>;
|
||||
|
||||
enum Roles
|
||||
{
|
||||
UidRole = Qt::UserRole + 100,
|
||||
@ -43,11 +45,11 @@ public:
|
||||
|
||||
Task::Ptr getLoadTask() override;
|
||||
bool isLoaded() override;
|
||||
const BaseVersionPtr at(int i) const override;
|
||||
const BaseVersion::Ptr at(int i) const override;
|
||||
int count() const override;
|
||||
void sortVersions() override;
|
||||
|
||||
BaseVersionPtr getRecommended() const override;
|
||||
BaseVersion::Ptr getRecommended() const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
RoleList providesRoles() const override;
|
||||
@ -65,38 +67,38 @@ public:
|
||||
}
|
||||
QString humanReadable() const;
|
||||
|
||||
VersionPtr getVersion(const QString &version);
|
||||
Version::Ptr getVersion(const QString &version);
|
||||
bool hasVersion(QString version) const;
|
||||
|
||||
QVector<VersionPtr> versions() const
|
||||
QVector<Version::Ptr> versions() const
|
||||
{
|
||||
return m_versions;
|
||||
}
|
||||
|
||||
public: // for usage only by parsers
|
||||
void setName(const QString &name);
|
||||
void setVersions(const QVector<VersionPtr> &versions);
|
||||
void merge(const VersionListPtr &other);
|
||||
void mergeFromIndex(const VersionListPtr &other);
|
||||
void setVersions(const QVector<Version::Ptr> &versions);
|
||||
void merge(const VersionList::Ptr &other);
|
||||
void mergeFromIndex(const VersionList::Ptr &other);
|
||||
void parse(const QJsonObject &obj) override;
|
||||
|
||||
signals:
|
||||
void nameChanged(const QString &name);
|
||||
|
||||
protected slots:
|
||||
void updateListData(QList<BaseVersionPtr>) override
|
||||
void updateListData(QList<BaseVersion::Ptr>) override
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
QVector<VersionPtr> m_versions;
|
||||
QHash<QString, VersionPtr> m_lookup;
|
||||
QVector<Version::Ptr> m_versions;
|
||||
QHash<QString, Version::Ptr> m_lookup;
|
||||
QString m_uid;
|
||||
QString m_name;
|
||||
|
||||
VersionPtr m_recommended;
|
||||
Version::Ptr m_recommended;
|
||||
|
||||
void setupAddedVersion(const int row, const VersionPtr &version);
|
||||
void setupAddedVersion(const int row, const Version::Ptr &version);
|
||||
};
|
||||
}
|
||||
Q_DECLARE_METATYPE(Meta::VersionListPtr)
|
||||
Q_DECLARE_METATYPE(Meta::VersionList::Ptr)
|
||||
|
Reference in New Issue
Block a user