7fd59977 |
1 | // File: NCollection_BaseCollection.hxx |
2 | // Created: Tue Apr 9 18:53:36 2002 |
3 | // Author: Alexander KARTOMIN (akm) |
4 | // <a-kartomin@opencascade.com> |
5 | |
6 | #ifndef NCollection_BaseCollection_HeaderFile |
7 | #define NCollection_BaseCollection_HeaderFile |
8 | |
9 | #include <NCollection_IncAllocator.hxx> |
1c35b92f |
10 | #include <NCollection_DefineAlloc.hxx> |
7fd59977 |
11 | |
12 | /** |
13 | * Purpose: NCollection_BaseCollection is the base abstract class for |
14 | * all collection templates of this package. |
15 | * The set of collections is similar to that of TCollection. |
16 | * Also the methods of classes have mostly the same names for |
17 | * easy switch from TCollection <-> NCollection containers. |
18 | * |
19 | * NCollection is a nocdlpack, thus it is compiled without WOK. |
20 | * BaseCollection allows assigning the collections of different |
21 | * kinds (the items type being the same) with a few obvious |
22 | * exclusions - one can not assign any collection to the map |
23 | * having double data (two keys or a key plus value). Only the |
24 | * maps of the very same type may be assigned through operator= |
25 | * Said maps are: DoubleMap, |
26 | * DataMap, |
27 | * IndexedDataMap |
28 | * |
29 | * For the users needing control over the memory usage the |
30 | * allocators were added (see NCollection_BaseAllocator header) |
31 | * Others may forget it - BaseAllocator is used by default and |
32 | * then memory is managed through Standard::Allocate/::Free. |
33 | */ |
34 | template<class TheItemType> class NCollection_BaseCollection |
35 | { |
36 | public: |
37 | // **************** The interface for iterating over collections |
38 | class Iterator |
39 | { |
40 | public: |
41 | //! Query if the end of collection is reached by iterator |
42 | virtual Standard_Boolean More(void) const=0; |
43 | //! Make a step along the collection |
44 | virtual void Next(void)=0; |
45 | //! Value inquiry |
46 | virtual const TheItemType& Value(void) const=0; |
47 | //! Value change access |
48 | virtual TheItemType& ChangeValue(void) const=0; |
1c35b92f |
49 | public: |
50 | DEFINE_STANDARD_ALLOC |
51 | DEFINE_NCOLLECTION_ALLOC |
7fd59977 |
52 | protected: |
53 | //! Empty constructor |
54 | Iterator (void) {} |
55 | //! Virtual destructor is necessary for classes with virtual methods |
56 | virtual ~Iterator (void) {} |
57 | protected: |
58 | //! operator= is prohibited |
59 | const Iterator& operator= (const Iterator&); |
60 | //! Copy constructor ** |
61 | Iterator (const Iterator&) {} |
62 | }; // End of nested class Iterator |
63 | |
64 | public: |
65 | // ---------- PUBLIC METHODS ------------ |
66 | |
67 | //! Common for all collections constructor takes care of theAllocator |
68 | NCollection_BaseCollection |
69 | (const Handle(NCollection_BaseAllocator)& theAllocator=0L) |
70 | { |
71 | if (theAllocator.IsNull()) |
72 | myAllocator = NCollection_BaseAllocator::CommonBaseAllocator(); |
73 | else |
74 | myAllocator = theAllocator; |
75 | } |
76 | |
77 | //! Number of items |
78 | virtual Standard_Integer Size(void) const = 0; |
79 | |
80 | //! Virtual assignment |
81 | virtual void Assign |
82 | (const NCollection_BaseCollection& theOther)=0; |
83 | |
84 | //! Method to create iterators for base collections |
85 | virtual Iterator& CreateIterator(void) const=0; |
86 | |
87 | //! Destructor - must be implemented to release the memory |
88 | virtual ~NCollection_BaseCollection (void) {} |
89 | |
90 | protected: |
91 | // --------- PROTECTED METHOD ----------- |
92 | const Handle(NCollection_BaseAllocator)& IterAllocator(void) const |
93 | { |
94 | if (myIterAllocator.IsNull()) |
95 | (Handle_NCollection_BaseAllocator&) myIterAllocator = |
96 | new NCollection_IncAllocator(64); |
97 | return myIterAllocator; |
98 | } |
99 | |
100 | protected: |
101 | // --------- PROTECTED FIELDS ----------- |
102 | Handle(NCollection_BaseAllocator) myAllocator; |
103 | private: |
104 | // ---------- PRIVATE FIELDS ------------ |
105 | Handle(NCollection_BaseAllocator) myIterAllocator; |
106 | |
107 | }; |
108 | |
109 | #endif |