Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:19:36

0001 // Copyright (c) 2026 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepGraph_RefUID_HeaderFile
0015 #define _BRepGraph_RefUID_HeaderFile
0016 
0017 #include <BRepGraph_RefId.hxx>
0018 #include <Standard_Assert.hxx>
0019 #include <Standard_HashUtils.hxx>
0020 
0021 #include <cstddef>
0022 #include <cstdint>
0023 #include <functional>
0024 #include <limits>
0025 
0026 //! Unique reference-entry identifier within a BRepGraph.
0027 //!
0028 //! Identity = (RefKind, Counter). Counter 0 is an invalid sentinel.
0029 struct BRepGraph_RefUID
0030 {
0031   BRepGraph_RefId::Kind Kind    = BRepGraph_RefId::Kind::Shell;
0032   uint32_t              Counter = 0;
0033 
0034   BRepGraph_RefUID() = default;
0035 
0036   BRepGraph_RefUID(const BRepGraph_RefId::Kind theKind, const uint32_t theCounter)
0037       : Kind(theKind),
0038         Counter(theCounter)
0039   {
0040   }
0041 
0042   static BRepGraph_RefUID Invalid() { return BRepGraph_RefUID(); }
0043 
0044   //! True if this UID has a valid kind and a non-zero counter.
0045   [[nodiscard]] bool IsValid() const { return Counter > 0 && BRepGraph_RefId::IsValidKind(Kind); }
0046 
0047   friend bool operator==(const BRepGraph_RefUID& theLeft, const BRepGraph_RefUID& theRight) noexcept
0048   {
0049     if (theLeft.Counter == 0 || theRight.Counter == 0)
0050     {
0051       return (theLeft.Counter == 0) == (theRight.Counter == 0);
0052     }
0053     return theLeft.Kind == theRight.Kind && theLeft.Counter == theRight.Counter;
0054   }
0055 
0056   friend bool operator!=(const BRepGraph_RefUID& theLeft, const BRepGraph_RefUID& theRight) noexcept
0057   {
0058     return !(theLeft == theRight);
0059   }
0060 
0061   friend bool operator<(const BRepGraph_RefUID& theLeft, const BRepGraph_RefUID& theRight) noexcept
0062   {
0063     if (theLeft.Kind != theRight.Kind)
0064     {
0065       return static_cast<int>(theLeft.Kind) < static_cast<int>(theRight.Kind);
0066     }
0067     return theLeft.Counter < theRight.Counter;
0068   }
0069 
0070   [[nodiscard]] size_t HashValue() const noexcept
0071   {
0072     if (Counter == 0)
0073     {
0074       return opencascade::hash(0);
0075     }
0076     size_t aCombination[2];
0077     aCombination[0] = opencascade::hash(static_cast<int>(Kind));
0078     aCombination[1] = opencascade::hash(Counter);
0079     return opencascade::hashBytes(aCombination, sizeof(aCombination));
0080   }
0081 };
0082 
0083 static_assert(sizeof(BRepGraph_RefUID) <= 8, "BRepGraph_RefUID must stay compact");
0084 
0085 template <>
0086 struct std::hash<BRepGraph_RefUID>
0087 {
0088   size_t operator()(const BRepGraph_RefUID& theUID) const noexcept { return theUID.HashValue(); }
0089 };
0090 
0091 #endif // _BRepGraph_RefUID_HeaderFile