0024911: Avoid using virtual functions in NCollection classes
[occt.git] / src / NCollection / NCollection_IndexedDataMap.hxx
index 939db85..27f7a0f 100644 (file)
@@ -16,7 +16,6 @@
 #ifndef NCollection_IndexedDataMap_HeaderFile
 #define NCollection_IndexedDataMap_HeaderFile
 
-#include <NCollection_BaseCollection.hxx>
 #include <NCollection_BaseMap.hxx>
 #include <NCollection_TListNode.hxx>
 #include <Standard_TypeMismatch.hxx>
@@ -50,9 +49,7 @@
 template < class TheKeyType, 
            class TheItemType, 
            class Hasher = NCollection_DefaultHasher<TheKeyType> > 
-  class NCollection_IndexedDataMap 
-  : public NCollection_BaseCollection<TheItemType>,
-    public NCollection_BaseMap
+class NCollection_IndexedDataMap : public NCollection_BaseMap
 {
   //!    Adaptation of the TListNode to the INDEXEDDatamap
  private:
@@ -96,7 +93,7 @@ template < class TheKeyType,
 
  public:
   //!   Implementation of the Iterator interface.
-  class Iterator : public NCollection_BaseCollection<TheItemType>::Iterator
+  class Iterator
   {
   public:
     //! Empty constructor
@@ -109,15 +106,15 @@ template < class TheKeyType,
       myNode (myMap->nodeFromIndex (1)),
       myIndex (1) {}
     //! Query if the end of collection is reached by iterator
-    virtual Standard_Boolean More(void) const
+    Standard_Boolean More(void) const
     { return (myMap != NULL) && (myIndex <= myMap->Extent()); }
     //! Make a step along the collection
-    virtual void Next(void)
+    void Next(void)
     {
       myNode = myMap->nodeFromIndex (++myIndex);
     }
     //! Value access
-    virtual const TheItemType& Value(void) const
+    const TheItemType& Value(void) const
     {  
 #if !defined No_Exception && !defined No_Standard_NoSuchObject
       if (!More())
@@ -126,7 +123,7 @@ template < class TheKeyType,
       return myNode->Value();
     }
     //! ChangeValue access
-    virtual TheItemType& ChangeValue(void) const
+    TheItemType& ChangeValue(void) const
     {  
 #if !defined No_Exception && !defined No_Standard_NoSuchObject
       if (!More())
@@ -144,7 +141,7 @@ template < class TheKeyType,
       return myNode->Key1();
     }
     //! Performs comparison of two iterators.
-    virtual Standard_Boolean IsEqual (const Iterator& theOther) const
+    Standard_Boolean IsEqual (const Iterator& theOther) const
     {
       return myMap == theOther.myMap &&
              myNode == theOther.myNode &&
@@ -180,34 +177,22 @@ template < class TheKeyType,
   //! Constructor
   NCollection_IndexedDataMap (const Standard_Integer NbBuckets=1,
                      const Handle(NCollection_BaseAllocator)& theAllocator = 0L)
-    :  NCollection_BaseCollection<TheItemType>(theAllocator),
-       NCollection_BaseMap (NbBuckets, Standard_False) {}
+    :  NCollection_BaseMap (NbBuckets, Standard_False, theAllocator) {}
 
   //! Copy constructor
   NCollection_IndexedDataMap (const NCollection_IndexedDataMap& theOther) 
-    : NCollection_BaseCollection<TheItemType>(theOther.myAllocator),
-      NCollection_BaseMap (theOther.NbBuckets(), Standard_False) 
+    : NCollection_BaseMap (theOther.NbBuckets(), Standard_False, theOther.myAllocator) 
   { *this = theOther; }
 
-  //! Assign another collection
-  virtual void Assign(const NCollection_BaseCollection<TheItemType>& theOther)
-  { 
-    if (this == &theOther)
-      return;
-    Standard_TypeMismatch::Raise("NCollection_IndexedDataMap::Assign");
-  }
-
   //! Exchange the content of two maps without re-allocations.
   //! Notice that allocators will be swapped as well!
   void Exchange (NCollection_IndexedDataMap& theOther)
   {
-    this->exchangeAllocators (theOther);
-    this->exchangeMapsData   (theOther);
+    this->exchangeMapsData (theOther);
   }
 
-  //! = another map
-  NCollection_IndexedDataMap& operator= 
-    (const NCollection_IndexedDataMap& theOther)
+  //! Assignment
+  NCollection_IndexedDataMap& Assign (const NCollection_IndexedDataMap& theOther)
   { 
     if (this == &theOther)
       return *this;
@@ -231,13 +216,19 @@ template < class TheKeyType,
     return *this;
   }
 
+  //! Assignment operator
+  NCollection_IndexedDataMap& operator= (const NCollection_IndexedDataMap& theOther)
+  { 
+    return Assign (theOther);
+  }
+
   //! ReSize
   void ReSize (const Standard_Integer N)
   {
     NCollection_ListNode** ppNewData1 = NULL;
     NCollection_ListNode** ppNewData2 = NULL;
     Standard_Integer newBuck;
-    if (BeginResize (N, newBuck, ppNewData1, ppNewData2, this->myAllocator)) 
+    if (BeginResize (N, newBuck, ppNewData1, ppNewData2))
     {
       if (myData1) 
       {
@@ -262,7 +253,7 @@ template < class TheKeyType,
           }
         }
       }
-      EndResize (N, newBuck, ppNewData1, ppNewData2, this->myAllocator);
+      EndResize (N, newBuck, ppNewData1, ppNewData2);
     }
   }
 
@@ -525,7 +516,7 @@ template < class TheKeyType,
   //! Clear data. If doReleaseMemory is false then the table of
   //! buckets is not released and will be reused.
   void Clear(const Standard_Boolean doReleaseMemory = Standard_True)
-  { Destroy (IndexedDataMapNode::delNode, this->myAllocator, doReleaseMemory); }
+  { Destroy (IndexedDataMapNode::delNode, doReleaseMemory); }
 
   //! Clear data and reset allocator
   void Clear (const Handle(NCollection_BaseAllocator)& theAllocator)
@@ -540,17 +531,12 @@ template < class TheKeyType,
   { Clear(); }
 
   //! Size
-  virtual Standard_Integer Size(void) const
+  Standard_Integer Size(void) const
   { return Extent(); }
 
  private:
   // ----------- PRIVATE METHODS -----------
 
-  //! Creates Iterator for use on BaseCollection
-  virtual TYPENAME NCollection_BaseCollection<TheItemType>::Iterator& 
-    CreateIterator(void) const
-  { return *(new (this->IterAllocator()) Iterator(*this)); }
-
   //! Find map node associated with specified index.
   //! Return NULL if not found (exception-free internal implementation).
   IndexedDataMapNode* nodeFromIndex (const Standard_Integer theKey2) const