1 // Created on: 2012-06-27
2 // Created by: Dmitry BOBYLEV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <TopTools_MutexForShapeProvider.hxx>
18 #include <Standard_Mutex.hxx>
19 #include <TopoDS_Iterator.hxx>
22 // macro to compare two types of shapes
23 #define SAMETYPE(x,y) ((x) == (y))
24 #define LESSCOMPLEX(x,y) ((x) > (y))
26 //=======================================================================
27 //function : TopTools_MutexForShapeProvider
29 //=======================================================================
30 TopTools_MutexForShapeProvider::TopTools_MutexForShapeProvider()
35 //=======================================================================
36 //function : ~TopTools_MutexForShapeProvider
38 //=======================================================================
39 TopTools_MutexForShapeProvider::~TopTools_MutexForShapeProvider()
44 //=======================================================================
45 //function : CreateMutexesForSubShapes
47 //=======================================================================
48 void TopTools_MutexForShapeProvider::CreateMutexesForSubShapes(const TopoDS_Shape& theShape,
49 const TopAbs_ShapeEnum theType)
51 if (LESSCOMPLEX(theShape.ShapeType(), theType))
54 for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next())
56 const TopoDS_Shape& aShape = anIt.Value();
57 if (LESSCOMPLEX(theType, aShape.ShapeType()))
59 CreateMutexesForSubShapes(aShape, theType);
61 else if (SAMETYPE(theType, aShape.ShapeType()))
63 CreateMutexForShape(aShape);
68 //=======================================================================
69 //function : CreateMutexForShape
71 //=======================================================================
72 void TopTools_MutexForShapeProvider::CreateMutexForShape(const TopoDS_Shape& theShape)
74 if (!myMap.IsBound(theShape.TShape()))
76 Standard_Mutex* aMutex = new Standard_Mutex();
77 myMap.Bind(theShape.TShape(), aMutex);
81 //=======================================================================
82 //function : CreateMutexForShape
84 //=======================================================================
85 Standard_Mutex* TopTools_MutexForShapeProvider::GetMutex(const TopoDS_Shape& theShape) const
87 if (myMap.IsBound(theShape.TShape()))
89 Standard_Mutex* aMutex = myMap.Find(theShape.TShape());
98 //=======================================================================
99 //function : RemoveAllMutexes
101 //=======================================================================
102 void TopTools_MutexForShapeProvider::RemoveAllMutexes()
104 for (NCollection_DataMap<TopoDS_Shape, Standard_Mutex *>::Iterator anIter;
105 anIter.More(); anIter.Next())
107 delete anIter.Value();