Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:19:44

0001 // Created by: Eugeny MALTCHIKOV
0002 // Copyright (c) 2017 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _BOPDS_Pair_HeaderFile
0016 #define _BOPDS_Pair_HeaderFile
0017 
0018 #include <Standard.hxx>
0019 #include <Standard_DefineAlloc.hxx>
0020 #include <Standard_HashUtils.hxx>
0021 
0022 //! The class is to provide the pair of indices of interfering shapes.
0023 
0024 class BOPDS_Pair
0025 {
0026 public:
0027   DEFINE_STANDARD_ALLOC
0028 
0029   BOPDS_Pair()
0030       : myIndex1(-1),
0031         myIndex2(-1)
0032   {
0033   }
0034 
0035   //
0036   BOPDS_Pair(const int theIndex1, const int theIndex2)
0037       : myIndex1(theIndex1),
0038         myIndex2(theIndex2)
0039   {
0040   }
0041 
0042   ~BOPDS_Pair() = default;
0043 
0044   //
0045   //! Sets the indices
0046   void SetIndices(const int theIndex1, const int theIndex2)
0047   {
0048     myIndex1 = theIndex1;
0049     myIndex2 = theIndex2;
0050   }
0051 
0052   //
0053   //! Gets the indices
0054   void Indices(int& theIndex1, int& theIndex2) const
0055   {
0056     theIndex1 = myIndex1;
0057     theIndex2 = myIndex2;
0058   }
0059 
0060   //
0061   //! Operator less
0062   bool operator<(const BOPDS_Pair& theOther) const
0063   {
0064     return ((myIndex1 != theOther.myIndex1) ? (myIndex1 < theOther.myIndex1)
0065                                             : (myIndex2 < theOther.myIndex2));
0066   }
0067 
0068   //
0069   //! Returns true if the Pair is equal to <the theOther>
0070   bool IsEqual(const BOPDS_Pair& theOther) const
0071   {
0072     return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2)
0073            || (myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1);
0074   }
0075 
0076   bool operator==(const BOPDS_Pair& theOther) const { return IsEqual(theOther); }
0077 
0078 protected:
0079   int myIndex1;
0080   int myIndex2;
0081 };
0082 
0083 namespace std
0084 {
0085 template <>
0086 struct hash<BOPDS_Pair>
0087 {
0088   size_t operator()(const BOPDS_Pair& thePair) const noexcept
0089   {
0090     // Combine two int values into a single hash value.
0091     int aCombination[2];
0092     thePair.Indices(aCombination[0], aCombination[1]);
0093     if (aCombination[0] > aCombination[1])
0094     {
0095       std::swap(aCombination[0], aCombination[1]);
0096     }
0097     return opencascade::hashBytes(aCombination, sizeof(aCombination));
0098   }
0099 };
0100 } // namespace std
0101 
0102 #endif // _BOPDS_Pair