File indexing completed on 2026-09-28 09:19:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BRepGraph_UID_HeaderFile
0015 #define _BRepGraph_UID_HeaderFile
0016
0017 #include <BRepGraph_NodeId.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
0030
0031
0032
0033 struct BRepGraph_UID
0034 {
0035 BRepGraph_NodeId::Kind Kind = BRepGraph_NodeId::Kind::Solid;
0036 uint32_t Counter = 0;
0037
0038
0039 BRepGraph_UID() = default;
0040
0041
0042
0043 BRepGraph_UID(const BRepGraph_NodeId::Kind theKind, const uint32_t theCounter)
0044 : Kind(theKind),
0045 Counter(theCounter)
0046 {
0047 }
0048
0049
0050 static BRepGraph_UID Invalid() { return BRepGraph_UID(); }
0051
0052
0053 [[nodiscard]] bool IsValid() const { return Counter > 0 && BRepGraph_NodeId::IsValidKind(Kind); }
0054
0055 [[nodiscard]] bool IsTopology() const
0056 {
0057 return IsValid() && BRepGraph_NodeId::IsTopologyKind(Kind);
0058 }
0059
0060 [[nodiscard]] bool IsAssembly() const
0061 {
0062 return IsValid() && BRepGraph_NodeId::IsAssemblyKind(Kind);
0063 }
0064
0065
0066 friend bool operator==(const BRepGraph_UID& theLeft, const BRepGraph_UID& theRight) noexcept
0067 {
0068 if (theLeft.Counter == 0 || theRight.Counter == 0)
0069 {
0070 return (theLeft.Counter == 0) == (theRight.Counter == 0);
0071 }
0072 return theLeft.Kind == theRight.Kind && theLeft.Counter == theRight.Counter;
0073 }
0074
0075 friend bool operator!=(const BRepGraph_UID& theLeft, const BRepGraph_UID& theRight) noexcept
0076 {
0077 return !(theLeft == theRight);
0078 }
0079
0080 friend bool operator<(const BRepGraph_UID& theLeft, const BRepGraph_UID& theRight) noexcept
0081 {
0082 if (theLeft.Kind != theRight.Kind)
0083 {
0084 return static_cast<int>(theLeft.Kind) < static_cast<int>(theRight.Kind);
0085 }
0086 return theLeft.Counter < theRight.Counter;
0087 }
0088
0089
0090 [[nodiscard]] size_t HashValue() const noexcept
0091 {
0092 if (Counter == 0)
0093 {
0094 return opencascade::hash(0);
0095 }
0096 size_t aCombination[2];
0097 aCombination[0] = opencascade::hash(static_cast<int>(Kind));
0098 aCombination[1] = opencascade::hash(Counter);
0099 return opencascade::hashBytes(aCombination, sizeof(aCombination));
0100 }
0101 };
0102
0103 static_assert(sizeof(BRepGraph_UID) <= 8, "BRepGraph_UID must stay compact");
0104
0105
0106 template <>
0107 struct std::hash<BRepGraph_UID>
0108 {
0109 size_t operator()(const BRepGraph_UID& theUID) const noexcept { return theUID.HashValue(); }
0110 };
0111
0112 #endif