1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-31 11:15:31 +03:00
occt/src/BOPDS/BOPDS_PassKey.lxx
abv d5f74e42d6 0024624: Lost word in license statement in source files
License statement text corrected; compiler warnings caused by Bison 2.41 disabled for MSVC; a few other compiler warnings on 54-bit Windows eliminated by appropriate type cast
Wrong license statements corrected in several files.
Copyright and license statements added in XSD and GLSL files.
Copyright year updated in some files.
Obsolete documentation files removed from DrawResources.
2014-02-20 16:15:17 +04:00

347 lines
9.2 KiB
Plaintext

// Created by: Peter KURNEV
// Copyright (c) 2010-2014 OPEN CASCADE SAS
// Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
// Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
// EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// 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.
static
inline Standard_Integer NormalizedId(const Standard_Integer aId,
const Standard_Integer aDiv);
static
inline void SortShell(const Standard_Integer n,
Standard_Integer* a);
//=======================================================================
//function :
//purpose :
//=======================================================================
inline BOPDS_PassKey::BOPDS_PassKey()
{
myAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
myPtr=NULL;
Clear();
}
//=======================================================================
//function :
//purpose :
//=======================================================================
inline BOPDS_PassKey::BOPDS_PassKey(const Handle(NCollection_BaseAllocator)& theAllocator)
{
myAllocator=theAllocator;
myPtr=NULL;
Clear();
}
//=======================================================================
//function :
//purpose :
//=======================================================================
inline BOPDS_PassKey::BOPDS_PassKey(const BOPDS_PassKey& aOther)
{
Standard_Integer i;
//
myPtr=NULL;
Clear();
//
myAllocator=aOther.myAllocator;
myNbIds=aOther.myNbIds;
mySum=aOther.mySum;
//
if (myNbIds) {
myPtr=Allocate(myNbIds);
for (i=0; i<myNbIds; ++i) {
myPtr[i]=aOther.myPtr[i];
}
}
}
//=======================================================================
//function :operator =
//purpose :
//=======================================================================
inline BOPDS_PassKey& BOPDS_PassKey::operator =(const BOPDS_PassKey& aOther)
{
Standard_Integer i;
//
Clear();
//
myAllocator=aOther.myAllocator;
myNbIds=aOther.myNbIds;
mySum=aOther.mySum;
//
if (myNbIds) {
myPtr=Allocate(myNbIds);
for (i=0; i<myNbIds; ++i) {
myPtr[i]=aOther.myPtr[i];
}
}
//
return *this;
}
//=======================================================================
//function :~
//purpose :
//=======================================================================
inline BOPDS_PassKey::~BOPDS_PassKey()
{
Clear();
}
//=======================================================================
//function :Allocate
//purpose :
//=======================================================================
inline BOPCol_PInteger BOPDS_PassKey::Allocate(const Standard_Integer theSize)
{
BOPCol_PInteger pPtr;
//
pPtr=(BOPCol_PInteger)myAllocator->Allocate(theSize*sizeof(Standard_Integer));
return pPtr;
}
//=======================================================================
//function :Clear
//purpose :
//=======================================================================
inline void BOPDS_PassKey::Clear()
{
myNbIds=0;
mySum=0;
if (myPtr) {
myAllocator->Free(myPtr);
myPtr=NULL;
}
}
//=======================================================================
//function :SetIds
//purpose :
//=======================================================================
inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1)
{
Clear();
myNbIds=1;
myPtr=Allocate(myNbIds);
myPtr[0]=aId1;
mySum=NormalizedId(aId1, myNbIds);
}
//=======================================================================
//function :SetIds
//purpose :
//=======================================================================
inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1,
const Standard_Integer aId2)
{
Clear();
//
myNbIds=2;
myPtr=Allocate(myNbIds);
//
if (aId1<aId2) {
myPtr[0]=aId1;
myPtr[1]=aId2;
}
else {
myPtr[0]=aId2;
myPtr[1]=aId1;
}
//
mySum=NormalizedId(aId1, myNbIds);
mySum=mySum+NormalizedId(aId2, myNbIds);
}
//=======================================================================
//function :SetIds
//purpose :
//=======================================================================
inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1,
const Standard_Integer aId2,
const Standard_Integer aId3)
{
Clear();
//
myNbIds=3;
myPtr=Allocate(myNbIds);
//
myPtr[0]=aId1;
myPtr[1]=aId2;
myPtr[2]=aId3;
//
SortShell(myNbIds, myPtr);
//
mySum=NormalizedId(aId1, myNbIds);
mySum=mySum+NormalizedId(aId2, myNbIds);
mySum=mySum+NormalizedId(aId3, myNbIds);
}
//=======================================================================
//function :SetIds
//purpose :
//=======================================================================
inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1,
const Standard_Integer aId2,
const Standard_Integer aId3,
const Standard_Integer aId4)
{
Clear();
//
myNbIds=4;
myPtr=Allocate(myNbIds);
//
myPtr[0]=aId1;
myPtr[1]=aId2;
myPtr[2]=aId3;
myPtr[3]=aId4;
//
SortShell(myNbIds, myPtr);
//
mySum=NormalizedId(aId1, myNbIds);
mySum=mySum+NormalizedId(aId2, myNbIds);
mySum=mySum+NormalizedId(aId3, myNbIds);
mySum=mySum+NormalizedId(aId4, myNbIds);
}
//=======================================================================
//function :SetIds
//purpose :
//=======================================================================
inline void BOPDS_PassKey::SetIds(const BOPCol_ListOfInteger& aLI)
{
Standard_Integer i, aId, aSum;
BOPCol_ListIteratorOfListOfInteger aIt;
//
Clear();
//
myNbIds=aLI.Extent();
myPtr=Allocate(myNbIds);
//
aSum=0;
aIt.Initialize(aLI);
for (i=0; aIt.More(); aIt.Next(), ++i) {
aId=aIt.Value();
myPtr[i]=aId;
aSum+=NormalizedId(aId, myNbIds);
}
mySum=aSum;
//
SortShell(myNbIds, myPtr);
}
//=======================================================================
//function :NbIds
//purpose :
//=======================================================================
inline Standard_Integer BOPDS_PassKey::NbIds()const
{
return myNbIds;
}
//=======================================================================
//function :Id
//purpose :
//=======================================================================
inline Standard_Integer BOPDS_PassKey::Id(const Standard_Integer aIndex) const
{
if (aIndex<0 || aIndex>myNbIds-1) {
return -1;
}
return myPtr[aIndex];
}
//=======================================================================
//function :Ids
//purpose :
//=======================================================================
inline void BOPDS_PassKey::Ids(Standard_Integer& aId1,
Standard_Integer& aId2) const
{
aId1=0;
aId2=0;
if (myNbIds>1) {
aId1=myPtr[0];
aId2=myPtr[1];
}
}
//=======================================================================
//function :IsEqual
//purpose :
//=======================================================================
inline Standard_Boolean BOPDS_PassKey::IsEqual(const BOPDS_PassKey& aOther) const
{
Standard_Boolean bRet;
Standard_Integer i;
//
bRet=Standard_False;
//
if (myNbIds!=aOther.myNbIds) {
return bRet;
}
for (i=0; i<myNbIds; ++i) {
if (myPtr[i]!=aOther.myPtr[i]) {
return bRet;
}
}
return !bRet;
}
//=======================================================================
//function : HashCode
//purpose :
//=======================================================================
inline Standard_Integer BOPDS_PassKey::HashCode(const Standard_Integer aUpper) const
{
return ::HashCode(mySum, aUpper);
}
//=======================================================================
// function: NormalizedId
// purpose :
//=======================================================================
inline Standard_Integer NormalizedId(const Standard_Integer aId,
const Standard_Integer aDiv)
{
Standard_Integer aMax, aTresh, aIdRet;
//
aIdRet=aId;
aMax=::IntegerLast();
aTresh=aMax/aDiv;
if (aId>aTresh) {
aIdRet=aId%aTresh;
}
return aIdRet;
}
//=======================================================================
// function: SortShell
// purpose :
//=======================================================================
inline void SortShell(const Standard_Integer n,
Standard_Integer* a)
{
Standard_Integer nd, i, j, l, d=1;
Standard_Integer x;
//
while(d<=n) {
d*=2;
}
//
while (d) {
d=(d-1)/2;
//
nd=n-d;
for (i=0; i<nd; ++i) {
j=i;
m30:;
l=j+d;
if (a[l] < a[j]) {
x=a[j];
a[j]=a[l];
a[l]=x;
j-=d;
if (j > -1) {
goto m30;
}
}//if (a[l] < a[j]){
}//for (i=0; i<nd; ++i)
}//while (1)
}