00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QGLIB_OBJECT_H
00020 #define QGLIB_OBJECT_H
00021
00022 #include "global.h"
00023 #include "refpointer.h"
00024 #include "paramspec.h"
00025 #include "value.h"
00026 #include "type.h"
00027 #include <QtCore/QList>
00028
00029 namespace QGlib {
00030
00038 class QTGLIB_EXPORT ObjectBase : public RefCountedObject
00039 {
00040 public:
00044 ParamSpecPtr findProperty(const char *name) const;
00045
00047 QList<ParamSpecPtr> listProperties() const;
00048
00052 Value property(const char *name) const;
00053
00058 template <class T> void setProperty(const char *name, const T & value);
00059
00065 void setProperty(const char *name, const Value & value);
00066
00067 void *data(const char *key) const;
00068 void *stealData(const char *key) const;
00069 void setData(const char *key, void *data, void (*destroyCallback)(void*) = NULL);
00070
00071 void *quarkData(const Quark & quark) const;
00072 void *stealQuarkData(const Quark & quark) const;
00073 void setQuarkData(const Quark & quark, void *data, void (*destroyCallback)(void*) = NULL);
00074
00075 protected:
00076 ObjectBase() {}
00077 virtual ~ObjectBase() {}
00078 Q_DISABLE_COPY(ObjectBase);
00079
00080 virtual void ref(bool increaseRef);
00081 virtual void unref();
00082 };
00083
00089 class QTGLIB_EXPORT Object : virtual public ObjectBase
00090 {
00091 QGLIB_WRAPPER(Object)
00092 };
00093
00099 class QTGLIB_EXPORT Interface : virtual public ObjectBase
00100 {
00101 QGLIB_WRAPPER_DIFFERENT_C_CLASS(Interface, Object)
00102 };
00103
00104
00105 template <class T>
00106 void ObjectBase::setProperty(const char *name, const T & value)
00107 {
00108 ParamSpecPtr param = findProperty(name);
00109 if (param) {
00110 Value v;
00111 v.init(param->valueType());
00112 v.set<T>(value);
00113 setProperty(name, v);
00114 }
00115 }
00116
00117 }
00118
00119 QGLIB_REGISTER_TYPE(QGlib::Object)
00120 QGLIB_REGISTER_TYPE(QGlib::Interface)
00121 QGLIB_REGISTER_WRAPIMPL_FOR_SUBCLASSES_OF(QGlib::Object, QGlib::Private::wrapObject)
00122
00123 #endif