mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0029376: Coding Rules, TColStd_PackedMapOfInteger - declare Iterator as nested class of map collection
This commit is contained in:
parent
803a8cafe5
commit
683d15cbd4
@ -68,7 +68,6 @@ TColStd_MapIteratorOfMapOfAsciiString.hxx
|
|||||||
TColStd_MapIteratorOfMapOfInteger.hxx
|
TColStd_MapIteratorOfMapOfInteger.hxx
|
||||||
TColStd_MapIteratorOfMapOfReal.hxx
|
TColStd_MapIteratorOfMapOfReal.hxx
|
||||||
TColStd_MapIteratorOfMapOfTransient.hxx
|
TColStd_MapIteratorOfMapOfTransient.hxx
|
||||||
TColStd_MapIteratorOfPackedMapOfInteger.cxx
|
|
||||||
TColStd_MapIteratorOfPackedMapOfInteger.hxx
|
TColStd_MapIteratorOfPackedMapOfInteger.hxx
|
||||||
TColStd_MapOfAsciiString.hxx
|
TColStd_MapOfAsciiString.hxx
|
||||||
TColStd_MapOfInteger.hxx
|
TColStd_MapOfInteger.hxx
|
||||||
|
@ -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 <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
|
|
||||||
#include <TColStd_PackedMapOfInteger.hxx>
|
|
||||||
|
|
||||||
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 <const TColStd_intMapNode *>(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 <const TColStd_intMapNode *>(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 <const TColStd_intMapNode *>(myNode);
|
|
||||||
myKey = TColStd_intMapNode_findNext (aNode, myIntMask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//=======================================================================
|
|
||||||
//function : Next
|
|
||||||
//purpose :
|
|
||||||
//=======================================================================
|
|
||||||
|
|
||||||
void TColStd_MapIteratorOfPackedMapOfInteger::Next ()
|
|
||||||
{
|
|
||||||
while (myNode) {
|
|
||||||
const TColStd_intMapNode * aNode =
|
|
||||||
reinterpret_cast <const TColStd_intMapNode *>(myNode);
|
|
||||||
myKey = TColStd_intMapNode_findNext (aNode, myIntMask);
|
|
||||||
if (myIntMask != ~0u)
|
|
||||||
break;
|
|
||||||
TCollection_BasicMapIterator::Next();
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,49 +16,9 @@
|
|||||||
#ifndef TColStd_MapIteratorOfPackedMapOfInteger_HeaderFile
|
#ifndef TColStd_MapIteratorOfPackedMapOfInteger_HeaderFile
|
||||||
#define TColStd_MapIteratorOfPackedMapOfInteger_HeaderFile
|
#define TColStd_MapIteratorOfPackedMapOfInteger_HeaderFile
|
||||||
|
|
||||||
#include <TCollection_BasicMapIterator.hxx>
|
#include <TColStd_PackedMapOfInteger.hxx>
|
||||||
#include <Standard_NoSuchObject.hxx>
|
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
|
//! Iterator of class TColStd_PackedMapOfInteger.
|
||||||
|
typedef TColStd_PackedMapOfInteger::Iterator TColStd_MapIteratorOfPackedMapOfInteger;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
#include <TColStd_PackedMapOfInteger.hxx>
|
#include <TColStd_PackedMapOfInteger.hxx>
|
||||||
#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
|
|
||||||
#include <TCollection_MapNode.hxx>
|
#include <TCollection_MapNode.hxx>
|
||||||
#include <Standard_Type.hxx>
|
#include <Standard_Type.hxx>
|
||||||
|
|
||||||
@ -23,16 +23,8 @@
|
|||||||
// 27 upper bits
|
// 27 upper bits
|
||||||
#define MASK_HIGH (~MASK_LOW)
|
#define MASK_HIGH (~MASK_LOW)
|
||||||
|
|
||||||
/**
|
//! Class implementing a block of 32 consecutive integer values as a node of a Map collection.
|
||||||
* Class implementing a block of 32 consecutive integer values as a node of
|
class TColStd_PackedMapOfInteger::TColStd_intMapNode : public TCollection_MapNode
|
||||||
* 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
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline TColStd_intMapNode (TCollection_MapNode * ptr = 0L)
|
inline TColStd_intMapNode (TCollection_MapNode * ptr = 0L)
|
||||||
@ -103,18 +95,6 @@ public:
|
|||||||
return ((myMask >> 5) == (unsigned)theOther);
|
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:
|
private:
|
||||||
unsigned int myMask;
|
unsigned int myMask;
|
||||||
unsigned int myData;
|
unsigned int myData;
|
||||||
@ -126,7 +106,7 @@ private:
|
|||||||
//purpose :
|
//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);
|
Standard_Boolean aResult (Standard_False);
|
||||||
const Standard_Integer aValInt = (1 << (theValue & MASK_LOW));
|
const Standard_Integer aValInt = (1 << (theValue & MASK_LOW));
|
||||||
@ -143,7 +123,7 @@ Standard_Boolean TColStd_intMapNode::AddValue (const Standard_Integer theValue)
|
|||||||
//purpose :
|
//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);
|
Standard_Boolean aResult (Standard_False);
|
||||||
const Standard_Integer aValInt = (1 << (theValue & MASK_LOW));
|
const Standard_Integer aValInt = (1 << (theValue & MASK_LOW));
|
||||||
@ -177,14 +157,12 @@ inline size_t TColStd_Population (unsigned int& theMask,
|
|||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : TColStd_intMapNode_findNext
|
//function : TColStd_intMapNode_findNext
|
||||||
//purpose : Find the smallest non-zero bit under the given mask. Outputs
|
//purpose :
|
||||||
// the new mask that does not contain the detected bit.
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
Standard_Integer TColStd_PackedMapOfInteger::TColStd_intMapNode_findNext (const TColStd_intMapNode* theNode,
|
||||||
Standard_Integer TColStd_intMapNode_findNext (const TColStd_intMapNode* theNode,
|
unsigned int& theMask)
|
||||||
unsigned int& theMask)
|
|
||||||
{
|
{
|
||||||
unsigned int val = theNode->myData & theMask;
|
unsigned int val = theNode->Data() & theMask;
|
||||||
int nZeros (0);
|
int nZeros (0);
|
||||||
if (val == 0)
|
if (val == 0)
|
||||||
theMask = ~0U; // void, nothing to do
|
theMask = ~0U; // void, nothing to do
|
||||||
@ -221,14 +199,12 @@ Standard_Integer TColStd_intMapNode_findNext (const TColStd_intMapNode* theNode,
|
|||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : TColStd_intMapNode_findPrev
|
//function : TColStd_intMapNode_findPrev
|
||||||
//purpose : Find the highest non-zero bit under the given mask. Outputs
|
//purpose :
|
||||||
// the new mask that does not contain the detected bit.
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
Standard_Integer TColStd_PackedMapOfInteger::TColStd_intMapNode_findPrev (const TColStd_intMapNode* theNode,
|
||||||
Standard_Integer TColStd_intMapNode_findPrev (const TColStd_intMapNode* theNode,
|
unsigned int& theMask)
|
||||||
unsigned int& theMask)
|
|
||||||
{
|
{
|
||||||
unsigned int val = theNode->myData & theMask;
|
unsigned int val = theNode->Data() & theMask;
|
||||||
int nZeros (0);
|
int nZeros (0);
|
||||||
if (val == 0)
|
if (val == 0)
|
||||||
theMask = ~0U; // void, nothing to do
|
theMask = ~0U; // void, nothing to do
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
#define TColStd_PackedMapOfInteger_HeaderFile
|
#define TColStd_PackedMapOfInteger_HeaderFile
|
||||||
|
|
||||||
#include <Standard_DefineAlloc.hxx>
|
#include <Standard_DefineAlloc.hxx>
|
||||||
|
#include <Standard_NoSuchObject.hxx>
|
||||||
#include <TCollection_BasicMap.hxx>
|
#include <TCollection_BasicMap.hxx>
|
||||||
|
#include <TCollection_BasicMapIterator.hxx>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimized Map of integer values. Each block of 32 integers is stored in 8 bytes in memory.
|
* 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
|
// operators new and delete must be defined explicitly
|
||||||
// since inherited ones are not accessible
|
// since inherited ones are not accessible
|
||||||
DEFINE_STANDARD_ALLOC
|
DEFINE_STANDARD_ALLOC
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// ---------- PUBLIC METHODS ----------
|
|
||||||
|
//! 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<const TColStd_intMapNode*>(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<const TColStd_intMapNode*>(myNode), myIntMask) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Restart the iteration
|
||||||
|
void Reset()
|
||||||
|
{
|
||||||
|
TCollection_BasicMapIterator::Reset();
|
||||||
|
myIntMask = ~0U;
|
||||||
|
myKey = myNode != NULL ? TColStd_intMapNode_findNext (reinterpret_cast<const TColStd_intMapNode*>(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<const TColStd_intMapNode*>(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
|
/// Constructor
|
||||||
inline TColStd_PackedMapOfInteger (const Standard_Integer NbBuckets = 1)
|
inline TColStd_PackedMapOfInteger (const Standard_Integer NbBuckets = 1)
|
||||||
@ -214,13 +275,28 @@ public:
|
|||||||
inline Standard_Integer InternalExtent () const
|
inline Standard_Integer InternalExtent () const
|
||||||
{ return TCollection_BasicMap::Extent(); }
|
{ return TCollection_BasicMap::Extent(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
private:
|
//! Class implementing a block of 32 consecutive integer values as a node of a Map collection.
|
||||||
// ---------- PRIVATE FIELDS ----------
|
//! 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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user