Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / NMTDS / NMTDS_Pair.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:        NMTDS_Pair.cxx
24 // Author:      Peter KURNEV
25
26 #include <NMTDS_Pair.hxx>
27
28 #include <stdio.h>
29 #include <string.h>
30 #include <TColStd_ListIteratorOfListOfInteger.hxx>
31 #include <TColStd_ListOfInteger.hxx>
32
33 #ifdef WNT
34 #pragma warning( disable : 4101) 
35 #endif
36
37 static
38   Standard_Integer NormalizedId(const Standard_Integer aId,
39                                 const Standard_Integer aDiv);
40
41 //=======================================================================
42 //function :
43 //purpose  : 
44 //=======================================================================
45 NMTDS_Pair::NMTDS_Pair()
46 {
47   Clear(); 
48 }
49 //=======================================================================
50 //function :
51 //purpose  : 
52 //=======================================================================
53 NMTDS_Pair::NMTDS_Pair(const NMTDS_Pair& aOther)
54 {
55   myId1=aOther.myId1;
56   myId2=aOther.myId2;
57 }
58 //=======================================================================
59 //function :operator =
60 //purpose  : 
61 //=======================================================================
62   NMTDS_Pair& NMTDS_Pair::operator =(const NMTDS_Pair& aOther)
63 {
64   myId1=aOther.myId1;
65   myId2=aOther.myId2;
66   return *this;
67 }
68 //=======================================================================
69 //function :~
70 //purpose  : 
71 //=======================================================================
72   NMTDS_Pair::~NMTDS_Pair()
73 {
74 }
75 //=======================================================================
76 //function :Clear
77 //purpose  : 
78 //=======================================================================
79   void NMTDS_Pair::Clear()
80 {
81   myId1=0;
82   myId2=0;
83 }
84 //=======================================================================
85 //function :SetIds
86 //purpose  : 
87 //=======================================================================
88   void NMTDS_Pair::SetIds(const Standard_Integer aId1,
89                           const Standard_Integer aId2)
90 {
91   Clear();
92   myId1=aId1;
93   myId2=aId2;
94   if (aId1>aId2) {
95     myId1=aId2;
96     myId2=aId1;
97   }
98 }
99 //=======================================================================
100 //function :Ids
101 //purpose  : 
102 //=======================================================================
103   void NMTDS_Pair::Ids(Standard_Integer& aId1,
104                        Standard_Integer& aId2) const
105 {
106   aId1=myId1;
107   aId2=myId2;
108 }
109 //=======================================================================
110 //function :IsEqual
111 //purpose  : 
112 //=======================================================================
113   Standard_Boolean NMTDS_Pair::IsEqual(const NMTDS_Pair& aOther) const
114 {
115  
116   Standard_Boolean bRet;
117   //
118   bRet=(myId1==aOther.myId1 && myId2==aOther.myId2);//ZZ
119   return bRet;
120 }
121 //=======================================================================
122 //function : HashCode
123 //purpose  : 
124 //=======================================================================
125   Standard_Integer NMTDS_Pair::HashCode(const Standard_Integer aUpper) const
126 {
127   Standard_Integer aSum;
128   //
129   aSum=0;
130   aSum+=NormalizedId(myId1, 2);
131   aSum+=NormalizedId(myId2, 2);
132   return ::HashCode(aSum, aUpper);
133 }
134 //=======================================================================
135 // function: NormalizedId
136 // purpose : 
137 //=======================================================================
138 Standard_Integer NormalizedId(const Standard_Integer aId,
139                               const Standard_Integer aDiv)
140 {
141   Standard_Integer aMax, aTresh, aIdRet;
142   //
143   aIdRet=aId;
144   aMax=::IntegerLast();
145   aTresh=aMax/aDiv;
146   if (aId>aTresh) {
147     aIdRet=aId%aTresh;
148   }
149   return aIdRet;
150 }