Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2002-04-09 |
2 | // Created by: Alexander KARTOMIN (akm) | |
3 | // Copyright (c) 2002-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
7fd59977 | 20 | #ifndef NCollection_BaseCollection_HeaderFile |
21 | #define NCollection_BaseCollection_HeaderFile | |
22 | ||
23 | #include <NCollection_IncAllocator.hxx> | |
1c35b92f | 24 | #include <NCollection_DefineAlloc.hxx> |
7fd59977 | 25 | |
26 | /** | |
27 | * Purpose: NCollection_BaseCollection is the base abstract class for | |
28 | * all collection templates of this package. | |
29 | * The set of collections is similar to that of TCollection. | |
30 | * Also the methods of classes have mostly the same names for | |
31 | * easy switch from TCollection <-> NCollection containers. | |
32 | * | |
33 | * NCollection is a nocdlpack, thus it is compiled without WOK. | |
34 | * BaseCollection allows assigning the collections of different | |
35 | * kinds (the items type being the same) with a few obvious | |
36 | * exclusions - one can not assign any collection to the map | |
37 | * having double data (two keys or a key plus value). Only the | |
38 | * maps of the very same type may be assigned through operator= | |
39 | * Said maps are: DoubleMap, | |
40 | * DataMap, | |
41 | * IndexedDataMap | |
42 | * | |
43 | * For the users needing control over the memory usage the | |
44 | * allocators were added (see NCollection_BaseAllocator header) | |
45 | * Others may forget it - BaseAllocator is used by default and | |
46 | * then memory is managed through Standard::Allocate/::Free. | |
47 | */ | |
48 | template<class TheItemType> class NCollection_BaseCollection | |
49 | { | |
50 | public: | |
51 | // **************** The interface for iterating over collections | |
52 | class Iterator | |
53 | { | |
54 | public: | |
55 | //! Query if the end of collection is reached by iterator | |
56 | virtual Standard_Boolean More(void) const=0; | |
57 | //! Make a step along the collection | |
58 | virtual void Next(void)=0; | |
59 | //! Value inquiry | |
60 | virtual const TheItemType& Value(void) const=0; | |
61 | //! Value change access | |
62 | virtual TheItemType& ChangeValue(void) const=0; | |
1c35b92f | 63 | public: |
64 | DEFINE_STANDARD_ALLOC | |
65 | DEFINE_NCOLLECTION_ALLOC | |
7fd59977 | 66 | protected: |
67 | //! Empty constructor | |
68 | Iterator (void) {} | |
69 | //! Virtual destructor is necessary for classes with virtual methods | |
70 | virtual ~Iterator (void) {} | |
71 | protected: | |
72 | //! operator= is prohibited | |
73 | const Iterator& operator= (const Iterator&); | |
74 | //! Copy constructor ** | |
75 | Iterator (const Iterator&) {} | |
76 | }; // End of nested class Iterator | |
77 | ||
78 | public: | |
79 | // ---------- PUBLIC METHODS ------------ | |
80 | ||
81 | //! Common for all collections constructor takes care of theAllocator | |
82 | NCollection_BaseCollection | |
83 | (const Handle(NCollection_BaseAllocator)& theAllocator=0L) | |
84 | { | |
85 | if (theAllocator.IsNull()) | |
86 | myAllocator = NCollection_BaseAllocator::CommonBaseAllocator(); | |
87 | else | |
88 | myAllocator = theAllocator; | |
89 | } | |
90 | ||
91 | //! Number of items | |
92 | virtual Standard_Integer Size(void) const = 0; | |
93 | ||
94 | //! Virtual assignment | |
95 | virtual void Assign | |
96 | (const NCollection_BaseCollection& theOther)=0; | |
97 | ||
98 | //! Method to create iterators for base collections | |
99 | virtual Iterator& CreateIterator(void) const=0; | |
100 | ||
101 | //! Destructor - must be implemented to release the memory | |
102 | virtual ~NCollection_BaseCollection (void) {} | |
103 | ||
1145e2bc RL |
104 | //! Returns attached allocator |
105 | const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; } | |
106 | ||
7fd59977 | 107 | protected: |
108 | // --------- PROTECTED METHOD ----------- | |
109 | const Handle(NCollection_BaseAllocator)& IterAllocator(void) const | |
110 | { | |
111 | if (myIterAllocator.IsNull()) | |
112 | (Handle_NCollection_BaseAllocator&) myIterAllocator = | |
113 | new NCollection_IncAllocator(64); | |
114 | return myIterAllocator; | |
115 | } | |
116 | ||
ab2db9a5 | 117 | //! Exchange allocators of two collections |
118 | void exchangeAllocators (NCollection_BaseCollection& theOther) | |
119 | { | |
120 | std::swap (myAllocator, theOther.myAllocator); | |
121 | std::swap (myIterAllocator, theOther.myIterAllocator); | |
122 | } | |
123 | ||
7fd59977 | 124 | protected: |
125 | // --------- PROTECTED FIELDS ----------- | |
126 | Handle(NCollection_BaseAllocator) myAllocator; | |
127 | private: | |
128 | // ---------- PRIVATE FIELDS ------------ | |
129 | Handle(NCollection_BaseAllocator) myIterAllocator; | |
130 | ||
131 | }; | |
132 | ||
133 | #endif |