mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0022850: Not stable fix 22735
Class TopTools_MutexForShapeProvider has been created Class contain methods: TopTools_MutexForShapeProvider::CreateMutexesForSubShapes - Creates and associates mutexes with each sub-shape of type theType in theShape. TopTools_MutexForShapeProvider::CreateMutexForShape - Creates and associates mutex with theShape TopTools_MutexForShapeProvider::GetMutex - Returns pointer to mutex associated with theShape. In case when mutex not found returns NULL. Added method RemoveAllMutexes to TopTools_MutexForShapeProvider Assign operator in MutexProvider, constructor and operator and assign operator in Standard_Mutex now private Replaced TopExp_Explorer with TopoDS_Iterator to avoid cyclic dependence
This commit is contained in:
2
src/TopTools/FILES
Normal file
2
src/TopTools/FILES
Normal file
@@ -0,0 +1,2 @@
|
||||
TopTools_MutexForShapeProvider.hxx
|
||||
TopTools_MutexForShapeProvider.cxx
|
@@ -213,7 +213,9 @@ is
|
||||
|
||||
--
|
||||
-- Package methods
|
||||
--
|
||||
--
|
||||
|
||||
imported MutexForShapeProvider;
|
||||
|
||||
Dump(Sh : Shape from TopoDS; S : in out OStream);
|
||||
---Purpose: Dumps the topological structure of <Sh> on the
|
||||
|
112
src/TopTools/TopTools_MutexForShapeProvider.cxx
Normal file
112
src/TopTools/TopTools_MutexForShapeProvider.cxx
Normal file
@@ -0,0 +1,112 @@
|
||||
// Created on: 2012-06-27
|
||||
// Created by: Dmitry BOBYLEV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#include <TopTools_MutexForShapeProvider.hxx>
|
||||
|
||||
#include <TopoDS_Iterator.hxx>
|
||||
|
||||
// macro to compare two types of shapes
|
||||
#define SAMETYPE(x,y) ((x) == (y))
|
||||
#define LESSCOMPLEX(x,y) ((x) > (y))
|
||||
|
||||
//=======================================================================
|
||||
//function : TopTools_MutexForShapeProvider
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
TopTools_MutexForShapeProvider::TopTools_MutexForShapeProvider()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : ~TopTools_MutexForShapeProvider
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
TopTools_MutexForShapeProvider::~TopTools_MutexForShapeProvider()
|
||||
{
|
||||
RemoveAllMutexes();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateMutexesForSubShapes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void TopTools_MutexForShapeProvider::CreateMutexesForSubShapes(const TopoDS_Shape& theShape,
|
||||
const TopAbs_ShapeEnum theType)
|
||||
{
|
||||
if (LESSCOMPLEX(theShape.ShapeType(), theType))
|
||||
return;
|
||||
|
||||
for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next())
|
||||
{
|
||||
const TopoDS_Shape& aShape = anIt.Value();
|
||||
if (LESSCOMPLEX(theType, aShape.ShapeType()))
|
||||
{
|
||||
CreateMutexesForSubShapes(aShape, theType);
|
||||
}
|
||||
else if (SAMETYPE(theType, aShape.ShapeType()))
|
||||
{
|
||||
CreateMutexForShape(aShape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateMutexForShape
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void TopTools_MutexForShapeProvider::CreateMutexForShape(const TopoDS_Shape& theShape)
|
||||
{
|
||||
if (!myMap.IsBound(theShape))
|
||||
{
|
||||
Standard_Mutex* aMutex = new Standard_Mutex();
|
||||
myMap.Bind(theShape, aMutex);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateMutexForShape
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Mutex* TopTools_MutexForShapeProvider::GetMutex(const TopoDS_Shape& theShape) const
|
||||
{
|
||||
if (myMap.IsBound(theShape))
|
||||
{
|
||||
Standard_Mutex* aMutex = myMap.Find(theShape);
|
||||
return aMutex;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveAllMutexes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void TopTools_MutexForShapeProvider::RemoveAllMutexes()
|
||||
{
|
||||
for (NCollection_DataMap<TopoDS_Shape, Standard_Mutex *, TopTools_ShapeMapHasher>::Iterator anIter;
|
||||
anIter.More(); anIter.Next())
|
||||
{
|
||||
delete anIter.Value();
|
||||
}
|
||||
myMap.Clear();
|
||||
}
|
66
src/TopTools/TopTools_MutexForShapeProvider.hxx
Normal file
66
src/TopTools/TopTools_MutexForShapeProvider.hxx
Normal file
@@ -0,0 +1,66 @@
|
||||
// Created on: 2012-06-27
|
||||
// Created by: Dmitry BOBYLEV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
|
||||
#ifndef _TopTools_MutexForShapeProvider_HeaderFile
|
||||
#define _TopTools_MutexForShapeProvider_HeaderFile
|
||||
|
||||
#include <NCollection_DataMap.hxx>
|
||||
#include <Standard_Mutex.hxx>
|
||||
#include <TopAbs_ShapeEnum.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopTools_ShapeMapHasher.hxx>
|
||||
|
||||
|
||||
//! Class TopTools_MutexForShapeProvider
|
||||
//! This class is used to create and store mutexes associated with shapes.
|
||||
class TopTools_MutexForShapeProvider
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
Standard_EXPORT TopTools_MutexForShapeProvider();
|
||||
|
||||
//! Destructor
|
||||
Standard_EXPORT ~TopTools_MutexForShapeProvider();
|
||||
|
||||
//! Creates and associates mutexes with each sub-shape of type theType in theShape.
|
||||
Standard_EXPORT void CreateMutexesForSubShapes(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType);
|
||||
|
||||
//! Creates and associates mutex with theShape
|
||||
Standard_EXPORT void CreateMutexForShape(const TopoDS_Shape& theShape);
|
||||
|
||||
//! Returns pointer to mutex associated with theShape.
|
||||
//! In case when mutex not found returns NULL.
|
||||
Standard_EXPORT Standard_Mutex* GetMutex(const TopoDS_Shape& theShape) const;
|
||||
|
||||
//! Removes all mutexes
|
||||
Standard_EXPORT void RemoveAllMutexes();
|
||||
|
||||
private:
|
||||
//! This method should not be called (prohibited).
|
||||
TopTools_MutexForShapeProvider (const TopTools_MutexForShapeProvider &);
|
||||
//! This method should not be called (prohibited).
|
||||
TopTools_MutexForShapeProvider & operator = (const TopTools_MutexForShapeProvider &);
|
||||
|
||||
|
||||
NCollection_DataMap<TopoDS_Shape, Standard_Mutex *, TopTools_ShapeMapHasher> myMap;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user