mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
refs #356 Update remaining CValueObject derived classes to use CValueObjectStdTuple instead.
This commit is contained in:
@@ -42,12 +42,29 @@ namespace BlackMisc
|
||||
static QString stringify(QString str, bool /*i18n*/) { return str; }
|
||||
};
|
||||
|
||||
// forward declaration
|
||||
template <template <class> class C, class T, class CIt>
|
||||
class CContainerBase;
|
||||
|
||||
//! \private
|
||||
template <template <class> class C, class T, class CIt>
|
||||
struct CValueObjectStdTuplePolicy<CContainerBase<C, T, CIt>> : public CValueObjectLegacy
|
||||
{};
|
||||
|
||||
/*!
|
||||
* \brief Base class for CCollection and CSequence adding mutating operations and CValueObject facility on top of CRangeBase.
|
||||
*/
|
||||
template <template <class> class C, class T, class CIt>
|
||||
class CContainerBase : public CValueObject, public CRangeBase<C<T>, CIt>
|
||||
class CContainerBase : public CValueObjectStdTuple<CContainerBase<C, T, CIt>>, public CRangeBase<C<T>, CIt>
|
||||
{
|
||||
//! \copydoc BlackMisc::CValueObject::compare
|
||||
friend int compare(const C<T> &a, const C<T> &b)
|
||||
{
|
||||
if (a.size() < b.size()) { return -1; }
|
||||
if (a.size() > b.size()) { return 1; }
|
||||
return std::lexicographical_compare(a.cbegin(), a.cend(), b.cbegin(), b.cend());
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Return a new container of a different type, containing the same elements as this one.
|
||||
@@ -127,7 +144,7 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
protected: // CValueObject overrides
|
||||
protected: // CValueObjectStdTuple overrides
|
||||
//! \copydoc BlackMisc::CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override
|
||||
{
|
||||
@@ -140,27 +157,6 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::CValueObject::getMetaTypeId
|
||||
virtual int getMetaTypeId() const override { return qMetaTypeId<C<T>>(); }
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::isA
|
||||
virtual bool isA(int metaTypeId) const override
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<C<T>>()) { return true; }
|
||||
return CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override
|
||||
{
|
||||
const auto &o = static_cast<const CContainerBase &>(other);
|
||||
if (derived().size() < o.derived().size()) { return -1; }
|
||||
if (derived().size() > o.derived().size()) { return 1; }
|
||||
//for (auto i1 = derived().cbegin(), i2 = o.derived().cbegin(); i1 != derived().cend() && i2 != o.derived().cend(); ++i1, ++i2)
|
||||
//{
|
||||
// if (*i1 < *i2) { return -1; }
|
||||
// if (*i1 > *i2) { return 1; }
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override
|
||||
{
|
||||
|
||||
@@ -74,10 +74,26 @@ namespace BlackMisc
|
||||
struct AssociativityTraits : public Private::AssociativityTraits<Private::ADL::SupportsQHash<Key>::value, Private::ADL::SupportsQMap<Key>::value>
|
||||
{};
|
||||
|
||||
//! Associative container with value semantics, chooses a sensible default implementation container type
|
||||
// forward declaration
|
||||
template<class Key, class Value, template <class...> class Impl = AssociativityTraits<Key>::template DefaultType>
|
||||
class CDictionary : public CValueObject
|
||||
class CDictionary;
|
||||
|
||||
//! \private
|
||||
template <class Key, class Value, template <class...> class Impl>
|
||||
struct CValueObjectStdTuplePolicy<CDictionary<Key, Value, Impl>> : public CValueObjectLegacy
|
||||
{};
|
||||
|
||||
//! Associative container with value semantics, chooses a sensible default implementation container type
|
||||
template<class Key, class Value, template <class...> class Impl /*= AssociativityTraits<Key>::template DefaultType*/>
|
||||
class CDictionary : public CValueObjectStdTuple<CDictionary<Key, Value, Impl>>
|
||||
{
|
||||
//! \copydoc BlackMisc::CValueObject::compare
|
||||
friend int compare(const CDictionary &a, const CDictionary &b)
|
||||
{
|
||||
if (a.m_impl.size() < b.m_impl.size()) { return -1; }
|
||||
if (a.m_impl.size() > b.m_impl.size()) { return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
//! The implementation container
|
||||
@@ -408,22 +424,6 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::CValueObject::getMetaTypeId
|
||||
virtual int getMetaTypeId() const override { return qMetaTypeId<CDictionary>(); }
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::isA
|
||||
virtual bool isA(int metaTypeId) const override
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CDictionary>()) { return true; }
|
||||
return CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override
|
||||
{
|
||||
const auto &o = static_cast<const CDictionary &>(other);
|
||||
if (m_impl.size() < o.m_impl.size()) { return -1; }
|
||||
if (m_impl.size() > o.m_impl.size()) { return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override
|
||||
{
|
||||
|
||||
@@ -117,24 +117,6 @@ namespace BlackMisc
|
||||
return qMetaTypeId<CPropertyIndexVariantMap>();
|
||||
}
|
||||
|
||||
/*
|
||||
* is a
|
||||
*/
|
||||
bool CPropertyIndexVariantMap::isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CPropertyIndexVariantMap>()) { return true; }
|
||||
return this->CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CPropertyIndexVariantMap::compareImpl(const CValueObject &/*otherBase*/) const
|
||||
{
|
||||
qFatal("not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshall to DBus
|
||||
*/
|
||||
|
||||
@@ -27,12 +27,16 @@ namespace BlackMisc
|
||||
// forward declaration
|
||||
class CPropertyIndex;
|
||||
class CPropertyIndexList;
|
||||
class CPropertyIndexVariantMap;
|
||||
|
||||
//! \private
|
||||
template <> struct CValueObjectStdTuplePolicy<CPropertyIndexVariantMap> : public CValueObjectLegacy {};
|
||||
|
||||
/*!
|
||||
* Specialized value object compliant map for variants,
|
||||
* based on indexes
|
||||
*/
|
||||
class CPropertyIndexVariantMap : public CValueObject
|
||||
class CPropertyIndexVariantMap : public CValueObjectStdTuple<CPropertyIndexVariantMap>
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -155,12 +159,6 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::getMetaTypeId
|
||||
virtual int getMetaTypeId() const override;
|
||||
|
||||
//! \copydoc CValueObject::isA
|
||||
virtual bool isA(int metaTypeId) const override;
|
||||
|
||||
//! \copydoc CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override;
|
||||
|
||||
//! \copydoc CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
|
||||
@@ -168,6 +168,22 @@ namespace BlackMisc
|
||||
using PropertyIndex = Policy::PropertyIndex::Default; //!< PropertyIndex policy
|
||||
};
|
||||
|
||||
/*!
|
||||
* Policy classes for use by classes with incomplete migration to CValueObjectStdTuple.
|
||||
*
|
||||
* This is to make it easier to apply the necessary changes to these classes for #356.
|
||||
* \todo Remove this and finish migrating classes that use it.
|
||||
*/
|
||||
struct CValueObjectLegacy : public CValueObjectStdTuplePolicy<CEmpty>
|
||||
{
|
||||
using Equals = Policy::Equals::None; //!< Equals policy
|
||||
using LessThan = Policy::LessThan::None; //!< Less than policy
|
||||
using Compare = Policy::Compare::None; //!< Compare policy
|
||||
using Hash = Policy::Hash::Own; //!< Hash policy
|
||||
using DBus = Policy::DBus::Own; //!< DBus policy
|
||||
using Json = Policy::Json::Own; //!< JSon policy
|
||||
};
|
||||
|
||||
/*!
|
||||
* Standard implementation of CValueObject using meta tuple system.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user