File indexing completed on 2026-09-28 09:19:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
0027
0028
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
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