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