From 31c33b4b8d759515b531e8c474b35b8aaa85cc80 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 16 Mar 2015 18:37:05 +0000 Subject: [PATCH] refs #356 Removed CValueObject and expanded CValueObjectStdTuple to compensate. * Involves rearranging some header includes to break cyclic include dependencies, * Adding a new, simple base class CEmpty, * Removing any remaining polymorphic uses of CValueObject with templates, * Adding a new trait for use with enable_if to restrict templates to work only with value objects, * Replacing the polymorphic/runtime multimethod-based compare functions with static/compile-time compare functions. --- src/blackmisc/collection.h | 2 + src/blackmisc/containerbase.h | 1 - src/blackmisc/icon.cpp | 1 + src/blackmisc/icon.h | 7 +- src/blackmisc/iconlist.h | 1 - src/blackmisc/logmessage.h | 3 +- src/blackmisc/propertyindex.h | 3 +- src/blackmisc/propertyindexlist.h | 2 + src/blackmisc/propertyindexvariantmap.cpp | 32 -- src/blackmisc/propertyindexvariantmap.h | 12 +- src/blackmisc/sequence.h | 2 + src/blackmisc/tuple_private.h | 22 +- src/blackmisc/valueobject.cpp | 197 +------ src/blackmisc/valueobject.h | 607 ++++++++++++---------- src/blackmisc/valueobject_policy.h | 128 ++--- src/blackmisc/valueobject_private.h | 25 +- src/blackmisc/variant.h | 11 +- 17 files changed, 440 insertions(+), 616 deletions(-) diff --git a/src/blackmisc/collection.h b/src/blackmisc/collection.h index dc1643957..3c34800d9 100644 --- a/src/blackmisc/collection.h +++ b/src/blackmisc/collection.h @@ -9,6 +9,8 @@ //! \file +#include "valueobject.h" // outside include guard due to cyclic dependency hack (MS) + #ifndef BLACKMISC_COLLECTION_H #define BLACKMISC_COLLECTION_H diff --git a/src/blackmisc/containerbase.h b/src/blackmisc/containerbase.h index 77d3acebc..ab7a55f04 100644 --- a/src/blackmisc/containerbase.h +++ b/src/blackmisc/containerbase.h @@ -12,7 +12,6 @@ #ifndef BLACKMISC_CONTAINERBASE_H #define BLACKMISC_CONTAINERBASE_H -#include "valueobject.h" #include "range.h" #include "propertyindexvariantmap.h" #include "blackmiscfreefunctions.h" diff --git a/src/blackmisc/icon.cpp b/src/blackmisc/icon.cpp index 381270289..5cb221147 100644 --- a/src/blackmisc/icon.cpp +++ b/src/blackmisc/icon.cpp @@ -8,6 +8,7 @@ */ #include "icon.h" +#include "pqangle.h" namespace BlackMisc { diff --git a/src/blackmisc/icon.h b/src/blackmisc/icon.h index 903c6a0a3..7b01c49fd 100644 --- a/src/blackmisc/icon.h +++ b/src/blackmisc/icon.h @@ -12,12 +12,17 @@ #ifndef BLACKMISC_ICON_H #define BLACKMISC_ICON_H +#include "valueobject.h" #include "icons.h" -#include "pqangle.h" #include namespace BlackMisc { + namespace PhysicalQuantities + { + class CAngle; + } + //! Value object for icons. An icon is stored in the global icon repository and //! identified by its index. It contains no(!) pyhsical data for the icon itself. class CIcon : public CValueObjectStdTuple diff --git a/src/blackmisc/iconlist.h b/src/blackmisc/iconlist.h index 4085e1e1f..95f29b411 100644 --- a/src/blackmisc/iconlist.h +++ b/src/blackmisc/iconlist.h @@ -12,7 +12,6 @@ #ifndef BLACKMISC_ICONLIST_H #define BLACKMISC_ICONLIST_H -#include "valueobject.h" #include "sequence.h" #include "collection.h" #include "icon.h" diff --git a/src/blackmisc/logmessage.h b/src/blackmisc/logmessage.h index 0afc8341e..214f0825a 100644 --- a/src/blackmisc/logmessage.h +++ b/src/blackmisc/logmessage.h @@ -137,7 +137,8 @@ namespace BlackMisc CLogMessage &operator <<(QChar v) { return arg(v); } CLogMessage &operator <<(char v) { return arg(QChar(v)); } CLogMessage &operator <<(double v) { return arg(QString::number(v)); } - CLogMessage &operator <<(const CValueObject &v) { return arg(v.toQString()); } + template ::value>::type> + CLogMessage &operator <<(const T &v) { return arg(v.toQString()); } //! @} //! Sends a verbatim, preformatted message to the log. diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index ce49abdcd..69645e31c 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -9,10 +9,11 @@ //! \file +#include "valueobject.h" // outside include guard due to cyclic dependency hack (MS) + #ifndef BLACKMISC_PROPERTYINDEX_H #define BLACKMISC_PROPERTYINDEX_H -#include "valueobject.h" #include "blackmiscfreefunctions.h" #include diff --git a/src/blackmisc/propertyindexlist.h b/src/blackmisc/propertyindexlist.h index 343d1b8d6..da54b74e7 100644 --- a/src/blackmisc/propertyindexlist.h +++ b/src/blackmisc/propertyindexlist.h @@ -9,6 +9,8 @@ //! \file +#include "valueobject.h" // outside include guard due to cyclic dependency hack (MS) + #ifndef BLACKMISC_PROPERTYINDEXLIST_H #define BLACKMISC_PROPERTYINDEXLIST_H diff --git a/src/blackmisc/propertyindexvariantmap.cpp b/src/blackmisc/propertyindexvariantmap.cpp index 01495603b..afb62c12f 100644 --- a/src/blackmisc/propertyindexvariantmap.cpp +++ b/src/blackmisc/propertyindexvariantmap.cpp @@ -84,38 +84,6 @@ namespace BlackMisc return !(valueMap == variant); } - /* - * Compare with CValueObject - */ - bool operator==(const CPropertyIndexVariantMap &indexMap, const CValueObject &valueObject) - { - return indexMap == valueObject.toCVariant(); - } - - /* - * Compare with CValueObject - */ - bool operator!=(const CPropertyIndexVariantMap &indexMap, const CValueObject &valueObject) - { - return !(indexMap == valueObject); - } - - /* - * Compare with CValueObject - */ - bool operator==(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap) - { - return valueMap == valueObject; - } - - /* - * Compare with CValueObject - */ - bool operator!=(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap) - { - return !(valueMap == valueObject); - } - /* * Convert to string */ diff --git a/src/blackmisc/propertyindexvariantmap.h b/src/blackmisc/propertyindexvariantmap.h index 17bd20062..f63573a8d 100644 --- a/src/blackmisc/propertyindexvariantmap.h +++ b/src/blackmisc/propertyindexvariantmap.h @@ -111,19 +111,23 @@ namespace BlackMisc //! Operator == with CValueObject //! \todo Still needed? - friend bool operator ==(const CPropertyIndexVariantMap &valueMap, const CValueObject &valueObject); + template ::value>::type> + friend bool operator ==(const CPropertyIndexVariantMap &valueMap, const T &valueObject) { return valueMap == CVariant::from(valueObject); } //! Operator != with CValueObject //! \todo Still needed? - friend bool operator !=(const CPropertyIndexVariantMap &valueMap, const CValueObject &valueObject); + template ::value>::type> + friend bool operator !=(const CPropertyIndexVariantMap &valueMap, const T &valueObject) { return valueMap != CVariant::from(valueObject); } //! Operator == with CValueObject //! \todo Still needed? - friend bool operator ==(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap); + template ::value>::type> + friend bool operator ==(const T &valueObject, const CPropertyIndexVariantMap &valueMap) { return valueMap == CVariant::from(valueObject); } //! Operator != with CValueObject //! \todo Still needed? - friend bool operator !=(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap); + template ::value>::type> + friend bool operator !=(const T &valueObject, const CPropertyIndexVariantMap &valueMap) { return valueMap != CVariant::from(valueObject); } //! Map const QMap &map() const { return this->m_values; } diff --git a/src/blackmisc/sequence.h b/src/blackmisc/sequence.h index 26f52d1df..280e7ad2d 100644 --- a/src/blackmisc/sequence.h +++ b/src/blackmisc/sequence.h @@ -9,6 +9,8 @@ //! \file +#include "valueobject.h" // outside include guard due to cyclic dependency hack (MS) + #ifndef BLACKMISC_SEQUENCE_H #define BLACKMISC_SEQUENCE_H diff --git a/src/blackmisc/tuple_private.h b/src/blackmisc/tuple_private.h index 98cb351c6..cf45bb962 100644 --- a/src/blackmisc/tuple_private.h +++ b/src/blackmisc/tuple_private.h @@ -25,8 +25,26 @@ namespace BlackMisc { - class CValueObject; + class CEmpty; template class TupleConverter; + template class CValueObjectStdTuple; + + //! Traits class to test whether a class template specialization is a base class of another class. + template