Debian Codegraph @

Source/Utilities/Container/CQtManagedRestrictedModificationList.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * This file incorporates work covered by the following copyright and
20 * permission notice (to be compatible with LGPLv2.1,
21 * this code is available/released under GPLv3,
22 * see https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility):
23 *
24 *
25 * Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
26 * Contact: http://www.qt-project.org/legal
27 *
28 * This file is part of the QtCore module of the Qt Toolkit.
29 *
30 * $QT_BEGIN_LICENSE:LGPL$
31 * Commercial License Usage
32 * Licensees holding valid commercial Qt licenses may use this file in
33 * accordance with the commercial license agreement provided with the
34 * Software or, alternatively, in accordance with the terms contained in
35 * a written agreement between you and Digia. For licensing terms and
36 * conditions see http://qt.digia.com/licensing. For further information
37 * use the contact form at http://qt.digia.com/contact-us.
38 *
39 * GNU Lesser General Public License Usage
40 * Alternatively, this file may be used under the terms of the GNU Lesser
41 * General Public License version 2.1 as published by the Free Software
42 * Foundation and appearing in the file LICENSE.LGPL included in the
43 * packaging of this file. Please review the following information to
44 * ensure the GNU Lesser General Public License version 2.1 requirements
45 * will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
46 *
47 * In addition, as a special exception, Digia gives you certain additional
48 * rights. These rights are described in the Digia Qt LGPL Exception
49 * version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
50 *
51 * GNU General Public License Usage
52 * Alternatively, this file may be used under the terms of the GNU
53 * General Public License version 3.0 as published by the Free Software
54 * Foundation and appearing in the file LICENSE.GPL included in the
55 * packaging of this file. Please review the following information to
56 * ensure the GNU General Public License version 3.0 requirements will be
57 * met: http://www.gnu.org/copyleft/gpl.html.
58 *
59 *
60 * $QT_END_LICENSE$
61 *
62 *
63 */
64
65 #ifndef KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONLIST_CPP
66 #define KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONLIST_CPP
67
68
69 #include "CQtManagedRestrictedModificationList.h"
70
71
72 namespace Konclude {
73
74 namespace Utilities {
75
76 namespace Container {
77
78
79 #ifdef KONCLUDE_EMPLOY_QT_MANAGED_RESTRICTED_MODIFICATION_LIST_CONTAINER
80
81
82 #if defined(Q_CC_BOR)
83 template <typename T>
84 Q_INLINE_TEMPLATE T &CQtManagedRestrictedModificationList<T>::Node::t()
85 { return QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic ? *(T*)v:*(T*)this; }
86 #endif
87
88 template <typename T>
89 Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::node_construct(Node *n, const T &t)
90 {
91 //if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t);
92 //else if (QTypeInfo<T>::isComplex) new (n) T(t);
93 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
94 n->v = CObjectAllocator<T>::allocate(mMemMan);
95 new (n->v) T(t);
96 } else if (QTypeInfo<T>::isComplex) new (n) T(t);
97
98 #if (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__IBMCPP__)) && !defined(__OPTIMIZE__)
99 // This violates pointer aliasing rules, but it is known to be safe (and silent)
100 // in unoptimized GCC builds (-fno-strict-aliasing). The other compilers which
101 // set the same define are assumed to be safe.
102 else *reinterpret_cast<T*>(n) = t;
103 #else
104 // This is always safe, but penaltizes unoptimized builds a lot.
105 else ::memcpy(n, &t, sizeof(T));
106 #endif
107 }
108
109 template <typename T>
110 Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::node_destruct(Node *n)
111 {
112 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
113 //delete reinterpret_cast<T*>(n->v);
114 T* ob = reinterpret_cast<T*>(n->v);
115 CObjectAllocator<T>::destroyAndRelease(ob,mMemMan);
116 } else if (QTypeInfo<T>::isComplex) reinterpret_cast<T*>(n)->~T();
117 }
118
119 template <typename T>
120 Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::node_copy(Node *from, Node *to, Node *src)
121 {
122 Node *current = from;
123 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
124 QT_TRY {
125 while(current != to) {
126 //current->v = new T(*reinterpret_cast<T*>(src->v));
127 current->v = CObjectAllocator<T>::allocate(mMemMan);
128 new (current->v) T(*reinterpret_cast<T*>(src->v));
129 ++current;
130 ++src;
131 }
132 } QT_CATCH(...) {
133 while (current-- != from) {
134 //delete reinterpret_cast<T*>(current->v);
135 T* ob = reinterpret_cast<T*>(current->v);
136 CObjectAllocator<T>::destroyAndRelease(ob,mMemMan);
137 }
138
139 QT_RETHROW;
140 }
141
142 } else if (QTypeInfo<T>::isComplex) {
143 QT_TRY {
144 while(current != to) {
145 new (current) T(*reinterpret_cast<T*>(src));
146 ++current;
147 ++src;
148 }
149 } QT_CATCH(...) {
150 while (current-- != from)
151 (reinterpret_cast<T*>(current))->~T();
152 QT_RETHROW;
153 }
154 } else {
155 if (src != from && to - from > 0)
156 memcpy(from, src, (to - from) * sizeof(Node *));
157 }
158 }
159
160 template <typename T>
161 Q_INLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::node_destruct(Node *from, Node *to)
162 {
163 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic)
164 while(from != to) {
165 --to;
166 //delete reinterpret_cast<T*>(to->v);
167 T* ob = reinterpret_cast<T*>(to->v);
168 CObjectAllocator<T>::destroyAndRelease(ob,mMemMan);
169 }
170 else if (QTypeInfo<T>::isComplex)
171 while (from != to) --to, reinterpret_cast<T*>(to)->~T();
172 }
173
174 template <typename T>
175 Q_INLINE_TEMPLATE CQtManagedRestrictedModificationList<T> &CQtManagedRestrictedModificationList<T>::operator=(const CQtManagedRestrictedModificationList<T> &l)
176 {
177 if (d != l.d) {
178 //l.d->ref.ref();
179 //if (!d->ref.deref())
180 // free(d);
181 //d = l.d;
182 //if (!d->sharable)
183 // detach_helper();
184
185 if (d->refList == this)
186 free(d);
187 d = l.d;
188 if (!d->sharable)
189 detach_helper();
190 }
191 return *this;
192 }
193
194
195 template <typename T>
196 CQtManagedRestrictedModificationList<T>* CQtManagedRestrictedModificationList<T>::init(CContext* context) {
197 clear();
198 mContext = context;
199 mMemMan = CContext::getMemoryAllocationManager(mContext);
200 return this;
201 }
202
203 template <typename T>
204 CQtManagedRestrictedModificationList<T>* CQtManagedRestrictedModificationList<T>::init(const CQtManagedRestrictedModificationList<T> &other, CContext* context) {
205 if (d != other.d) {
206 if (d->refList == this)
207 free(d);
208 mContext = context;
209 mMemMan = CContext::getMemoryAllocationManager(mContext);
210 d = other.d;
211 if (!d->sharable)
212 detach_helper();
213 }
214 mContext = context;
215 mMemMan = CContext::getMemoryAllocationManager(mContext);
216 return this;
217 }
218
219 template <typename T>
220 CQtManagedRestrictedModificationList<T>* CQtManagedRestrictedModificationList<T>::init(const CQtManagedRestrictedModificationList<T> *other, CContext* context) {
221 if (!other) {
222 if (d != other->d) {
223 if (d->refList == this)
224 free(d);
225 mContext = context;
226 mMemMan = CContext::getMemoryAllocationManager(mContext);
227 if (other) {
228 d = other->d;
229 if (!d->sharable)
230 detach_helper();
231 }
232 }
233 } else {
234 if (d->refList == this)
235 free(d);
236 d = &CQtManagedRestrictedModificationListData::shared_null;
237 }
238 mContext = context;
239 mMemMan = CContext::getMemoryAllocationManager(mContext);
240 return this;
241 }
242
243
244
245 template <typename T>
246 inline typename CQtManagedRestrictedModificationList<T>::iterator CQtManagedRestrictedModificationList<T>::insert(iterator before, const T &t)
247 {
248 int iBefore = int(before.i - reinterpret_cast<Node *>(p.begin()));
249 Node *n = reinterpret_cast<Node *>(p.insert(iBefore,mMemMan));
250 QT_TRY {
251 node_construct(n, t);
252 } QT_CATCH(...) {
253 p.remove(iBefore);
254 QT_RETHROW;
255 }
256 return n;
257 }
258 template <typename T>
259 inline typename CQtManagedRestrictedModificationList<T>::iterator CQtManagedRestrictedModificationList<T>::erase(iterator it)
260 { node_destruct(it.i);
261 return reinterpret_cast<Node *>(p.erase(reinterpret_cast<void**>(it.i))); }
262 template <typename T>
263 inline const T &CQtManagedRestrictedModificationList<T>::at(int i) const
264 { Q_ASSERT_X(i >= 0 && i < p.size(), "CQtManagedRestrictedModificationList<T>::at", "index out of range");
265 return reinterpret_cast<Node *>(p.at(i))->t(); }
266 template <typename T>
267 inline const T &CQtManagedRestrictedModificationList<T>::operator[](int i) const
268 { Q_ASSERT_X(i >= 0 && i < p.size(), "CQtManagedRestrictedModificationList<T>::operator[]", "index out of range");
269 return reinterpret_cast<Node *>(p.at(i))->t(); }
270 template <typename T>
271 inline T &CQtManagedRestrictedModificationList<T>::operator[](int i)
272 { Q_ASSERT_X(i >= 0 && i < p.size(), "CQtManagedRestrictedModificationList<T>::operator[]", "index out of range");
273 detach(); return reinterpret_cast<Node *>(p.at(i))->t(); }
274 template <typename T>
275 inline void CQtManagedRestrictedModificationList<T>::removeAt(int i)
276 { if(i >= 0 && i < p.size()) { detach();
277 node_destruct(reinterpret_cast<Node *>(p.at(i))); p.remove(i); } }
278 template <typename T>
279 inline T CQtManagedRestrictedModificationList<T>::takeAt(int i)
280 { Q_ASSERT_X(i >= 0 && i < p.size(), "CQtManagedRestrictedModificationList<T>::take", "index out of range");
281 detach(); Node *n = reinterpret_cast<Node *>(p.at(i)); T t = n->t(); node_destruct(n);
282 p.remove(i); return t; }
283 template <typename T>
284 inline T CQtManagedRestrictedModificationList<T>::takeFirst()
285 { T t = first(); removeFirst(); return t; }
286 template <typename T>
287 inline T CQtManagedRestrictedModificationList<T>::takeLast()
288 { T t = last(); removeLast(); return t; }
289
290 template <typename T>
291 Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::reserve(int alloc)
292 {
293 if (d->alloc < alloc) {
294 //if (d->ref != 1)
295 if (d->refList != this)
296 detach_helper(alloc);
297 else
298 p.realloc(alloc,mMemMan);
299 }
300 }
301
302 template <typename T>
303 Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::append(const T &t)
304 {
305 //if (d->ref != 1) {
306 if (d->refList != this) {
307 Node *n = detach_helper_grow(INT_MAX, 1);
308 QT_TRY {
309 node_construct(n, t);
310 } QT_CATCH(...) {
311 --d->end;
312 QT_RETHROW;
313 }
314 } else {
315 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
316 Node *n = reinterpret_cast<Node *>(p.append(mMemMan));
317 QT_TRY {
318 node_construct(n, t);
319 } QT_CATCH(...) {
320 --d->end;
321 QT_RETHROW;
322 }
323 } else {
324 Node *n, copy;
325 node_construct(&copy, t); // t might be a reference to an object in the array
326 QT_TRY {
327 n = reinterpret_cast<Node *>(p.append(mMemMan));;
328 } QT_CATCH(...) {
329 node_destruct(&copy);
330 QT_RETHROW;
331 }
332 *n = copy;
333 }
334 }
335 }
336
337 template <typename T>
338 inline void CQtManagedRestrictedModificationList<T>::prepend(const T &t)
339 {
340 //if (d->ref != 1) {
341 if (d->refList != this) {
342 Node *n = detach_helper_grow(0, 1);
343 QT_TRY {
344 node_construct(n, t);
345 } QT_CATCH(...) {
346 ++d->begin;
347 QT_RETHROW;
348 }
349 } else {
350 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
351 Node *n = reinterpret_cast<Node *>(p.prepend(mMemMan));
352 QT_TRY {
353 node_construct(n, t);
354 } QT_CATCH(...) {
355 ++d->begin;
356 QT_RETHROW;
357 }
358 } else {
359 Node *n, copy;
360 node_construct(&copy, t); // t might be a reference to an object in the array
361 QT_TRY {
362 n = reinterpret_cast<Node *>(p.prepend(mMemMan));;
363 } QT_CATCH(...) {
364 node_destruct(&copy);
365 QT_RETHROW;
366 }
367 *n = copy;
368 }
369 }
370 }
371
372 template <typename T>
373 inline void CQtManagedRestrictedModificationList<T>::insert(int i, const T &t)
374 {
375 //if (d->ref != 1) {
376 if (d->refList != this) {
377 Node *n = detach_helper_grow(i, 1);
378 QT_TRY {
379 node_construct(n, t);
380 } QT_CATCH(...) {
381 p.remove(i);
382 QT_RETHROW;
383 }
384 } else {
385 if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
386 Node *n = reinterpret_cast<Node *>(p.insert(i,mMemMan));
387 QT_TRY {
388 node_construct(n, t);
389 } QT_CATCH(...) {
390 p.remove(i);
391 QT_RETHROW;
392 }
393 } else {
394 Node *n, copy;
395 node_construct(&copy, t); // t might be a reference to an object in the array
396 QT_TRY {
397 n = reinterpret_cast<Node *>(p.insert(i,mMemMan));;
398 } QT_CATCH(...) {
399 node_destruct(&copy);
400 QT_RETHROW;
401 }
402 *n = copy;
403 }
404 }
405 }
406
407 template <typename T>
408 inline void CQtManagedRestrictedModificationList<T>::replace(int i, const T &t)
409 {
410 Q_ASSERT_X(i >= 0 && i < p.size(), "CQtManagedRestrictedModificationList<T>::replace", "index out of range");
411 detach();
412 reinterpret_cast<Node *>(p.at(i))->t() = t;
413 }
414
415 template <typename T>
416 inline void CQtManagedRestrictedModificationList<T>::swap(int i, int j)
417 {
418 Q_ASSERT_X(i >= 0 && i < p.size() && j >= 0 && j < p.size(),
419 "CQtManagedRestrictedModificationList<T>::swap", "index out of range");
420 detach();
421 void *t = d->array[d->begin + i];
422 d->array[d->begin + i] = d->array[d->begin + j];
423 d->array[d->begin + j] = t;
424 }
425
426 template <typename T>
427 inline void CQtManagedRestrictedModificationList<T>::move(int from, int to)
428 {
429 Q_ASSERT_X(from >= 0 && from < p.size() && to >= 0 && to < p.size(),
430 "CQtManagedRestrictedModificationList<T>::move", "index out of range");
431 detach();
432 p.move(from, to);
433 }
434
435 template<typename T>
436 Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<T> CQtManagedRestrictedModificationList<T>::mid(int pos, int alength) const
437 {
438 if (alength < 0 || pos + alength > size())
439 alength = size() - pos;
440 if (pos == 0 && alength == size())
441 return *this;
442 CQtManagedRestrictedModificationList<T> cpy;
443 cpy.reserve(alength);
444 cpy.d->end = alength;
445 QT_TRY {
446 cpy.node_copy(reinterpret_cast<Node *>(cpy.p.begin()),
447 reinterpret_cast<Node *>(cpy.p.end()),
448 reinterpret_cast<Node *>(p.begin() + pos));
449 } QT_CATCH(...) {
450 // restore the old end
451 cpy.d->end = 0;
452 QT_RETHROW;
453 }
454 return cpy;
455 }
456
457 template<typename T>
458 Q_OUTOFLINE_TEMPLATE T CQtManagedRestrictedModificationList<T>::value(int i) const
459 {
460 if (i < 0 || i >= p.size()) {
461 return T();
462 }
463 return reinterpret_cast<Node *>(p.at(i))->t();
464 }
465
466 template<typename T>
467 Q_OUTOFLINE_TEMPLATE T CQtManagedRestrictedModificationList<T>::value(int i, const T& defaultValue) const
468 {
469 return ((i < 0 || i >= p.size()) ? defaultValue : reinterpret_cast<Node *>(p.at(i))->t());
470 }
471
472 template <typename T>
473 Q_OUTOFLINE_TEMPLATE typename CQtManagedRestrictedModificationList<T>::Node *CQtManagedRestrictedModificationList<T>::detach_helper_grow(int i, int c)
474 {
475 Node *n = reinterpret_cast<Node *>(p.begin());
476 CQtManagedRestrictedModificationListData::Data *x = p.detach_grow(&i, c,mMemMan,this);
477 QT_TRY {
478 node_copy(reinterpret_cast<Node *>(p.begin()),
479 reinterpret_cast<Node *>(p.begin() + i), n);
480 } QT_CATCH(...) {
481 //qFree(d);
482 CObjectAllocator<CQtManagedRestrictedModificationListData::Data>::destroyAndRelease(d,mMemMan);
483 d = x;
484 QT_RETHROW;
485 }
486 QT_TRY {
487 node_copy(reinterpret_cast<Node *>(p.begin() + i + c),
488 reinterpret_cast<Node *>(p.end()), n + i);
489 } QT_CATCH(...) {
490 node_destruct(reinterpret_cast<Node *>(p.begin()),
491 reinterpret_cast<Node *>(p.begin() + i));
492 //qFree(d);
493 CObjectAllocator<CQtManagedRestrictedModificationListData::Data>::destroyAndRelease(d,mMemMan);
494 d = x;
495 QT_RETHROW;
496 }
497
498 //if (!x->ref.deref())
499 if (d->refList == this) {
500 free(x);
501 }
502
503 return reinterpret_cast<Node *>(p.begin() + i);
504 }
505
506 template <typename T>
507 Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::detach_helper(int alloc)
508 {
509 Node *n = reinterpret_cast<Node *>(p.begin());
510 CQtManagedRestrictedModificationListData::Data *x = p.detach(alloc,mMemMan,this);
511 QT_TRY {
512 node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.end()), n);
513 } QT_CATCH(...) {
514 //qFree(d);
515 CObjectAllocator<CQtManagedRestrictedModificationListData::Data>::destroyAndRelease(d,mMemMan);
516 d = x;
517 QT_RETHROW;
518 }
519
520 //if (!x->ref.deref())
521 if (d->refList == this) {
522 free(x);
523 }
524 }
525
526 template <typename T>
527 Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::detach_helper()
528 {
529 detach_helper(d->alloc);
530 }
531
532 template <typename T>
533 Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<T>::~CQtManagedRestrictedModificationList()
534 {
535 //if (d && !d->ref.deref())
536 if (d && d->refList == this)
537 free(d);
538 }
539
540 template <typename T>
541 Q_OUTOFLINE_TEMPLATE bool CQtManagedRestrictedModificationList<T>::operator==(const CQtManagedRestrictedModificationList<T> &l) const
542 {
543 if (p.size() != l.p.size())
544 return false;
545 if (d == l.d)
546 return true;
547 Node *i = reinterpret_cast<Node *>(p.end());
548 Node *b = reinterpret_cast<Node *>(p.begin());
549 Node *li = reinterpret_cast<Node *>(l.p.end());
550 while (i != b) {
551 --i; --li;
552 if (!(i->t() == li->t()))
553 return false;
554 }
555 return true;
556 }
557
558 // ### Qt 5: rename freeData() to avoid confusion with std::free()
559 template <typename T>
560 Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::free(CQtManagedRestrictedModificationListData::Data *data)
561 {
562 node_destruct(reinterpret_cast<Node *>(data->array + data->begin),
563 reinterpret_cast<Node *>(data->array + data->end));
564 //if (data->ref == 0)
565 if (data->refList == this)
566 //qFree(data);
567 CObjectAllocator<CQtManagedRestrictedModificationListData::Data>::destroyAndRelease(data,mMemMan);
568 }
569
570
571 template <typename T>
572 Q_OUTOFLINE_TEMPLATE void CQtManagedRestrictedModificationList<T>::clear()
573 {
574 *this = CQtManagedRestrictedModificationList<T>(mContext);
575 }
576
577 template <typename T>
578 Q_OUTOFLINE_TEMPLATE int CQtManagedRestrictedModificationList<T>::removeAll(const T &_t)
579 {
580 detachShared();
581 const T t = _t;
582 int removedCount=0, i=0;
583 Node *n;
584 while (i < p.size())
585 if ((n = reinterpret_cast<Node *>(p.at(i)))->t() == t) {
586 node_destruct(n);
587 p.remove(i);
588 ++removedCount;
589 } else {
590 ++i;
591 }
592 return removedCount;
593 }
594
595 template <typename T>
596 Q_OUTOFLINE_TEMPLATE bool CQtManagedRestrictedModificationList<T>::removeOne(const T &_t)
597 {
598 detachShared();
599 int index = indexOf(_t);
600 if (index != -1) {
601 removeAt(index);
602 return true;
603 }
604 return false;
605 }
606
607 template <typename T>
608 Q_OUTOFLINE_TEMPLATE typename CQtManagedRestrictedModificationList<T>::iterator CQtManagedRestrictedModificationList<T>::erase(typename CQtManagedRestrictedModificationList<T>::iterator afirst,
609 typename CQtManagedRestrictedModificationList<T>::iterator alast)
610 {
611 for (Node *n = afirst.i; n < alast.i; ++n)
612 node_destruct(n);
613 int idx = afirst - begin();
614 p.remove(idx, alast - afirst);
615 return begin() + idx;
616 }
617
618 template <typename T>
619 Q_OUTOFLINE_TEMPLATE CQtManagedRestrictedModificationList<T> &CQtManagedRestrictedModificationList<T>::operator+=(const CQtManagedRestrictedModificationList<T> &l)
620 {
621 if (!l.isEmpty()) {
622 if (isEmpty()) {
623 *this = l;
624 } else {
625 //Node *n = (d->ref != 1)
626 Node *n = (d->refList != this)
627 ? detach_helper_grow(INT_MAX, l.size())
628 : reinterpret_cast<Node *>(p.append2(l.p,mMemMan));
629 QT_TRY {
630 node_copy(n, reinterpret_cast<Node *>(p.end()),
631 reinterpret_cast<Node *>(l.p.begin()));
632 } QT_CATCH(...) {
633 // restore the old end
634 d->end -= int(reinterpret_cast<Node *>(p.end()) - n);
635 QT_RETHROW;
636 }
637 }
638 }
639 return *this;
640 }
641
642 template <typename T>
643 inline void CQtManagedRestrictedModificationList<T>::append(const CQtManagedRestrictedModificationList<T> &t)
644 {
645 *this += t;
646 }
647
648 template <typename T>
649 Q_OUTOFLINE_TEMPLATE int CQtManagedRestrictedModificationList<T>::indexOf(const T &t, int from) const
650 {
651 if (from < 0)
652 from = qMax(from + p.size(), 0);
653 if (from < p.size()) {
654 Node *n = reinterpret_cast<Node *>(p.at(from -1));
655 Node *e = reinterpret_cast<Node *>(p.end());
656 while (++n != e)
657 if (n->t() == t)
658 return int(n - reinterpret_cast<Node *>(p.begin()));
659 }
660 return -1;
661 }
662
663 template <typename T>
664 Q_OUTOFLINE_TEMPLATE int CQtManagedRestrictedModificationList<T>::lastIndexOf(const T &t, int from) const
665 {
666 if (from < 0)
667 from += p.size();
668 else if (from >= p.size())
669 from = p.size()-1;
670 if (from >= 0) {
671 Node *b = reinterpret_cast<Node *>(p.begin());
672 Node *n = reinterpret_cast<Node *>(p.at(from + 1));
673 while (n-- != b) {
674 if (n->t() == t)
675 return n - b;
676 }
677 }
678 return -1;
679 }
680
681 template <typename T>
682 Q_OUTOFLINE_TEMPLATE bool CQtManagedRestrictedModificationList<T>::contains(const T &t) const
683 {
684 Node *b = reinterpret_cast<Node *>(p.begin());
685 Node *i = reinterpret_cast<Node *>(p.end());
686 while (i-- != b)
687 if (i->t() == t)
688 return true;
689 return false;
690 }
691
692 template <typename T>
693 Q_OUTOFLINE_TEMPLATE int CQtManagedRestrictedModificationList<T>::count(const T &t) const
694 {
695 int c = 0;
696 Node *b = reinterpret_cast<Node *>(p.begin());
697 Node *i = reinterpret_cast<Node *>(p.end());
698 while (i-- != b)
699 if (i->t() == t)
700 ++c;
701 return c;
702 }
703
704
705 #endif // KONCLUDE_EMPLOY_QT_MANAGED_RESTRICTED_MODIFICATION_LIST_CONTAINER
706
707
708 }; // end namespace Container
709
710 }; // end namespace Utilities
711
712 }; // end namespace Konclude
713
714 #endif // KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONLIST_CPP