diff --git a/src/TColStd/FILES b/src/TColStd/FILES index 911ffe6399..ee75061d79 100755 --- a/src/TColStd/FILES +++ b/src/TColStd/FILES @@ -68,7 +68,6 @@ TColStd_MapIteratorOfMapOfAsciiString.hxx TColStd_MapIteratorOfMapOfInteger.hxx TColStd_MapIteratorOfMapOfReal.hxx TColStd_MapIteratorOfMapOfTransient.hxx -TColStd_MapIteratorOfPackedMapOfInteger.cxx TColStd_MapIteratorOfPackedMapOfInteger.hxx TColStd_MapOfAsciiString.hxx TColStd_MapOfInteger.hxx diff --git a/src/TColStd/TColStd_MapIteratorOfPackedMapOfInteger.cxx b/src/TColStd/TColStd_MapIteratorOfPackedMapOfInteger.cxx deleted file mode 100644 index a159184c9d..0000000000 --- a/src/TColStd/TColStd_MapIteratorOfPackedMapOfInteger.cxx +++ /dev/null @@ -1,90 +0,0 @@ -// Created on: 2005-12-09 -// Created by: Alexander GRIGORIEV -// Copyright (c) 2005-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -class TColStd_intMapNode; - -extern Standard_Integer TColStd_intMapNode_findNext (const TColStd_intMapNode *, - unsigned int& ); - -//======================================================================= -//function : TColStd_MapIteratorOfPackedMapOfInteger -//purpose : Constructor -//======================================================================= - -TColStd_MapIteratorOfPackedMapOfInteger::TColStd_MapIteratorOfPackedMapOfInteger - (const TColStd_PackedMapOfInteger& theMap) - : TCollection_BasicMapIterator (theMap), - myIntMask (~0U) -{ - if (myNode) { - const TColStd_intMapNode * aNode = - reinterpret_cast (myNode); - myKey = TColStd_intMapNode_findNext (aNode, myIntMask); - } -} - - -//======================================================================= -//function : Initialize -//purpose : -//======================================================================= - -void TColStd_MapIteratorOfPackedMapOfInteger::Initialize - (const TColStd_PackedMapOfInteger& theMap) -{ - TCollection_BasicMapIterator::Initialize (theMap); - myIntMask = ~0U; - if (myNode) { - const TColStd_intMapNode * aNode = - reinterpret_cast (myNode); - myKey = TColStd_intMapNode_findNext (aNode, myIntMask); - } -} - -//======================================================================= -//function : Reset -//purpose : -//======================================================================= - -void TColStd_MapIteratorOfPackedMapOfInteger::Reset () -{ - TCollection_BasicMapIterator::Reset(); - myIntMask = ~0U; - if (myNode) { - const TColStd_intMapNode * aNode = - reinterpret_cast (myNode); - myKey = TColStd_intMapNode_findNext (aNode, myIntMask); - } -} - -//======================================================================= -//function : Next -//purpose : -//======================================================================= - -void TColStd_MapIteratorOfPackedMapOfInteger::Next () -{ - while (myNode) { - const TColStd_intMapNode * aNode = - reinterpret_cast (myNode); - myKey = TColStd_intMapNode_findNext (aNode, myIntMask); - if (myIntMask != ~0u) - break; - TCollection_BasicMapIterator::Next(); - } -} diff --git a/src/TColStd/TColStd_MapIteratorOfPackedMapOfInteger.hxx b/src/TColStd/TColStd_MapIteratorOfPackedMapOfInteger.hxx index 8b783b77ab..dcfc6ee5d7 100644 --- a/src/TColStd/TColStd_MapIteratorOfPackedMapOfInteger.hxx +++ b/src/TColStd/TColStd_MapIteratorOfPackedMapOfInteger.hxx @@ -16,49 +16,9 @@ #ifndef TColStd_MapIteratorOfPackedMapOfInteger_HeaderFile #define TColStd_MapIteratorOfPackedMapOfInteger_HeaderFile -#include -#include - -class TColStd_PackedMapOfInteger; - -/** - * Iterator of class TColStd_PackedMapOfInteger - */ - -class TColStd_MapIteratorOfPackedMapOfInteger: public TCollection_BasicMapIterator -{ - public: - // ---------- PUBLIC METHODS ---------- - - /// Empty Constructor. - inline TColStd_MapIteratorOfPackedMapOfInteger() - : myIntMask (~0U), myKey (0) {} - - /// Constructor. - Standard_EXPORT TColStd_MapIteratorOfPackedMapOfInteger - (const TColStd_PackedMapOfInteger&); - - /// Re-initialize with the same or another Map instance. - Standard_EXPORT void Initialize (const TColStd_PackedMapOfInteger&); - - /// Restart the iteraton - Standard_EXPORT void Reset(); - - /// Query the iterated key. Defined in TColStd_PackedMapOfInteger.cxx - inline Standard_Integer Key () const - { - Standard_NoSuchObject_Raise_if ((myIntMask == ~0U), - "TColStd_MapIteratorOfPackedMapOfInteger::Key"); - return myKey; - } - - /// Increment the iterator - Standard_EXPORT void Next(); - -private: - unsigned int myIntMask; ///< all bits set above the iterated position - Standard_Integer myKey; ///< Currently iterated key -}; +#include +//! Iterator of class TColStd_PackedMapOfInteger. +typedef TColStd_PackedMapOfInteger::Iterator TColStd_MapIteratorOfPackedMapOfInteger; #endif diff --git a/src/TColStd/TColStd_PackedMapOfInteger.cxx b/src/TColStd/TColStd_PackedMapOfInteger.cxx index ce544612c8..6a82f2d0f6 100644 --- a/src/TColStd/TColStd_PackedMapOfInteger.cxx +++ b/src/TColStd/TColStd_PackedMapOfInteger.cxx @@ -14,7 +14,7 @@ // commercial license or contractual agreement. #include -#include + #include #include @@ -23,16 +23,8 @@ // 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,12 @@ 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 TColStd_intMapNode* theNode, + unsigned int& theMask) { - unsigned int val = theNode->myData & theMask; + unsigned int val = theNode->Data() & theMask; int nZeros (0); if (val == 0) theMask = ~0U; // void, nothing to do @@ -221,14 +199,12 @@ Standard_Integer TColStd_intMapNode_findNext (const TColStd_intMapNode* theNode, //======================================================================= //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 TColStd_intMapNode* theNode, + unsigned int& theMask) { - unsigned int val = theNode->myData & theMask; + unsigned int val = theNode->Data() & theMask; int nZeros (0); if (val == 0) theMask = ~0U; // void, nothing to do diff --git a/src/TColStd/TColStd_PackedMapOfInteger.hxx b/src/TColStd/TColStd_PackedMapOfInteger.hxx index dc56eaceb7..340666600b 100644 --- a/src/TColStd/TColStd_PackedMapOfInteger.hxx +++ b/src/TColStd/TColStd_PackedMapOfInteger.hxx @@ -17,7 +17,9 @@ #define TColStd_PackedMapOfInteger_HeaderFile #include +#include #include +#include /** * Optimized Map of integer values. Each block of 32 integers is stored in 8 bytes in memory. @@ -28,9 +30,68 @@ class TColStd_PackedMapOfInteger : private TCollection_BasicMap // operators new and delete must be defined explicitly // since inherited ones are not accessible DEFINE_STANDARD_ALLOC - - public: - // ---------- PUBLIC METHODS ---------- + +public: + + //! Iterator of class TColStd_PackedMapOfInteger. + class Iterator : public TCollection_BasicMapIterator + { + public: + + /// Empty Constructor. + Iterator() : myIntMask (~0U), myKey (0) {} + + /// Constructor. + Iterator (const TColStd_PackedMapOfInteger& theMap) + : TCollection_BasicMapIterator (theMap), + myIntMask (~0U) + { + myKey = myNode != NULL ? TColStd_intMapNode_findNext (reinterpret_cast(myNode), myIntMask) : 0; + } + + //! Re-initialize with the same or another Map instance. + void Initialize (const TColStd_PackedMapOfInteger& theMap) + { + TCollection_BasicMapIterator::Initialize (theMap); + myIntMask = ~0U; + myKey = myNode != NULL ? TColStd_intMapNode_findNext (reinterpret_cast(myNode), myIntMask) : 0; + } + + //! Restart the iteration + void Reset() + { + TCollection_BasicMapIterator::Reset(); + myIntMask = ~0U; + myKey = myNode != NULL ? TColStd_intMapNode_findNext (reinterpret_cast(myNode), myIntMask) : 0; + } + + //! Query the iterated key. + Standard_Integer Key() const + { + Standard_NoSuchObject_Raise_if ((myIntMask == ~0U), "TColStd_MapIteratorOfPackedMapOfInteger::Key"); + return myKey; + } + + //! Increment the iterator + void Next() + { + for (; myNode != NULL; TCollection_BasicMapIterator::Next()) + { + const TColStd_intMapNode* aNode = reinterpret_cast(myNode); + myKey = TColStd_intMapNode_findNext (aNode, myIntMask); + if (myIntMask != ~0u) + { + break; + } + } + } + + private: + unsigned int myIntMask; //!< all bits set above the iterated position + Standard_Integer myKey; //!< Currently iterated key + }; + +public: /// Constructor inline TColStd_PackedMapOfInteger (const Standard_Integer NbBuckets = 1) @@ -214,13 +275,28 @@ public: inline Standard_Integer InternalExtent () const { return TCollection_BasicMap::Extent(); } +private: - private: - // ---------- PRIVATE FIELDS ---------- + //! 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; - size_t myExtent; + //! Find the smallest non-zero bit under the given mask. + //! Outputs the new mask that does not contain the detected bit. + Standard_EXPORT static Standard_Integer TColStd_intMapNode_findNext (const TColStd_intMapNode* theNode, + unsigned int& theMask); - friend class TColStd_MapIteratorOfPackedMapOfInteger; + //! Find the highest non-zero bit under the given mask. + //! Outputs the new mask that does not contain the detected bit. + Standard_EXPORT static Standard_Integer TColStd_intMapNode_findPrev (const TColStd_intMapNode* theNode, + unsigned int& theMask); + +private: + size_t myExtent; }; #endif