BPS C++ API  2.24.4
bpsvariant.h
Go to the documentation of this file.
1 
4 #ifndef BPSVARIANT_H
5 #define BPSVARIANT_H
6 
7 #include "bpscore_global.h"
8 #include <QVariant>
9 
10 #undef BPSVARIANT_CONVERT_FROM // Not possible in current qt release (4.8.2)
11 
86 {
87 public:
91  template <typename T>
92  static void registerCompare()
93  {
94  registerCompare(qMetaTypeId<T>(), &compare<T>);
95  } // registerCompare
96 
101  template <typename F, typename T>
102  static void registerConvertTo()
103  {
104  registerConvert(qMetaTypeId<F>(), qMetaTypeId<T>(), &convertTo<F,T>);
105  } // registerCompare
106 
107 # ifdef BPSVARIANT_CONVERT_FROM
109 
112  template <typename F, typename T>
113  static void registerConvertFrom()
114  {
115  registerConvert(qMetaTypeId<F>(), qMetaTypeId<T>(), &convertFrom<F,T>);
116  } // registerCompare
118 # endif
119 
120 private:
122  BpsVariant() {};
123 
124  template <typename T>
125  static bool compare(const QVariant::Private* a1st, const QVariant::Private* a2nd)
126  {
127  // the v_cast<> does not work here ... why?
128  return *static_cast<T*>(a1st->data.shared->ptr) == *static_cast<T*>(a2nd->data.shared->ptr);
129  } // compare
130 
131  template <typename F, typename T>
132  static bool convertTo(const QVariant::Private *aPrivate, int aType, void* aResult, bool* aOk)
133  {
134  Q_UNUSED(aType)
135  return static_cast<F*>(aPrivate->data.shared->ptr)->convertTo(static_cast<T*>(aResult), aOk);
136  } // convertTo
137 
138 # ifdef BPSVARIANT_CONVERT_FROM
139  template <typename F, typename T>
140  static bool convertFrom(const QVariant::Private *aPrivate, int aType, void* aResult, bool* aOk)
141  {
142  return static_cast<T*>(aResult)->convertFrom(static_cast<F*>(aPrivate->data.shared->ptr), aOk);
143  } // convertFrom
144 # endif
145 
146  static void registerCompare(int aType, QVariant::f_compare aCompare);
147  static void registerConvert(int aFromType, int aToType, QVariant::f_convert aConvert);
149 };
150 
151 #endif // BPSVARIANT_H
Public include file for BPS CORE library macros.
#define BPSCORE_EXPORT
Declare class to be an import from the shared library.
Definition: bpscore_global.h:22
Hook up custom variable types and classes in QVariant.
Definition: bpsvariant.h:86
static void registerCompare()
Register custom type/class for QVariant equal operator.
Definition: bpsvariant.h:92
static void registerConvertTo()
Register custom type for QVariant conversion to other types.
Definition: bpsvariant.h:102