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 _BRepGraphInc_RepId_HeaderFile
0015 #define _BRepGraphInc_RepId_HeaderFile
0016
0017 #include <Standard_Assert.hxx>
0018 #include <Standard_HashUtils.hxx>
0019
0020 #include <cstdint>
0021 #include <functional>
0022 #include <limits>
0023
0024 class BRepGraph;
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 struct BRepGraph_RepId
0035 {
0036
0037 enum class Kind : int
0038 {
0039 EdgeCurve3D = 0,
0040 EdgePolygon3D = 1,
0041 CoEdgeCurve2D = 2,
0042 CoEdgePolygon2D = 3,
0043 CoEdgePolygonOnTri = 4,
0044 FaceSurface = 5,
0045 FaceTriangulation = 6
0046 };
0047
0048
0049 static bool IsValidKind(const Kind theKind)
0050 {
0051 switch (theKind)
0052 {
0053 case Kind::EdgeCurve3D:
0054 case Kind::EdgePolygon3D:
0055 case Kind::CoEdgeCurve2D:
0056 case Kind::CoEdgePolygon2D:
0057 case Kind::CoEdgePolygonOnTri:
0058 case Kind::FaceSurface:
0059 case Kind::FaceTriangulation:
0060 return true;
0061 }
0062 return false;
0063 }
0064
0065
0066 template <Kind TheKind>
0067 struct Typed
0068 {
0069 static constexpr uint32_t THE_START_INDEX = 0u;
0070 static constexpr uint32_t THE_INVALID_INDEX = std::numeric_limits<uint32_t>::max();
0071
0072 uint32_t Index;
0073
0074
0075 Typed()
0076 : Index(THE_INVALID_INDEX)
0077 {
0078 }
0079
0080
0081 explicit Typed(const uint32_t theIdx)
0082 : Index(theIdx)
0083 {
0084 }
0085
0086
0087 [[nodiscard]] static Typed Start() { return Typed(THE_START_INDEX); }
0088
0089
0090 [[nodiscard]] static Typed Invalid() { return Typed(); }
0091
0092
0093 [[nodiscard]] bool IsValid() const { return Index != THE_INVALID_INDEX; }
0094
0095
0096 [[nodiscard]] bool IsValid(const uint32_t theMaxCount) const
0097 {
0098 return IsValid() && Index < theMaxCount;
0099 }
0100
0101
0102 operator BRepGraph_RepId() const { return BRepGraph_RepId(TheKind, Index); }
0103
0104
0105 [[nodiscard]] bool IsRemoved(const BRepGraph& theGraph) const
0106 {
0107 return BRepGraph_RepId(*this).IsRemoved(theGraph);
0108 }
0109
0110
0111 Typed& operator++()
0112 {
0113 Standard_ASSERT_VOID(Index != THE_INVALID_INDEX, "pre-increment on invalid use id");
0114 ++Index;
0115 return *this;
0116 }
0117
0118
0119 Typed operator++(int)
0120 {
0121 Standard_ASSERT_VOID(Index != THE_INVALID_INDEX, "post-increment on invalid use id");
0122 Typed aPrev = *this;
0123 ++Index;
0124 return aPrev;
0125 }
0126
0127 bool operator==(const Typed& theOther) const { return Index == theOther.Index; }
0128
0129 bool operator!=(const Typed& theOther) const { return Index != theOther.Index; }
0130
0131 bool operator<(const Typed& theOther) const { return Index < theOther.Index; }
0132
0133 bool operator<=(const Typed& theOther) const { return Index <= theOther.Index; }
0134
0135 bool operator>(const Typed& theOther) const { return Index > theOther.Index; }
0136
0137 bool operator>=(const Typed& theOther) const { return Index >= theOther.Index; }
0138 };
0139
0140 static constexpr uint32_t THE_START_INDEX = 0u;
0141 static constexpr uint32_t THE_INVALID_INDEX = std::numeric_limits<uint32_t>::max();
0142
0143 Kind RepKind;
0144 uint32_t Index;
0145
0146
0147 BRepGraph_RepId()
0148 : RepKind(Kind::EdgeCurve3D),
0149 Index(THE_INVALID_INDEX)
0150 {
0151 }
0152
0153 BRepGraph_RepId(const Kind theKind, const uint32_t theIdx)
0154 : RepKind(theKind),
0155 Index(theIdx)
0156 {
0157 }
0158
0159
0160 [[nodiscard]] bool IsValid() const { return IsValidKind(RepKind) && Index != THE_INVALID_INDEX; }
0161
0162
0163 [[nodiscard]] bool IsValid(const uint32_t theMaxCount) const
0164 {
0165 return IsValid() && Index < theMaxCount;
0166 }
0167
0168 bool operator==(const BRepGraph_RepId& theOther) const
0169 {
0170 return RepKind == theOther.RepKind && Index == theOther.Index;
0171 }
0172
0173 bool operator!=(const BRepGraph_RepId& theOther) const { return !(*this == theOther); }
0174
0175 bool operator<(const BRepGraph_RepId& theOther) const
0176 {
0177 if (RepKind != theOther.RepKind)
0178 {
0179 return static_cast<int>(RepKind) < static_cast<int>(theOther.RepKind);
0180 }
0181 return Index < theOther.Index;
0182 }
0183
0184
0185 [[nodiscard]] Standard_EXPORT bool IsRemoved(const BRepGraph& theGraph) const;
0186 };
0187
0188
0189 using BRepGraph_EdgeCurve3DRepId = BRepGraph_RepId::Typed<BRepGraph_RepId::Kind::EdgeCurve3D>;
0190 using BRepGraph_EdgePolygon3DRepId = BRepGraph_RepId::Typed<BRepGraph_RepId::Kind::EdgePolygon3D>;
0191 using BRepGraph_CoEdgeCurve2DRepId = BRepGraph_RepId::Typed<BRepGraph_RepId::Kind::CoEdgeCurve2D>;
0192 using BRepGraph_CoEdgePolygon2DRepId =
0193 BRepGraph_RepId::Typed<BRepGraph_RepId::Kind::CoEdgePolygon2D>;
0194 using BRepGraph_CoEdgePolygonOnTriRepId =
0195 BRepGraph_RepId::Typed<BRepGraph_RepId::Kind::CoEdgePolygonOnTri>;
0196 using BRepGraph_FaceSurfaceRepId = BRepGraph_RepId::Typed<BRepGraph_RepId::Kind::FaceSurface>;
0197 using BRepGraph_FaceTriangulationRepId =
0198 BRepGraph_RepId::Typed<BRepGraph_RepId::Kind::FaceTriangulation>;
0199
0200 template <>
0201 struct std::hash<BRepGraph_RepId>
0202 {
0203 size_t operator()(const BRepGraph_RepId& theId) const noexcept
0204 {
0205 size_t aCombination[2];
0206 aCombination[0] = opencascade::hash(static_cast<int>(theId.RepKind));
0207 aCombination[1] = opencascade::hash(theId.Index);
0208 return opencascade::hashBytes(aCombination, sizeof(aCombination));
0209 }
0210 };
0211
0212 template <BRepGraph_RepId::Kind TheKind>
0213 struct std::hash<BRepGraph_RepId::Typed<TheKind>>
0214 {
0215 size_t operator()(const BRepGraph_RepId::Typed<TheKind>& theId) const noexcept
0216 {
0217 return std::hash<uint32_t>{}(theId.Index);
0218 }
0219 };
0220
0221 #endif