0030550: Coding - Integer overflow in Standard_CString HashCodes
[occt.git] / src / BOPDS / BOPDS_Pair.hxx
CommitLineData
25dfc507 1// Created by: Eugeny MALTCHIKOV
2// Copyright (c) 2017 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#ifndef _BOPDS_Pair_HeaderFile
16#define _BOPDS_Pair_HeaderFile
17
18#include <Standard.hxx>
19#include <Standard_DefineAlloc.hxx>
20#include <Standard_Handle.hxx>
21
22//! The class is to provide the pair of indices of interfering shapes.
23
24class BOPDS_Pair {
25 public:
26
27 DEFINE_STANDARD_ALLOC
28
29 BOPDS_Pair() : myIndex1(-1), myIndex2(-1) {}
30 //
31 BOPDS_Pair(const Standard_Integer theIndex1,
32 const Standard_Integer theIndex2) : myIndex1(theIndex1), myIndex2(theIndex2) {}
33
34 ~BOPDS_Pair(){}
35 //
36 //! Sets the indices
37 void SetIndices(const Standard_Integer theIndex1,
38 const Standard_Integer theIndex2)
39 {
40 myIndex1 = theIndex1;
41 myIndex2 = theIndex2;
42 }
43 //
44 //! Gets the indices
45 void Indices(Standard_Integer& theIndex1,
46 Standard_Integer& theIndex2) const
47 {
48 theIndex1 = myIndex1;
49 theIndex2 = myIndex2;
50 }
51 //
52 //! Operator less
53 Standard_Boolean operator < (const BOPDS_Pair& theOther) const
54 {
55 return ((myIndex1 != theOther.myIndex1) ?
56 (myIndex1 < theOther.myIndex1) : (myIndex2 < theOther.myIndex2));
57 }
58 //
59 //! Returns true if the Pair is equal to <the theOther>
60 Standard_Boolean IsEqual (const BOPDS_Pair& theOther) const
61 {
62 return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2) ||
63 (myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1);
64 }
2b2be3fb 65
66 //! Computes a hash code for this pair, in the range [1, theUpperBound]
67 //! @param theUpperBound the upper bound of the range a computing hash code must be within
68 //! @return a computed hash code, in the range [1, theUpperBound]
69 Standard_Integer HashCode (const Standard_Integer theUpperBound) const
25dfc507 70 {
2b2be3fb 71 return ::HashCode(myIndex1 + myIndex2, theUpperBound);
25dfc507 72 }
73
74 protected:
75 Standard_Integer myIndex1;
76 Standard_Integer myIndex2;
77};
78
79#endif // _BOPDS_Pair