reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
IntrusiveListElement.hxx
Go to the documentation of this file.
1#ifndef RESIP_IntrusiveListElement
2#define RESIP_IntrusiveListElement
3
57namespace resip
58{
59
60template <class P>
62{
63 public:
65 : mNext(0),
66 mPrev(0)
67 {}
68
70 {
71 remove();
72 }
73
74 // make this element an empty list
75 static P makeList(P elem)
76 {
77 resip_assert(!elem->IntrusiveListElement<P>::mNext);
78
79 elem->IntrusiveListElement<P>::mPrev = elem;
80 elem->IntrusiveListElement<P>::mNext = elem;
81
82 return elem;
83 }
84
85 bool empty() const
86 {
89
90 return static_cast<const IntrusiveListElement<P>*>(mNext) == static_cast<const IntrusiveListElement<P>*>(this);
91 }
92
93 // .dlb. add reverse_iterator?
94
96 {
97 public:
98 explicit iterator(const P start)
99 : mPos(start)
100 {}
101
103 {
104 mPos = rhs.mPos;
105 return *this;
106 }
107
109 {
110 mPos = mPos->IntrusiveListElement<P>::mNext;
111 return *this;
112 }
113
114 friend bool operator==(const iterator& lhs, const iterator& rhs)
115 {
116 return lhs.mPos == rhs.mPos;
117 }
118
119 friend bool operator!=(const iterator& lhs, const iterator& rhs)
120 {
121 return lhs.mPos != rhs.mPos;
122 }
123
125 {
126 return mPos;
127 }
128
129 private:
130 P mPos;
131 };
132
134 {
137 return iterator(mNext);
138 }
139
141 {
144 return iterator(static_cast<P>(this));
145 }
146
147 friend class iterator;
148
149 // pushing an element onto the same list twice is undefined
151 {
154
155 elem->IntrusiveListElement<P>::mNext = mNext;
156 elem->IntrusiveListElement<P>::mPrev = static_cast<P>(this);
157
158 elem->IntrusiveListElement<P>::mNext->IntrusiveListElement<P>::mPrev = elem;
159 elem->IntrusiveListElement<P>::mPrev->IntrusiveListElement<P>::mNext = elem;
160 }
161
162 // putting an element onto the same list twice is undefined
164 {
167
168 elem->IntrusiveListElement<P>::mPrev = mPrev;
169 elem->IntrusiveListElement<P>::mNext = static_cast<P>(this);
170
171 elem->IntrusiveListElement<P>::mPrev->IntrusiveListElement<P>::mNext = elem;
172 elem->IntrusiveListElement<P>::mNext->IntrusiveListElement<P>::mPrev = elem;
173 }
174
175 void remove()
176 {
177 if (mNext)
178 {
179 // prev -> this -> next
180 // <- <-
181 //
182 // prev -> next
183 // <-
184 mNext->IntrusiveListElement<P>::mPrev = mPrev;
185 mPrev->IntrusiveListElement<P>::mNext = mNext;
186 }
187
188 mNext = 0;
189 mPrev = 0;
190 }
191
192 protected:
193 mutable P mNext;
194 mutable P mPrev;
195};
196
197template <class P>
199{
200 public:
202 : mNext(0),
203 mPrev(0)
204 {}
205
207 {
208 remove();
209 }
210
211 // make this element an empty list
212 static P makeList(P elem)
213 {
214 resip_assert(!elem->IntrusiveListElement1<P>::mNext);
215
216 elem->IntrusiveListElement1<P>::mPrev = elem;
217 elem->IntrusiveListElement1<P>::mNext = elem;
218
219 return elem;
220 }
221
222 bool empty() const
223 {
226
227 return static_cast<const IntrusiveListElement1<P>*>(mNext) == static_cast<const IntrusiveListElement1<P>*>(this);
228 }
229
230 // .dlb. add reverse_iterator?
231
233 {
234 public:
235 explicit iterator(const P start)
236 : mPos(start)
237 {}
238
240 {
241 mPos = rhs.mPos;
242 return *this;
243 }
244
246 {
247 mPos = mPos->IntrusiveListElement1<P>::mNext;
248 return *this;
249 }
250
251 friend bool operator==(const iterator& lhs, const iterator& rhs)
252 {
253 return lhs.mPos == rhs.mPos;
254 }
255
256 friend bool operator!=(const iterator& lhs, const iterator& rhs)
257 {
258 return lhs.mPos != rhs.mPos;
259 }
260
262 {
263 return mPos;
264 }
265
266 private:
267 P mPos;
268 };
269
271 {
274 return iterator(mNext);
275 }
276
278 {
281 return iterator(static_cast<P>(this));
282 }
283
284 friend class iterator;
285
286 // pushing an element onto the same list twice is undefined
288 {
291
292 elem->IntrusiveListElement1<P>::mNext = mNext;
293 elem->IntrusiveListElement1<P>::mPrev = static_cast<P>(this);
294
295 elem->IntrusiveListElement1<P>::mNext->IntrusiveListElement1<P>::mPrev = elem;
296 elem->IntrusiveListElement1<P>::mPrev->IntrusiveListElement1<P>::mNext = elem;
297 }
298
299 // putting an element onto the same list twice is undefined
301 {
304
305 elem->IntrusiveListElement1<P>::mPrev = mPrev;
306 elem->IntrusiveListElement1<P>::mNext = static_cast<P>(this);
307
308 elem->IntrusiveListElement1<P>::mPrev->IntrusiveListElement1<P>::mNext = elem;
309 elem->IntrusiveListElement1<P>::mNext->IntrusiveListElement1<P>::mPrev = elem;
310 }
311
312 void remove()
313 {
314 if (mNext)
315 {
316 // prev -> this -> next
317 // <- <-
318 //
319 // prev -> next
320 // <-
321 mNext->IntrusiveListElement1<P>::mPrev = mPrev;
322 mPrev->IntrusiveListElement1<P>::mNext = mNext;
323 }
324
325 mNext = 0;
326 mPrev = 0;
327 }
328
329 protected:
330 mutable P mNext;
331 mutable P mPrev;
332};
333
334template <class P>
336{
337 public:
339 : mNext(0),
340 mPrev(0)
341 {}
342
344 {
345 remove();
346 }
347
348 // make this element an empty list
349 static P makeList(P elem)
350 {
351 resip_assert(!elem->IntrusiveListElement2<P>::mNext);
352
353 elem->IntrusiveListElement2<P>::mPrev = elem;
354 elem->IntrusiveListElement2<P>::mNext = elem;
355
356 return elem;
357 }
358
359 bool empty() const
360 {
363
364 return static_cast<const IntrusiveListElement2<P>*>(mNext) == static_cast<const IntrusiveListElement2<P>*>(this);
365 }
366
367 // .dlb. add reverse_iterator?
368
370 {
371 public:
372 explicit iterator(const P start)
373 : mPos(start)
374 {}
375
377 {
378 mPos = rhs.mPos;
379 return *this;
380 }
381
383 {
384 mPos = mPos->IntrusiveListElement2<P>::mNext;
385 return *this;
386 }
387
388 friend bool operator==(const iterator& lhs, const iterator& rhs)
389 {
390 return lhs.mPos == rhs.mPos;
391 }
392
393 friend bool operator!=(const iterator& lhs, const iterator& rhs)
394 {
395 return lhs.mPos != rhs.mPos;
396 }
397
399 {
400 return mPos;
401 }
402
403 private:
404 P mPos;
405 };
406
408 {
411 return iterator(mNext);
412 }
413
415 {
418 return iterator(static_cast<P>(this));
419 }
420
421 friend class iterator;
422
423 // pushing an element onto the same list twice is undefined
425 {
428
429 elem->IntrusiveListElement2<P>::mNext = mNext;
430 elem->IntrusiveListElement2<P>::mPrev = static_cast<P>(this);
431
432 elem->IntrusiveListElement2<P>::mNext->IntrusiveListElement2<P>::mPrev = elem;
433 elem->IntrusiveListElement2<P>::mPrev->IntrusiveListElement2<P>::mNext = elem;
434 }
435
436 // putting an element onto the same list twice is undefined
438 {
441
442 elem->IntrusiveListElement2<P>::mPrev = mPrev;
443 elem->IntrusiveListElement2<P>::mNext = static_cast<P>(this);
444
445 elem->IntrusiveListElement2<P>::mPrev->IntrusiveListElement2<P>::mNext = elem;
446 elem->IntrusiveListElement2<P>::mNext->IntrusiveListElement2<P>::mPrev = elem;
447 }
448
449 void remove()
450 {
451 if (mNext)
452 {
453 // prev -> this -> next
454 // <- <-
455 //
456 // prev -> next
457 // <-
458 mNext->IntrusiveListElement2<P>::mPrev = mPrev;
459 mPrev->IntrusiveListElement2<P>::mNext = mNext;
460 }
461
462 mNext = 0;
463 mPrev = 0;
464 }
465
466 protected:
467 mutable P mNext;
468 mutable P mPrev;
469};
470
471template <class P>
473{
474 public:
476 : mNext(0),
477 mPrev(0)
478 {}
479
481 {
482 remove();
483 }
484
485 // make this element an empty list
486 static P makeList(P elem)
487 {
488 resip_assert(!elem->IntrusiveListElement3<P>::mNext);
489
490 elem->IntrusiveListElement3<P>::mPrev = elem;
491 elem->IntrusiveListElement3<P>::mNext = elem;
492
493 return elem;
494 }
495
496 bool empty() const
497 {
500
501 return static_cast<const IntrusiveListElement3<P>*>(mNext) == static_cast<const IntrusiveListElement3<P>*>(this);
502 }
503
504 // .dlb. add reverse_iterator?
505
507 {
508 public:
509 explicit iterator(const P start)
510 : mPos(start)
511 {}
512
514 {
515 mPos = rhs.mPos;
516 return *this;
517 }
518
520 {
521 mPos = mPos->IntrusiveListElement3<P>::mNext;
522 return *this;
523 }
524
525 friend bool operator==(const iterator& lhs, const iterator& rhs)
526 {
527 return lhs.mPos == rhs.mPos;
528 }
529
530 friend bool operator!=(const iterator& lhs, const iterator& rhs)
531 {
532 return lhs.mPos != rhs.mPos;
533 }
534
536 {
537 return mPos;
538 }
539
540 private:
541 P mPos;
542 };
543
545 {
548 return iterator(mNext);
549 }
550
552 {
555 return iterator(static_cast<P>(this));
556 }
557
558 friend class iterator;
559
560 // pushing an element onto the same list twice is undefined
562 {
565
566 elem->IntrusiveListElement3<P>::mNext = mNext;
567 elem->IntrusiveListElement3<P>::mPrev = static_cast<P>(this);
568
569 elem->IntrusiveListElement3<P>::mNext->IntrusiveListElement3<P>::mPrev = elem;
570 elem->IntrusiveListElement3<P>::mPrev->IntrusiveListElement3<P>::mNext = elem;
571 }
572
573 // putting an element onto the same list twice is undefined
575 {
578
579 elem->IntrusiveListElement3<P>::mPrev = mPrev;
580 elem->IntrusiveListElement3<P>::mNext = static_cast<P>(this);
581
582 elem->IntrusiveListElement3<P>::mPrev->IntrusiveListElement3<P>::mNext = elem;
583 elem->IntrusiveListElement3<P>::mNext->IntrusiveListElement3<P>::mPrev = elem;
584 }
585
586 void remove()
587 {
588 if (mNext)
589 {
590 // prev -> this -> next
591 // <- <-
592 //
593 // prev -> next
594 // <-
595 mNext->IntrusiveListElement3<P>::mPrev = mPrev;
596 mPrev->IntrusiveListElement3<P>::mNext = mNext;
597 }
598
599 mNext = 0;
600 mPrev = 0;
601 }
602
603 protected:
604 mutable P mNext;
605 mutable P mPrev;
606};
607
608}
609
610#endif
611
612
613/* ====================================================================
614 * The Vovida Software License, Version 1.0
615 *
616 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
617 *
618 * Redistribution and use in source and binary forms, with or without
619 * modification, are permitted provided that the following conditions
620 * are met:
621 *
622 * 1. Redistributions of source code must retain the above copyright
623 * notice, this list of conditions and the following disclaimer.
624 *
625 * 2. Redistributions in binary form must reproduce the above copyright
626 * notice, this list of conditions and the following disclaimer in
627 * the documentation and/or other materials provided with the
628 * distribution.
629 *
630 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
631 * and "Vovida Open Communication Application Library (VOCAL)" must
632 * not be used to endorse or promote products derived from this
633 * software without prior written permission. For written
634 * permission, please contact vocal@vovida.org.
635 *
636 * 4. Products derived from this software may not be called "VOCAL", nor
637 * may "VOCAL" appear in their name, without prior written
638 * permission of Vovida Networks, Inc.
639 *
640 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
641 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
642 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
643 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
644 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
645 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
646 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
647 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
648 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
649 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
650 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
651 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
652 * DAMAGE.
653 *
654 * ====================================================================
655 *
656 * This software consists of voluntary contributions made by Vovida
657 * Networks, Inc. and many individuals on behalf of Vovida Networks,
658 * Inc. For more information on Vovida Networks, Inc., please see
659 * <http://www.vovida.org/>.
660 *
661 */
#define resip_assert(x)
This file needs to work for both C and C++ code.
friend bool operator==(const iterator &lhs, const iterator &rhs)
iterator & operator=(const iterator &rhs)
friend bool operator!=(const iterator &lhs, const iterator &rhs)
friend bool operator==(const iterator &lhs, const iterator &rhs)
iterator & operator=(const iterator &rhs)
friend bool operator!=(const iterator &lhs, const iterator &rhs)
friend bool operator==(const iterator &lhs, const iterator &rhs)
iterator & operator=(const iterator &rhs)
friend bool operator!=(const iterator &lhs, const iterator &rhs)
friend bool operator==(const iterator &lhs, const iterator &rhs)
iterator & operator=(const iterator &rhs)
friend bool operator!=(const iterator &lhs, const iterator &rhs)
dcm! – add UnusedChecking(_enum) below;
void list()
Definition userAdmin.cxx:66