1 // Created on: 2002-04-09
2 // Created by: Alexander KARTOMIN (akm)
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
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.
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.
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.
21 #ifndef NCollection_BaseCollection_HeaderFile
22 #define NCollection_BaseCollection_HeaderFile
24 #include <NCollection_IncAllocator.hxx>
25 #include <NCollection_DefineAlloc.hxx>
28 * Purpose: NCollection_BaseCollection is the base abstract class for
29 * all collection templates of this package.
30 * The set of collections is similar to that of TCollection.
31 * Also the methods of classes have mostly the same names for
32 * easy switch from TCollection <-> NCollection containers.
34 * NCollection is a nocdlpack, thus it is compiled without WOK.
35 * BaseCollection allows assigning the collections of different
36 * kinds (the items type being the same) with a few obvious
37 * exclusions - one can not assign any collection to the map
38 * having double data (two keys or a key plus value). Only the
39 * maps of the very same type may be assigned through operator=
40 * Said maps are: DoubleMap,
44 * For the users needing control over the memory usage the
45 * allocators were added (see NCollection_BaseAllocator header)
46 * Others may forget it - BaseAllocator is used by default and
47 * then memory is managed through Standard::Allocate/::Free.
49 template<class TheItemType> class NCollection_BaseCollection
52 // **************** The interface for iterating over collections
56 //! Query if the end of collection is reached by iterator
57 virtual Standard_Boolean More(void) const=0;
58 //! Make a step along the collection
59 virtual void Next(void)=0;
61 virtual const TheItemType& Value(void) const=0;
62 //! Value change access
63 virtual TheItemType& ChangeValue(void) const=0;
66 DEFINE_NCOLLECTION_ALLOC
70 //! Virtual destructor is necessary for classes with virtual methods
71 virtual ~Iterator (void) {}
73 //! operator= is prohibited
74 const Iterator& operator= (const Iterator&);
75 //! Copy constructor **
76 Iterator (const Iterator&) {}
77 }; // End of nested class Iterator
80 // ---------- PUBLIC METHODS ------------
82 //! Common for all collections constructor takes care of theAllocator
83 NCollection_BaseCollection
84 (const Handle(NCollection_BaseAllocator)& theAllocator=0L)
86 if (theAllocator.IsNull())
87 myAllocator = NCollection_BaseAllocator::CommonBaseAllocator();
89 myAllocator = theAllocator;
93 virtual Standard_Integer Size(void) const = 0;
95 //! Virtual assignment
97 (const NCollection_BaseCollection& theOther)=0;
99 //! Method to create iterators for base collections
100 virtual Iterator& CreateIterator(void) const=0;
102 //! Destructor - must be implemented to release the memory
103 virtual ~NCollection_BaseCollection (void) {}
105 //! Returns attached allocator
106 const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; }
109 // --------- PROTECTED METHOD -----------
110 const Handle(NCollection_BaseAllocator)& IterAllocator(void) const
112 if (myIterAllocator.IsNull())
113 (Handle_NCollection_BaseAllocator&) myIterAllocator =
114 new NCollection_IncAllocator(64);
115 return myIterAllocator;
119 // --------- PROTECTED FIELDS -----------
120 Handle(NCollection_BaseAllocator) myAllocator;
122 // ---------- PRIVATE FIELDS ------------
123 Handle(NCollection_BaseAllocator) myIterAllocator;