PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
contain.h
Go to the documentation of this file.
1 /*
2 * contain.h
3 *
4 * Umbrella include for Container Classes.
5 *
6 * Portable Windows Library
7 *
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9 *
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
14 *
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * The Original Code is Portable Windows Library.
21 *
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23 *
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
26 *
27 * Contributor(s): ______________________________________.
28 *
29 * $Revision: 27066 $
30 * $Author: rjongbloed $
31 * $Date: 2012-02-28 19:23:49 +1100 (Tue, 28 Feb 2012) $
32 */
33
34 #ifndef PTLIB_CONTAIN_H
35 #define PTLIB_CONTAIN_H
36
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40
41
42 #include <ptlib/object.h>
43 #include <ptlib/critsec.h>
44
45
47 // Abstract container class
48
49 // The type below cannot be nested into PContainer as DevStudio 2005 AUTOEXP.DAT doesn't like it
50 class PContainerReference
51 {
52 public:
53 __inline PContainerReference(PINDEX initialSize, bool isConst = false)
54 : size(initialSize)
55 , count(1)
56 , deleteObjects(true)
57 , constObject(isConst)
58 {
59 }
60
61 __inline PContainerReference(const PContainerReference & ref)
62 : size(ref.size)
63 , count(1)
64 , deleteObjects(ref.deleteObjects)
65 , constObject(false)
66 {
67 }
68
69 PINDEX size; // Size of what the container contains
70 PAtomicInteger count; // reference count to the container content - guaranteed to be atomic
71 bool deleteObjects; // Used by PCollection but put here for efficiency
72 bool constObject; // Indicates object is constant/static, copy on write.
73
74 PDECLARE_POOL_ALLOCATOR();
75
76 private:
77 void operator=(const PContainerReference &) { }
78 };
79
80
103 class PContainer : public PObject
104 {
105 PCLASSINFO(PContainer, PObject);
106
107 public:
112 PContainer(
113 PINDEX initialSize = 0
114 );
115
120 PContainer(
121 const PContainer & cont
122 );
123
131 PContainer & operator=(
132 const PContainer & cont
133 );
134
139 virtual ~PContainer()
140 { Destruct(); }
141
143
152 virtual PINDEX GetSize() const;
153
167 virtual PBoolean SetSize(
168 PINDEX newSize
169 ) = 0;
170
176 PBoolean SetMinSize(
177 PINDEX minSize
178 );
179
186 virtual PBoolean IsEmpty() const;
187
194 PBoolean IsUnique() const;
195
204 virtual PBoolean MakeUnique();
206
207 protected:
218 PContainer(
219 int dummy,
220 const PContainer * cont
221 );
222
224 PContainer(PContainerReference & reference);
225
236 virtual void DestroyContents() = 0;
237
247 virtual void AssignContents(const PContainer & c);
248
260 void CopyContents(const PContainer & c);
261
278 void CloneContents(const PContainer * src);
279
283 void Destruct();
284
288 virtual void DestroyReference();
289
290 PContainerReference * reference;
291 };
292
293
294
342 #define PCONTAINERINFO(cls, par) \
343 PCLASSINFO(cls, par) \
344 public: \
345 cls(const cls & c) : par(c) { CopyContents(c); } \
346 cls & operator=(const cls & c) \
347 { AssignContents(c); return *this; } \
348 virtual ~cls() { Destruct(); } \
349 virtual PBoolean MakeUnique() \
350 { if(par::MakeUnique())return true; CloneContents(this);return false; } \
351 protected: \
352 cls(int dummy, const cls * c) : par(dummy, c) { CloneContents(c); } \
353 virtual void DestroyContents(); \
354 void CloneContents(const cls * c); \
355 void CopyContents(const cls & c); \
356 virtual void AssignContents(const PContainer & c) \
357 { par::AssignContents(c); CopyContents((const cls &)c); }
358
359
361 // Abstract collection of objects class
362
394 class PCollection : public PContainer
395 {
396 PCLASSINFO(PCollection, PContainer);
397
398 public:
403 PCollection(
404 PINDEX initialSize = 0
405 );
407
423 virtual void PrintOn(
424 ostream &strm
425 ) const;
427
439 virtual PINDEX Append(
440 PObject * obj
441 ) = 0;
442
459 virtual PINDEX Insert(
460 const PObject & before,
461 PObject * obj
462 ) = 0;
463
475 virtual PINDEX InsertAt(
476 PINDEX index,
477 PObject * obj
478 ) = 0;
479
489 virtual PBoolean Remove(
490 const PObject * obj
491 ) = 0;
492
501 virtual PObject * RemoveAt(
502 PINDEX index
503 ) = 0;
504
511 virtual void RemoveAll();
512
526 virtual PBoolean SetAt(
527 PINDEX index,
528 PObject * val
529 ) = 0;
530
536 virtual PObject * GetAt(
537 PINDEX index
538 ) const = 0;
539
546 virtual PINDEX GetObjectsIndex(
547 const PObject * obj
548 ) const = 0;
549
558 virtual PINDEX GetValuesIndex(
559 const PObject & obj
560 ) const = 0;
561
575 PINLINE void AllowDeleteObjects(
576 PBoolean yes = true
577 );
578
582 void DisallowDeleteObjects();
584
585 protected:
596 PINLINE PCollection(
597 int dummy,
598 const PCollection * coll
599 );
600 };
601
602
603
605 // The abstract array class
606
607 #include <ptlib/array.h>
608
610 // The abstract array class
611
612 #include <ptlib/lists.h>
613
615 // PString class (specialised version of PBASEARRAY(char))
616
617 #include <ptlib/dict.h>
618
619
621 // PString class
622
623 #include <ptlib/pstring.h>
624
625
626
628 // Fill in all the inline functions
629
630 #if P_USE_INLINES
631 #include <ptlib/contain.inl>
632 #endif
633
634
635 #endif // PTLIB_CONTAIN_H
636
637
638 // End Of File ///////////////////////////////////////////////////////////////