summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qcom.h90
1 files changed, 89 insertions, 1 deletions
diff --git a/library/qcom.h b/library/qcom.h
index 8c0fa60..9972d8f 100644
--- a/library/qcom.h
+++ b/library/qcom.h
@@ -66,12 +66,100 @@ struct Q_EXPORT QLibraryInterface : public QUnknownInterface
66 QUnknownInterface* iface = 0; \ 66 QUnknownInterface* iface = 0; \
67 i->queryInterface( IID_QUnknown, &iface ); \ 67 i->queryInterface( IID_QUnknown, &iface ); \
68 return iface; 68 return iface;
69 69
70template <class T>
71class QInterfacePtr
72{
73public:
74 QInterfacePtr():iface(0){}
75
76 QInterfacePtr( T* i) {
77 if ( (iface = i) )
78 iface->addRef();
79 }
80
81 QInterfacePtr(const QInterfacePtr<T> &p) {
82 if ( (iface = p.iface) )
83 iface->addRef();
84 }
85
86 ~QInterfacePtr() {
87 if ( iface )
88 iface->release();
89 }
90
91 QInterfacePtr<T> &operator=(const QInterfacePtr<T> &p) {
92 if ( iface != p.iface ) {
93 if ( iface )
94 iface->release();
95 if ( (iface = p.iface) )
96 iface->addRef();
97 }
98 return *this;
99 }
100
101 QInterfacePtr<T> &operator=(T* i) {
102 if (iface != i ) {
103 if ( iface )
104 iface->release();
105 if ( (iface = i) )
106 iface->addRef();
107 }
108 return *this;
109 }
110
111 bool operator==( const QInterfacePtr<T> &p ) const { return iface == p.iface; }
112
113 bool operator!= ( const QInterfacePtr<T>& p ) const { return !( *this == p ); }
114
115 bool isNull() const { return !iface; }
116
117 T* operator->() const { return iface; }
118
119 T& operator*() const { return *iface; }
120
121 operator T*() const { return iface; }
122
123 QUnknownInterface** operator &() const {
124 if( iface )
125 iface->release();
126 return (QUnknownInterface**)&iface;
127 }
128
129 T** operator &() {
130 if ( iface )
131 iface->release();
132 return &iface;
133 }
134
135private:
136 T* iface;
137};
138
139
140// internal class that wraps an initialized ulong
141struct Q_EXPORT QtULong
142{
143 QtULong() : ref( 0 ) { }
144 operator unsigned long () const { return ref; }
145 unsigned long& operator++() { return ++ref; }
146 unsigned long operator++( int ) { return ref++; }
147 unsigned long& operator--() { return --ref; }
148 unsigned long operator--( int ) { return ref--; }
149
150 unsigned long ref;
151};
152
70#define Q_EXPORT_INTERFACE() \ 153#define Q_EXPORT_INTERFACE() \
71 extern "C" QUnknownInterface* ucm_instantiate() 154 extern "C" QUnknownInterface* ucm_instantiate()
72 155
73#define Q_REFCOUNT ulong addRef() {return ref++;}ulong release() {if(!--ref){delete this;return 0;}return ref;} 156#define Q_REFCOUNT \
157private: \
158 QtULong qtrefcount; \
159public: \
160 ulong addRef() {return qtrefcount++;} \
161 ulong release() {if(!--qtrefcount){delete this;return 0;}return qtrefcount;}
74 162
75#else // QT_NO_COMPONENT 163#else // QT_NO_COMPONENT
76 164
77struct Q_EXPORT QUnknownInterface 165struct Q_EXPORT QUnknownInterface