~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/dimg/dshareddata.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    QAtomicInt ref;
54
54
 
55
55
    inline DSharedData() : ref(0) { }
56
 
    inline DSharedData(const DSharedData &) : ref(0) { }
 
56
    inline DSharedData(const DSharedData&) : ref(0) { }
57
57
 
58
58
    /** Returns true if the reference count is not 0.
59
59
     *  For the normal use case, you do not need this method.
60
60
     */
61
61
    inline bool isReferenced() const
62
 
        { return (int)ref > 0; }
 
62
    {
 
63
        return (int)ref > 0;
 
64
    }
63
65
    inline bool hasMoreReferences() const
64
 
        { return (int)ref != 1; }
 
66
    {
 
67
        return (int)ref != 1;
 
68
    }
65
69
 
66
70
private:
67
71
    // using the assignment operator would lead to corruption in the ref-counting
68
 
    DSharedData& operator=(const DSharedData &);
 
72
    DSharedData& operator=(const DSharedData&);
69
73
};
70
74
 
71
75
template <class T> class DSharedDataPointer
84
88
     */
85
89
 
86
90
    /** Various operators for accessing the pointer const and non-const */
87
 
    inline T& operator*() { return *d; }
88
 
    inline const T& operator*() const { return *d; }
89
 
    inline T *operator->() { return d; }
90
 
    inline const T *operator->() const { return d; }
91
 
    inline operator T *() { return d; }
92
 
    inline operator const T *() const { return d; }
93
 
    inline T *data() { return d; }
 
91
    inline T& operator*()
 
92
    {
 
93
        return *d;
 
94
    }
 
95
    inline const T& operator*() const
 
96
    {
 
97
        return *d;
 
98
    }
 
99
    inline T* operator->()
 
100
    {
 
101
        return d;
 
102
    }
 
103
    inline const T* operator->() const
 
104
    {
 
105
        return d;
 
106
    }
 
107
    inline operator T* ()
 
108
    {
 
109
        return d;
 
110
    }
 
111
    inline operator const T* () const
 
112
    {
 
113
        return d;
 
114
    }
 
115
    inline T* data()
 
116
    {
 
117
        return d;
 
118
    }
94
119
 
95
 
    inline const T *data() const { return d; }
96
 
    inline const T *constData() const { return d; }
 
120
    inline const T* data() const
 
121
    {
 
122
        return d;
 
123
    }
 
124
    inline const T* constData() const
 
125
    {
 
126
        return d;
 
127
    }
97
128
 
98
129
    /** This method carries out a const_cast, so it returns a non-const pointer
99
130
     *  from a const DSharedDataPointer.
100
131
     *  Typically, this should only be used if you know it should be used
101
132
     *  (to implement a lazy loading caching technique or similar)
102
133
     */
103
 
    inline T* constCastData() const { return const_cast<T*>(d); }
104
 
 
105
 
    inline bool operator==(const DSharedDataPointer<T>& other) const { return d == other.d; }
106
 
    inline bool operator!=(const DSharedDataPointer<T>& other) const { return d != other.d; }
107
 
 
108
 
    inline DSharedDataPointer() { d = 0; }
109
 
 
110
 
    explicit inline DSharedDataPointer(T *data) : d(data)
111
 
        { if (d) d->ref.ref(); }
 
134
    inline T* constCastData() const
 
135
    {
 
136
        return const_cast<T*>(d);
 
137
    }
 
138
 
 
139
    inline bool operator==(const DSharedDataPointer<T>& other) const
 
140
    {
 
141
        return d == other.d;
 
142
    }
 
143
    inline bool operator!=(const DSharedDataPointer<T>& other) const
 
144
    {
 
145
        return d != other.d;
 
146
    }
 
147
 
 
148
    inline DSharedDataPointer()
 
149
    {
 
150
        d = 0;
 
151
    }
 
152
 
 
153
    explicit inline DSharedDataPointer(T* data) : d(data)
 
154
    {
 
155
        if (d)
 
156
        {
 
157
            d->ref.ref();
 
158
        }
 
159
    }
112
160
 
113
161
    inline ~DSharedDataPointer()
114
 
        { if (d && !d->ref.deref()) delete d; }
 
162
    {
 
163
        if (d && !d->ref.deref())
 
164
        {
 
165
            delete d;
 
166
        }
 
167
    }
115
168
 
116
169
    inline DSharedDataPointer(const DSharedDataPointer<T>& o) : d(o.d)
117
 
        { if (d) d->ref.ref(); }
 
170
    {
 
171
        if (d)
 
172
        {
 
173
            d->ref.ref();
 
174
        }
 
175
    }
118
176
 
119
177
    inline DSharedDataPointer<T> & operator=(const DSharedDataPointer<T>& o)
120
178
    {
122
180
        return *this;
123
181
    }
124
182
 
125
 
    inline DSharedDataPointer& operator=(T *o)
 
183
    inline DSharedDataPointer& operator=(T* o)
126
184
    {
127
185
        delete assign(o);
128
186
        return *this;
137
195
     * @returns A T object with reference count 0, which may be deleted;
138
196
     *          or 0 if no object need to be dropped.
139
197
     */
140
 
    inline T *assign(const DSharedDataPointer<T>& o)
 
198
    inline T* assign(const DSharedDataPointer<T>& o)
141
199
    {
142
200
        if (o.d != d)
143
201
        {
144
202
            // reference new value
145
203
            if (o.d)
 
204
            {
146
205
                o.d->ref.ref();
 
206
            }
 
207
 
147
208
            // store old value
148
 
            T *x = d;
 
209
            T* x = d;
149
210
            // assign new value
150
211
            d = o.d;
 
212
 
151
213
            // dereference old value,
152
214
            // return value and ownership if dereferenced
153
215
            if (x && !x->ref.deref())
 
216
            {
154
217
                return x;
 
218
            }
155
219
        }
 
220
 
156
221
        return 0;
157
222
    }
158
223
 
159
 
    inline T *assign(T *o)
 
224
    inline T* assign(T* o)
160
225
    {
161
226
        if (o != d)
162
227
        {
163
228
            // reference new value
164
229
            if (o)
 
230
            {
165
231
                o->ref.ref();
 
232
            }
 
233
 
166
234
            // store old value
167
 
            T *x = d;
 
235
            T* x = d;
168
236
            // assign new value
169
237
            d = o;
 
238
 
170
239
            // dereference old value,
171
240
            // return value and ownership if dereferenced
172
241
            if (x && !x->ref.deref())
 
242
            {
173
243
                return x;
 
244
            }
174
245
        }
 
246
 
175
247
        return 0;
176
248
    }
177
249
 
178
250
    /**
179
251
     * Semantics like assign, but no new pointer is assigned to this.
180
252
     */
181
 
    inline T *unassign()
 
253
    inline T* unassign()
182
254
    {
183
255
        return assign(0);
184
256
    }
185
257
 
186
 
    inline bool operator!() const { return !d; }
 
258
    inline bool operator!() const
 
259
    {
 
260
        return !d;
 
261
    }
187
262
 
188
263
private:
189
264