0024516: Copyright information has been corrupted within some headers
[occt.git] / src / TopTools / TopTools_MutexForShapeProvider.cxx
1 // Created on: 2012-06-27
2 // Created by: Dmitry BOBYLEV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <TopTools_MutexForShapeProvider.hxx>
17
18 #include <Standard_Mutex.hxx>
19 #include <TopoDS_Iterator.hxx>
20
21
22 // macro to compare two types of shapes
23 #define SAMETYPE(x,y) ((x) == (y))
24 #define LESSCOMPLEX(x,y) ((x) > (y))
25
26 //=======================================================================
27 //function : TopTools_MutexForShapeProvider
28 //purpose  : 
29 //=======================================================================
30 TopTools_MutexForShapeProvider::TopTools_MutexForShapeProvider()
31 {
32 }
33
34
35 //=======================================================================
36 //function : ~TopTools_MutexForShapeProvider
37 //purpose  : 
38 //=======================================================================
39 TopTools_MutexForShapeProvider::~TopTools_MutexForShapeProvider()
40 {
41   RemoveAllMutexes();
42 }
43
44 //=======================================================================
45 //function : CreateMutexesForSubShapes
46 //purpose  : 
47 //=======================================================================
48 void TopTools_MutexForShapeProvider::CreateMutexesForSubShapes(const TopoDS_Shape& theShape,
49                                                                const TopAbs_ShapeEnum theType)
50 {
51   if (LESSCOMPLEX(theShape.ShapeType(), theType))
52     return;
53
54   for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next())
55   {
56     const TopoDS_Shape& aShape = anIt.Value();
57     if (LESSCOMPLEX(theType, aShape.ShapeType()))
58     {
59       CreateMutexesForSubShapes(aShape, theType);
60     }
61     else if (SAMETYPE(theType, aShape.ShapeType()))
62     {
63       CreateMutexForShape(aShape);
64     }
65   }
66 }
67
68 //=======================================================================
69 //function : CreateMutexForShape
70 //purpose  : 
71 //=======================================================================
72 void TopTools_MutexForShapeProvider::CreateMutexForShape(const TopoDS_Shape& theShape)
73 {
74   if (!myMap.IsBound(theShape.TShape()))
75   {
76     Standard_Mutex* aMutex = new Standard_Mutex();
77     myMap.Bind(theShape.TShape(), aMutex);
78   }
79 }
80
81 //=======================================================================
82 //function : CreateMutexForShape
83 //purpose  : 
84 //=======================================================================
85 Standard_Mutex* TopTools_MutexForShapeProvider::GetMutex(const TopoDS_Shape& theShape) const
86 {
87   if (myMap.IsBound(theShape.TShape()))
88   {
89     Standard_Mutex* aMutex = myMap.Find(theShape.TShape());
90     return aMutex;
91   }
92   else
93   {
94     return NULL;
95   }
96 }
97
98 //=======================================================================
99 //function : RemoveAllMutexes
100 //purpose  : 
101 //=======================================================================
102 void TopTools_MutexForShapeProvider::RemoveAllMutexes()
103 {
104   for (NCollection_DataMap<TopoDS_Shape, Standard_Mutex *>::Iterator anIter;
105          anIter.More(); anIter.Next())
106   {
107     delete anIter.Value();
108   }
109   myMap.Clear();
110 }