From aeb95ebb3069fb0749a3c8db2c96894f7c967dab Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 4 May 2015 00:14:00 +0100 Subject: [PATCH] refs #413 Removed all policy classes. --- src/blackmisc/valueobject.h | 57 ---- src/blackmisc/valueobject_policy.h | 477 ----------------------------- 2 files changed, 534 deletions(-) delete mode 100644 src/blackmisc/valueobject_policy.h diff --git a/src/blackmisc/valueobject.h b/src/blackmisc/valueobject.h index b975b9026..4154685a4 100644 --- a/src/blackmisc/valueobject.h +++ b/src/blackmisc/valueobject.h @@ -19,7 +19,6 @@ #include "icons.h" #include "blackmiscfreefunctions.h" #include "valueobject_private.h" -#include "valueobject_policy.h" #include #include #include @@ -82,62 +81,6 @@ namespace BlackMisc ~CEmpty() = default; }; - /*! - * Default policy classes for use by CValueObject. - * - * The default policies are inherited from the policies of the base class. There is a specialization - * for the terminating case in which the base class is CEmpty. - * - * Specialize this template to use non-default policies for a particular derived class. - * Due to the void default template parameter, specializations can inherit from CValueObjectPolicy<> - * so that only the policies which differ from the default need be specified. - * Policy classes which can be used are defined in namespace BlackMisc::Policy. - */ - template struct CValueObjectPolicy - { - using MetaType = Policy::MetaType::Inherit; //!< Metatype policy - using Equals = Policy::Equals::Inherit; //!< Equals policy - using LessThan = Policy::LessThan::Inherit; //!< LessThan policy - using Compare = Policy::Compare::Inherit; //!< Compare policy - using Hash = Policy::Hash::Inherit; //!< Hash policy - using DBus = Policy::DBus::Inherit; //!< DBus policy - using Json = Policy::Json::Inherit; //!< JSON policy - using PropertyIndex = Policy::PropertyIndex::Default; //!< PropertyIndex policy - }; - - /*! - * Default policy classes for use by CValueObject. - * - * Specialization for the terminating case in which the base class is CEmpty. - */ - template <> struct CValueObjectPolicy - { - using MetaType = Policy::MetaType::Default; //!< Metatype policy - using Equals = Policy::Equals::MetaTuple; //!< Equals policy - using LessThan = Policy::LessThan::MetaTuple; //!< Less than policy - using Compare = Policy::Compare::MetaTuple; //!< Compare policy - using Hash = Policy::Hash::MetaTuple; //!< Hash policy - using DBus = Policy::DBus::MetaTuple; //!< DBus policy - using Json = Policy::Json::MetaTuple; //!< JSon policy - using PropertyIndex = Policy::PropertyIndex::Default; //!< PropertyIndex policy - }; - - /*! - * Policy classes for use by classes with incomplete migration to new CValueObject. - * - * 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 CValueObjectPolicy - { - 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 - }; - namespace Mixin { diff --git a/src/blackmisc/valueobject_policy.h b/src/blackmisc/valueobject_policy.h deleted file mode 100644 index 050a2ed7f..000000000 --- a/src/blackmisc/valueobject_policy.h +++ /dev/null @@ -1,477 +0,0 @@ -/* Copyright (C) 2014 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_VALUEOBJECT_POLICY_H -#define BLACKMISC_VALUEOBJECT_POLICY_H - -#include "tuple.h" -#include -#include - -namespace BlackMisc -{ - class CEmpty; - class CPropertyIndexList; - class CPropertyIndexVariantMap; - - template - struct CValueObjectPolicy; - - template - void registerMetaValueType(); - - namespace Policy - { - namespace Private - { - //! \private Alias for the policy of the base class of T - template - using Inherit = CValueObjectPolicy; - - //! \private - using BlackMisc::Private::EncapsulationBreaker; - } - - namespace MetaType - { - //! CValueObject registerMetadata policy which only registers with QMetaType and QtDBus - struct QMetaTypeAndDBusOnly - { - //! Register with QMetaType - template - static void registerImpl() { qRegisterMetaType(); qDBusRegisterMetaType(); } - }; - - //! CValueObject default registerMetadata policy - struct Default - { - //! Register with QMetaType - template - static void registerImpl() { QMetaTypeAndDBusOnly::registerImpl(); maybeRegisterMetaValueType(); } - - private: - // FIXME use TemplateIsBaseOf - template ::value>::type* = nullptr> - static void maybeRegisterMetaValueType() { BlackMisc::registerMetaValueType(); } - template ::value>::type* = nullptr> - static void maybeRegisterMetaValueType() {} - }; - - //! CValueObject registerMetadata policy which inherits the policy of the base class - struct Inherit - { - //! Register with QMetaType - template - static void registerImpl() { Private::Inherit::MetaType::template registerImpl(); } - }; - - //! CValueObject registerMetadata policy which also registers QList - struct DefaultAndQList - { - //! Register with QMetaType - template - static void registerImpl() { Default::registerImpl(); Default::registerImpl>(); } - }; - - //! CValueObject policy for a class which should not register itself as meta type - struct None - { - //! Register with QMetaType - template - static void registerImpl() { } - }; - } - - namespace Equals - { - //! CValueObject policy for a class which should not have an equals operator - struct None - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops {}; - }; - - //! CValueObject equals operator policy which inherits the policy of the base class - struct Inherit - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops : public CValueObjectPolicy::Equals::template Ops {}; - }; - - //! CValueObject policy for a class whose meta tuple members can be compared by the equals operator - struct MetaTuple - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops : private Private::EncapsulationBreaker - { - //! Equals operator - friend bool operator ==(const T &a, const T &b) { return Private::EncapsulationBreaker::toMetaTuple(a) == Private::EncapsulationBreaker::toMetaTuple(b) && baseEquals(a, b); } - - //! Not equals operator - friend bool operator !=(const T &a, const T &b) { return !(a == b); } - - private: - template static bool baseEquals(const U &a, const U &b) { return a == b; } - template static bool baseEquals(const CEmpty &, const CEmpty &) { return true; } - }; - }; - - //! Some classes define their own custom equals operator; this policy provides a not equals operator which simply negates the result - struct OwnEquals - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops - { - //! Not equals operator; class T already has its own equals operator - friend bool operator !=(const T &a, const T &b) { return !(a == b); } - }; - }; - - //! \private Detect the policy of T, following inheritance. - template ::Equals> struct IsMetaTuple : public std::false_type {}; - template struct IsMetaTuple : public std::true_type {}; - template struct IsMetaTuple : public IsMetaTuple {}; - } - - namespace LessThan - { - //! CValueObject policy for a class which should not have a less than operator - struct None - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops {}; - }; - - //! CValueObject less than operator policy which inherits the policy of the base class - struct Inherit - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops : public CValueObjectPolicy::LessThan::template Ops {}; - }; - - //! CValueObject policy for a class whose meta tuple members can be compared by the less than operator - struct MetaTuple - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops : private Private::EncapsulationBreaker - { - //! Less than operator - friend bool operator <(const T &a, const T &b) { return Private::EncapsulationBreaker::toMetaTuple(a) < Private::EncapsulationBreaker::toMetaTuple(b); } - - //! Greater than operator - friend bool operator >(const T &a, const T &b) { return b < a; } - - //! Greater or equal operator - friend bool operator >=(const T &a, const T &b) { return !(a < b); } - - //! Less or equal operator - friend bool operator <=(const T &a, const T &b) { return !(b < a); } - }; - }; - - //! Some classes define their own custom less than operator; this policy implements other comparison operators in terms of this one - struct OwnLessThan - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops - { - //! Greater than operator; class T already has its own less than operator - friend bool operator >(const T &a, const T &b) { return b < a; } - - //! Greater or equal operator; class T already has its own less than operator - friend bool operator >=(const T &a, const T &b) { return !(a < b); } - - //! Less or equal operator; class T already has its own less than operator - friend bool operator <=(const T &a, const T &b) { return !(b < a); } - }; - }; - - //! \private Detect the policy of T, following inheritance. - template ::LessThan> struct IsMetaTuple : public std::false_type {}; - template struct IsMetaTuple : public std::true_type {}; - template struct IsMetaTuple : public IsMetaTuple {}; - } - - namespace Compare - { - //! CValueObject policy for a class without compare() support - struct None - { - //! Inner class template which actually bestows the friend function via the Barton-Nackman trick - template - struct Ops {}; - }; - - //! CValueObject compare() policy which inherits the policy of the base class - struct Inherit - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops : public CValueObjectPolicy::Compare::template Ops {}; - }; - - //! CValueObject policy for a class with default metatuple-based compare() support - struct MetaTuple - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops : private Private::EncapsulationBreaker - { - //! compare friend function - friend int compare(const T &a, const T &b) - { - int result = BlackMisc::compare(Private::EncapsulationBreaker::toMetaTuple(a), Private::EncapsulationBreaker::toMetaTuple(b)); - return result ? result : compare(static_cast(a), static_cast(b)); - } - }; - }; - - //! CValueObject policy for a class which implements compare() in terms of the less than operator - struct LessThan - { - //! Inner class template which actually bestows the operators via the Barton-Nackman trick - template - struct Ops - { - //! compare friend function - friend int compare(const T &a, const T &b) - { - if (a < b) { return -1; } - if (b < a) { return 1; } - return 0; - } - }; - }; - - //! \private Detect the policy of T, following inheritance. - template ::Compare> struct IsMetaTuple : public std::false_type {}; - template struct IsMetaTuple : public std::true_type {}; - template struct IsMetaTuple : public IsMetaTuple {}; - } - - namespace Hash - { - //! CValueObject policy for a class without hashing support - struct None - { - //! \copydoc BlackMisc::CValueObject::getHashValue - template - static uint hashImpl(const T &) { qFatal("Not implemented"); return 0; } - }; - - //! CValueObject hashing policy which inherits the policy of the base class - struct Inherit - { - //! \copydoc BlackMisc::CValueObject::getHashValue - template - static uint hashImpl(const T &obj) { return Private::Inherit::Hash::template hashImpl(obj); } - }; - - //! CValueObject policy for a class with default metatuple-based hashing support - struct MetaTuple : private Private::EncapsulationBreaker - { - //! \copydoc BlackMisc::CValueObject::getHashValue - template - static uint hashImpl(const T &obj) { return qHash(Private::EncapsulationBreaker::toMetaTuple(obj)); } - }; - - //! CValueObject policy for a class which implements its own custom hashing support - struct Own - { - //! \copydoc BlackMisc::CValueObject::getHashValue - template - static uint hashImpl(const T &) { return 0; } - }; - - //! \private Detect the policy of T, following inheritance. - template ::Hash> struct IsMetaTuple : public std::false_type {}; - template struct IsMetaTuple : public std::true_type {}; - template struct IsMetaTuple : public IsMetaTuple {}; - } - - namespace DBus - { - //! CValueObject policy for a class without DBus marshalling support - struct None - { - //! \copydoc BlackMisc::CValueObject::marshallToDbus - template - static void marshallImpl(QDBusArgument &, const T &) { qFatal("Not implemented"); } - - //! \copydoc BlackMisc::CValueObject::unmarshallFromDbus - template - static void unmarshallImpl(const QDBusArgument &, T &) { qFatal("Not implemented"); } - }; - - //! CValueObject marshalling policy which inherits the policy of the base class - struct Inherit - { - //! \copydoc BlackMisc::CValueObject::marshallToDbus - template - static void marshallImpl(QDBusArgument &arg, const T &obj) { Private::Inherit::DBus::template marshallImpl(arg, obj); } - - //! \copydoc BlackMisc::CValueObject::unmarshallFromDbus - template - static void unmarshallImpl(const QDBusArgument &arg, T &obj) { return Private::Inherit::DBus::template unmarshallImpl(arg, obj); } - }; - - //! CValueObject policy for a class with default metatuple-based DBus marshalling support - struct MetaTuple : private Private::EncapsulationBreaker - { - //! \copydoc BlackMisc::CValueObject::marshallToDbus - template - static void marshallImpl(QDBusArgument &arg, const T &obj) { arg << Private::EncapsulationBreaker::toMetaTuple(obj); } - - //! \copydoc BlackMisc::CValueObject::unmarshallFromDbus - template - static void unmarshallImpl(const QDBusArgument &arg, T &obj) { arg >> Private::EncapsulationBreaker::toMetaTuple(obj); } - }; - - //! CValueObject policy for a class which implements its own custom DBus marshalling support - struct Own - { - //! \copydoc BlackMisc::CValueObject::marshallToDbus - template - static void marshallImpl(QDBusArgument &, const T &) {} - - //! \copydoc BlackMisc::CValueObject::unmarshallFromDbus - template - static void unmarshallImpl(const QDBusArgument &, T &) {} - }; - - //! \private Detect the policy of T, following inheritance. - template ::DBus> struct IsMetaTuple : public std::false_type {}; - template struct IsMetaTuple : public std::true_type {}; - template struct IsMetaTuple : public IsMetaTuple {}; - } - - namespace Json - { - //! CValueObject policy for a class without JSON support - struct None - { - //! \copydoc BlackMisc::serializeJson - template - static QJsonObject serializeImpl(const T &) { qFatal("Not implemented"); return {}; } - - //! \copydoc BlackMisc::deserializeJson - template - static void deserializeImpl(const QJsonObject &, T &) { qFatal("Not implemented"); } - }; - - //! CValueObject JSON policy which inherits the policy of the base class - struct Inherit - { - //! \copydoc BlackMisc::serializeJson - template - static QJsonObject serializeImpl(const T &obj) { return Private::Inherit::Json::template serializeImpl(obj); } - - //! \copydoc BlackMisc::deserializeJson - template - static void deserializeImpl(const QJsonObject &json, T &obj) { Private::Inherit::Json::template deserializeImpl(json, obj); } - }; - - //! CValueObject policy for a class with default metatuple-based JSON support - struct MetaTuple : private Private::EncapsulationBreaker - { - //! \copydoc BlackMisc::serializeJson - template - static QJsonObject serializeImpl(const T &obj) { return BlackMisc::serializeJson(Private::EncapsulationBreaker::toMetaTuple(obj)); } - - //! \copydoc BlackMisc::deserializeJson - template - static void deserializeImpl(const QJsonObject &json, T &obj) { BlackMisc::deserializeJson(json, Private::EncapsulationBreaker::toMetaTuple(obj)); } - }; - - //! CValueObject policy for a class which implements its own custom JSON support - struct Own - { - //! \copydoc BlackMisc::serializeJson - template - static QJsonObject serializeImpl(const T &) { return {}; } - - //! \copydoc BlackMisc::deserializeJson - template - static void deserializeImpl(const QJsonObject &, T &) {} - }; - - //! \private Detect the policy of T, following inheritance. - template ::Json> struct IsMetaTuple : public std::false_type {}; - template struct IsMetaTuple : public std::true_type {}; - template struct IsMetaTuple : public IsMetaTuple {}; - } - - namespace PropertyIndex - { - //! CValueObject policy for PropertyIndex related methods - struct Default - { - //! \private - template - using EnableIfEmptyBase = typename std::enable_if::value>::type *; - - //! \private - template - using DisableIfEmptyBase = typename std::enable_if::value>::type *; - - //! \copydoc CValueObject::apply - //! @{ - template - static void apply(T &obj, const CPropertyIndexVariantMap &indexMap, CPropertyIndexList &o_changed, bool skipEqualValues, DisableIfEmptyBase = nullptr) { o_changed = obj.T::base_type::apply(indexMap, skipEqualValues); } - template - static void apply(T &obj, const CPropertyIndexVariantMap &indexMap, CPropertyIndexList &o_changed, bool skipEqualValues, EnableIfEmptyBase = nullptr); // implemented in valueobject.h due to cyclic include dependency - //! @} - - //! \copydoc CValueObject::setPropertyByIndex - //! @{ - template - static void setPropertyByIndex(T &obj, const CVariant &variant, const CPropertyIndex &index, DisableIfEmptyBase = nullptr) { return obj.T::base_type::setPropertyByIndex(variant, index); } - template - static void setPropertyByIndex(T &obj, const CVariant &variant, const CPropertyIndex &index, EnableIfEmptyBase = nullptr); // implemented in valueobject.h due to cyclic include dependency - //! @} - - //! \copydoc CValueObject::propertyByIndex - //! @{ - template - static void propertyByIndex(const T &obj, const CPropertyIndex &index, CVariant &o_property, DisableIfEmptyBase = nullptr) { o_property = obj.T::base_type::propertyByIndex(index); } - template - static void propertyByIndex(const T &obj, const CPropertyIndex &index, CVariant &o_property, EnableIfEmptyBase = nullptr); // implemented in valueobject.h due to cyclic include dependency - //! @} - - //! \copydoc CValueObject::propertyByIndexAsString - //! @{ - template - static QString propertyByIndexAsString(const T &obj, const CPropertyIndex &index, bool i18n, DisableIfEmptyBase = nullptr) { return obj.T::base_type::propertyByIndexAsString(index, i18n); } - template - static QString propertyByIndexAsString(const T &obj, const CPropertyIndex &index, bool i18n, EnableIfEmptyBase = nullptr); // implemented in valueobject.h due to cyclic include dependency - //! @} - - //! \copydoc CValueObject::equalsPropertyByIndex - //! @{ - template - static bool equalsPropertyByIndex(const T &obj, const CVariant &compareValue, const CPropertyIndex &index, DisableIfEmptyBase = nullptr) { return obj.T::base_type::equalsPropertyByIndex(compareValue, index); } - template - static bool equalsPropertyByIndex(const T &obj, const CVariant &compareValue, const CPropertyIndex &index, EnableIfEmptyBase = nullptr); // implemented in valueobject.h due to cyclic include dependency - //! @} - }; - } - } -} - -#endif