OCC22540 Regression: Exception during building of patch by GeomPlate
[occt.git] / src / NCollection / NCollection_BaseCollection.hxx
CommitLineData
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>
10
11/**
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.
17*
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,
25* DataMap,
26* IndexedDataMap
27*
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.
32*/
33template<class TheItemType> class NCollection_BaseCollection
34{
35 public:
36 // **************** The interface for iterating over collections
37 class Iterator
38 {
39 public:
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;
44 //! Value inquiry
45 virtual const TheItemType& Value(void) const=0;
46 //! Value change access
47 virtual TheItemType& ChangeValue(void) const=0;
48 protected:
49 //! Empty constructor
50 Iterator (void) {}
51 //! Virtual destructor is necessary for classes with virtual methods
52 virtual ~Iterator (void) {}
53 protected:
54 //! operator= is prohibited
55 const Iterator& operator= (const Iterator&);
56 //! Copy constructor **
57 Iterator (const Iterator&) {}
58 }; // End of nested class Iterator
59
60 public:
61 // ---------- PUBLIC METHODS ------------
62
63 //! Common for all collections constructor takes care of theAllocator
64 NCollection_BaseCollection
65 (const Handle(NCollection_BaseAllocator)& theAllocator=0L)
66 {
67 if (theAllocator.IsNull())
68 myAllocator = NCollection_BaseAllocator::CommonBaseAllocator();
69 else
70 myAllocator = theAllocator;
71 }
72
73 //! Number of items
74 virtual Standard_Integer Size(void) const = 0;
75
76 //! Virtual assignment
77 virtual void Assign
78 (const NCollection_BaseCollection& theOther)=0;
79
80 //! Method to create iterators for base collections
81 virtual Iterator& CreateIterator(void) const=0;
82
83 //! Destructor - must be implemented to release the memory
84 virtual ~NCollection_BaseCollection (void) {}
85
86 protected:
87 // --------- PROTECTED METHOD -----------
88 const Handle(NCollection_BaseAllocator)& IterAllocator(void) const
89 {
90 if (myIterAllocator.IsNull())
91 (Handle_NCollection_BaseAllocator&) myIterAllocator =
92 new NCollection_IncAllocator(64);
93 return myIterAllocator;
94 }
95
96 protected:
97 // --------- PROTECTED FIELDS -----------
98 Handle(NCollection_BaseAllocator) myAllocator;
99 private:
100 // ---------- PRIVATE FIELDS ------------
101 Handle(NCollection_BaseAllocator) myIterAllocator;
102
103};
104
105#endif