Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:04

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  public:
0026 
0027   DEFINE_STANDARD_ALLOC
0028 
0029   BOPDS_Pair() : myIndex1(-1), myIndex2(-1) {}
0030   //
0031   BOPDS_Pair(const Standard_Integer theIndex1,
0032              const Standard_Integer theIndex2) : myIndex1(theIndex1), myIndex2(theIndex2) {}
0033   
0034   ~BOPDS_Pair(){}
0035   //
0036   //! Sets the indices
0037   void SetIndices(const Standard_Integer theIndex1,
0038                   const Standard_Integer theIndex2)
0039   {
0040     myIndex1 = theIndex1;
0041     myIndex2 = theIndex2;
0042   }
0043   //
0044   //! Gets the indices
0045   void Indices(Standard_Integer& theIndex1,
0046                Standard_Integer& theIndex2) const
0047   {
0048     theIndex1 = myIndex1;
0049     theIndex2 = myIndex2;
0050   }
0051   //
0052   //! Operator less
0053   Standard_Boolean operator < (const  BOPDS_Pair& theOther) const
0054   {
0055     return ((myIndex1 != theOther.myIndex1) ?
0056             (myIndex1 < theOther.myIndex1) : (myIndex2 < theOther.myIndex2));
0057   }
0058   //
0059   //! Returns true if the Pair is equal to <the theOther>
0060   Standard_Boolean IsEqual (const BOPDS_Pair& theOther) const
0061   {
0062     return (myIndex1 == theOther.myIndex1 && myIndex2 == theOther.myIndex2) ||
0063            (myIndex1 == theOther.myIndex2 && myIndex2 == theOther.myIndex1);
0064   }
0065 
0066   bool operator==(const BOPDS_Pair& theOther) const
0067   {
0068     return IsEqual(theOther);
0069   }
0070 
0071  protected:
0072   Standard_Integer myIndex1;
0073   Standard_Integer myIndex2;
0074 };
0075 
0076 namespace std
0077 {
0078   template <>
0079   struct hash<BOPDS_Pair>
0080   {
0081     size_t operator()(const BOPDS_Pair& thePair) const noexcept
0082     {
0083       // Combine two int values into a single hash value.
0084       int aCombination[2];
0085       thePair.Indices(aCombination[0], aCombination[1]);
0086       if (aCombination[0] > aCombination[1])
0087       {
0088         std::swap(aCombination[0], aCombination[1]);
0089       }
0090       return opencascade::hashBytes(aCombination, sizeof(aCombination));
0091     }
0092   };
0093 }
0094 
0095 #endif // _BOPDS_Pair