0029764: Foundation Classes, TColStd_MapIteratorOfPackedMapOfInteger - workaround...
[occt.git] / src / TColStd / TColStd_PackedMapOfInteger.cxx
index 68f6196..b4e0f91 100644 (file)
 // commercial license or contractual agreement.
 
 #include <TColStd_PackedMapOfInteger.hxx>
-#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
+
 #include <TCollection_MapNode.hxx>
-#include <Standard_DefineHandle.hxx>
+#include <Standard_Type.hxx>
 
 // 5 lower bits
 #define MASK_LOW  0x001f
 // 27 upper bits
 #define MASK_HIGH (~MASK_LOW)
 
-/**
- * Class implementing a block of 32 consecutive integer values as a node of
- * a Map collection. The data are stored in 64 bits as:
- * - bits  0 - 4 : (number of integers stored in the block) - 1;
- * - bits  5 - 31: base address of the block of integers (low bits assumed 0)
- * - bits 32 - 63: 32-bit field where each bit indicates the presence of the
- *                 corresponding integer in the block. Number of non-zero bits
- *                 must be equal to the number expressed in bits 0-4.
- */
-class TColStd_intMapNode : public TCollection_MapNode
+//! Class implementing a block of 32 consecutive integer values as a node of a Map collection.
+class TColStd_PackedMapOfInteger::TColStd_intMapNode : public TCollection_MapNode
 {
 public:
   inline TColStd_intMapNode (TCollection_MapNode * ptr = 0L)
@@ -103,18 +95,6 @@ public:
     return ((myMask >> 5) == (unsigned)theOther);
   }
 
-  /**
-   * Local friend function, used in TColStd_MapIteratorOfPackedMapOfInteger.
-   */
-  friend Standard_Integer TColStd_intMapNode_findNext(const TColStd_intMapNode*,
-                                                      unsigned int& );
-
-  /**
-   * Local friend function.
-   */
-  friend Standard_Integer TColStd_intMapNode_findPrev(const TColStd_intMapNode*,
-                                                      unsigned int& );
-
 private:
   unsigned int      myMask;
   unsigned int      myData;
@@ -126,7 +106,7 @@ private:
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean TColStd_intMapNode::AddValue (const Standard_Integer theValue)
+Standard_Boolean TColStd_PackedMapOfInteger::TColStd_intMapNode::AddValue (const Standard_Integer theValue)
 {
   Standard_Boolean aResult (Standard_False);
   const Standard_Integer aValInt = (1 << (theValue & MASK_LOW));
@@ -143,7 +123,7 @@ Standard_Boolean TColStd_intMapNode::AddValue (const Standard_Integer theValue)
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean TColStd_intMapNode::DelValue (const Standard_Integer theValue)
+Standard_Boolean TColStd_PackedMapOfInteger::TColStd_intMapNode::DelValue (const Standard_Integer theValue)
 {
   Standard_Boolean aResult (Standard_False);
   const Standard_Integer aValInt = (1 << (theValue & MASK_LOW));
@@ -177,14 +157,13 @@ inline size_t TColStd_Population (unsigned int&      theMask,
 
 //=======================================================================
 //function : TColStd_intMapNode_findNext
-//purpose  : Find the smallest non-zero bit under the given mask. Outputs
-//           the new mask that does not contain the detected bit.
+//purpose  :
 //=======================================================================
-
-Standard_Integer TColStd_intMapNode_findNext (const TColStd_intMapNode* theNode,
-                                              unsigned int&             theMask)
+Standard_Integer TColStd_PackedMapOfInteger::TColStd_intMapNode_findNext (const Standard_Address theNode,
+                                                                          unsigned int&          theMask)
 {
-  unsigned int val = theNode->myData & theMask;
+  const TColStd_intMapNode* aNode = reinterpret_cast<const TColStd_intMapNode*> (theNode);
+  unsigned int val = aNode->Data() & theMask;
   int nZeros (0);
   if (val == 0)
     theMask = ~0U;   // void, nothing to do
@@ -216,19 +195,18 @@ Standard_Integer TColStd_intMapNode_findNext (const TColStd_intMapNode* theNode,
     }
     theMask = (aMask << 1);
   }
-  return nZeros + theNode->Key();
+  return nZeros + aNode->Key();
 }
 
 //=======================================================================
 //function : TColStd_intMapNode_findPrev
-//purpose  : Find the highest non-zero bit under the given mask. Outputs
-//           the new mask that does not contain the detected bit.
+//purpose  :
 //=======================================================================
-
-Standard_Integer TColStd_intMapNode_findPrev (const TColStd_intMapNode* theNode,
-                                              unsigned int&             theMask)
+Standard_Integer TColStd_PackedMapOfInteger::TColStd_intMapNode_findPrev (const Standard_Address theNode,
+                                                                          unsigned int&          theMask)
 {
-  unsigned int val = theNode->myData & theMask;
+  const TColStd_intMapNode* aNode = reinterpret_cast<const TColStd_intMapNode*> (theNode);
+  unsigned int val = aNode->Data() & theMask;
   int nZeros (0);
   if (val == 0)
     theMask = ~0U;   // void, nothing to do
@@ -260,7 +238,7 @@ Standard_Integer TColStd_intMapNode_findPrev (const TColStd_intMapNode* theNode,
     }
     theMask = (aMask >> 1);
   }
-  return (31 - nZeros) + theNode->Key();
+  return (31 - nZeros) + aNode->Key();
 }
 
 //=======================================================================
@@ -479,7 +457,7 @@ Standard_Integer TColStd_PackedMapOfInteger::GetMinimalMapped () const
     }
     if (pFoundNode) {
       unsigned int aFullMask (0xffffffff);
-      aResult = TColStd_intMapNode_findNext (pFoundNode, aFullMask);
+      aResult = TColStd_intMapNode_findNext ((const Standard_Address )pFoundNode, aFullMask);
     }
   }
   return aResult;
@@ -508,7 +486,7 @@ Standard_Integer TColStd_PackedMapOfInteger::GetMaximalMapped () const
     }
     if (pFoundNode) {
       unsigned int aFullMask (0xffffffff);
-      aResult = TColStd_intMapNode_findPrev (pFoundNode, aFullMask);
+      aResult = TColStd_intMapNode_findPrev ((const Standard_Address )pFoundNode, aFullMask);
     }
   }
   return aResult;
@@ -1215,6 +1193,8 @@ Standard_Boolean TColStd_PackedMapOfInteger::IsSubset (const TColStd_PackedMapOf
         // Find the corresponding block in the 2nd map
         const TColStd_intMapNode * p2 =
           aData2 [HashCode (aKeyInt, nBuckets2)];
+        if (!p2)
+          return Standard_False;
         while (p2) {
           if ( p2->IsEqual(aKeyInt) ) {
             if ( p1->Data() & ~p2->Data() ) // at least one bit set in p1 is not set in p2