File indexing completed on 2026-09-28 09:19:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BRepGraph_ItemId_HeaderFile
0015 #define _BRepGraph_ItemId_HeaderFile
0016
0017 #include <BRepGraph_NodeId.hxx>
0018 #include <BRepGraph_RefId.hxx>
0019 #include <Standard_Assert.hxx>
0020 #include <Standard_HashUtils.hxx>
0021 #include <Standard_TypeDef.hxx>
0022
0023 #include <cstdint>
0024 #include <functional>
0025 #include <limits>
0026
0027
0028
0029 class BRepGraph_ItemId
0030 {
0031 public:
0032
0033 enum class Domain : uint8_t
0034 {
0035 None,
0036 Node,
0037 Reference
0038 };
0039
0040
0041 BRepGraph_ItemId() = default;
0042
0043
0044 BRepGraph_ItemId(const BRepGraph_NodeId theNode)
0045 {
0046 if (theNode.IsValid())
0047 {
0048 myDomain = Domain::Node;
0049 myIndex = theNode.Index;
0050 myKind = static_cast<uint8_t>(theNode.NodeKind);
0051 }
0052 }
0053
0054
0055 BRepGraph_ItemId(const BRepGraph_RefId theRef)
0056 {
0057 if (theRef.IsValid())
0058 {
0059 myDomain = Domain::Reference;
0060 myIndex = theRef.Index;
0061 myKind = static_cast<uint8_t>(theRef.RefKind);
0062 }
0063 }
0064
0065
0066 [[nodiscard]] bool IsValid() const noexcept
0067 {
0068 if (myIndex == THE_INVALID_INDEX)
0069 {
0070 return false;
0071 }
0072
0073 switch (myDomain)
0074 {
0075 case Domain::Node:
0076 return BRepGraph_NodeId::IsValidKind(static_cast<BRepGraph_NodeId::Kind>(myKind));
0077 case Domain::Reference:
0078 return BRepGraph_RefId::IsValidKind(static_cast<BRepGraph_RefId::Kind>(myKind));
0079 case Domain::None:
0080 return false;
0081 }
0082 return false;
0083 }
0084
0085
0086 [[nodiscard]] Domain ItemDomain() const noexcept { return myDomain; }
0087
0088
0089 [[nodiscard]] bool IsNode() const noexcept { return myDomain == Domain::Node; }
0090
0091
0092 [[nodiscard]] bool IsReference() const noexcept { return myDomain == Domain::Reference; }
0093
0094
0095 [[nodiscard]] BRepGraph_NodeId NodeId() const noexcept
0096 {
0097 return IsNode() && BRepGraph_NodeId::IsValidKind(static_cast<BRepGraph_NodeId::Kind>(myKind))
0098 ? BRepGraph_NodeId(static_cast<BRepGraph_NodeId::Kind>(myKind), myIndex)
0099 : BRepGraph_NodeId();
0100 }
0101
0102
0103 [[nodiscard]] BRepGraph_RefId RefId() const noexcept
0104 {
0105 return IsReference() && BRepGraph_RefId::IsValidKind(static_cast<BRepGraph_RefId::Kind>(myKind))
0106 ? BRepGraph_RefId(static_cast<BRepGraph_RefId::Kind>(myKind), myIndex)
0107 : BRepGraph_RefId();
0108 }
0109
0110
0111 [[nodiscard]] BRepGraph_NodeId::Kind NodeKind() const noexcept
0112 {
0113 Standard_ASSERT_RETURN(
0114 IsNode() && BRepGraph_NodeId::IsValidKind(static_cast<BRepGraph_NodeId::Kind>(myKind)),
0115 "BRepGraph_ItemId::NodeKind(): item is not a valid node",
0116 BRepGraph_NodeId::Kind::Solid);
0117 return static_cast<BRepGraph_NodeId::Kind>(myKind);
0118 }
0119
0120
0121 [[nodiscard]] BRepGraph_RefId::Kind RefKind() const noexcept
0122 {
0123 Standard_ASSERT_RETURN(
0124 IsReference() && BRepGraph_RefId::IsValidKind(static_cast<BRepGraph_RefId::Kind>(myKind)),
0125 "BRepGraph_ItemId::RefKind(): item is not a valid reference",
0126 BRepGraph_RefId::Kind::Shell);
0127 return static_cast<BRepGraph_RefId::Kind>(myKind);
0128 }
0129
0130
0131 [[nodiscard]] uint8_t RawKind() const noexcept { return myKind; }
0132
0133
0134 [[nodiscard]] uint8_t Kind() const noexcept { return RawKind(); }
0135
0136
0137 [[nodiscard]] uint32_t Index() const noexcept { return myIndex; }
0138
0139 friend bool operator==(const BRepGraph_ItemId& theLeft, const BRepGraph_ItemId& theRight) noexcept
0140 {
0141 return theLeft.myDomain == theRight.myDomain && theLeft.myKind == theRight.myKind
0142 && theLeft.myIndex == theRight.myIndex;
0143 }
0144
0145 friend bool operator!=(const BRepGraph_ItemId& theLeft, const BRepGraph_ItemId& theRight) noexcept
0146 {
0147 return !(theLeft == theRight);
0148 }
0149
0150 private:
0151 static constexpr uint32_t THE_INVALID_INDEX = std::numeric_limits<uint32_t>::max();
0152
0153 Domain myDomain = Domain::None;
0154 uint32_t myIndex = THE_INVALID_INDEX;
0155 uint8_t myKind = 0;
0156 };
0157
0158
0159 template <>
0160 struct std::hash<BRepGraph_ItemId>
0161 {
0162 size_t operator()(const BRepGraph_ItemId& theId) const noexcept
0163 {
0164 size_t aCombination[3];
0165 aCombination[0] = opencascade::hash(static_cast<uint32_t>(theId.ItemDomain()));
0166 aCombination[1] = opencascade::hash(static_cast<uint32_t>(theId.RawKind()));
0167 aCombination[2] = opencascade::hash(theId.Index());
0168 return opencascade::hashBytes(aCombination, sizeof(aCombination));
0169 }
0170 };
0171
0172 #endif