Back to home page

EIC code displayed by LXR

 
 

    


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

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_UIDsView_HeaderFile
0015 #define _BRepGraph_UIDsView_HeaderFile
0016 
0017 #include <BRepGraph.hxx>
0018 #include <BRepGraph_VersionStamp.hxx>
0019 
0020 class Standard_GUID;
0021 
0022 //! @brief Read-only view for persistent node and reference identifiers.
0023 //!
0024 //! UIDs are (Kind, Counter) pairs that persist across graph mutations
0025 //! (Compact, node removal). Counters are monotonic and independent of vector
0026 //! indices. Clear() starts a new graph generation and refreshes the graph
0027 //! GUID, enabling stale-reference detection when a graph is rebuilt.
0028 //! Provides bidirectional NodeId/UID and RefId/RefUID resolution.
0029 //!
0030 //! Version stamps are exposed here for graph-owned cache and layer freshness
0031 //! checks. They reuse node/reference UID identity and do not introduce a
0032 //! persistent representation identity.
0033 class BRepGraph::UIDsView
0034 {
0035 public:
0036   //! Return the UID assigned to a node.
0037   //! @param[in] theNode node identifier
0038   //! @return UID for the active node, or invalid UID if theNode is out of bounds or removed
0039   [[nodiscard]] Standard_EXPORT BRepGraph_UID Of(const BRepGraph_NodeId theNode) const;
0040 
0041   //! Return the RefUID assigned to a reference.
0042   //! @param[in] theRefId reference identifier
0043   //! @return RefUID for the active reference, or invalid RefUID if theRefId is out of bounds or
0044   //! removed
0045   [[nodiscard]] Standard_EXPORT BRepGraph_RefUID Of(const BRepGraph_RefId theRefId) const;
0046 
0047   //! Return the persistent UID assigned to a generic graph item.
0048   //! @param[in] theItem definition-node or reference-entry item id
0049   //! @return durable item UID, or invalid UID if the item is out of bounds or removed
0050   [[nodiscard]] Standard_EXPORT BRepGraph_ItemUID Of(const BRepGraph_ItemId theItem) const;
0051 
0052   //! Resolve a UID back to a NodeId using the internal reverse index.
0053   //! @param[in] theUID unique identifier to resolve
0054   //! @return corresponding active NodeId, or invalid NodeId if not found/removed
0055   [[nodiscard]] Standard_EXPORT BRepGraph_NodeId NodeIdFrom(const BRepGraph_UID& theUID) const;
0056 
0057   //! Resolve a RefUID back to a RefId using the internal reverse index.
0058   //! @param[in] theUID unique reference identifier to resolve
0059   //! @return corresponding active RefId, or invalid RefId if not found/removed
0060   [[nodiscard]] Standard_EXPORT BRepGraph_RefId RefIdFrom(const BRepGraph_RefUID& theUID) const;
0061 
0062   //! Resolve a generic item UID back to a transient item id.
0063   //! @param[in] theUID durable node/reference item identity
0064   //! @return active item id, or invalid item id if the UID cannot be resolved
0065   [[nodiscard]] Standard_EXPORT BRepGraph_ItemId ItemIdFrom(const BRepGraph_ItemUID& theUID) const;
0066 
0067   //! Check if a UID is valid and exists in this graph generation.
0068   //! @param[in] theUID unique identifier to check
0069   //! @return true if the UID resolves to an active node in this graph generation
0070   [[nodiscard]] Standard_EXPORT bool Has(const BRepGraph_UID& theUID) const;
0071 
0072   //! Check if a RefUID is valid and exists in this graph generation.
0073   //! @param[in] theUID unique reference identifier to check
0074   //! @return true if the RefUID resolves to an active reference in this graph generation
0075   [[nodiscard]] Standard_EXPORT bool Has(const BRepGraph_RefUID& theUID) const;
0076 
0077   //! Check if a generic item UID exists in this graph generation.
0078   [[nodiscard]] Standard_EXPORT bool Has(const BRepGraph_ItemUID& theUID) const;
0079 
0080   //! Return the current generation counter (incremented on each BRepGraph::Clear()).
0081   //! @return graph generation number
0082   [[nodiscard]] Standard_EXPORT uint32_t Generation() const;
0083 
0084   //! Return the graph-level identity GUID.
0085   //! Generated randomly at BRepGraph::Clear() time; changes on each rebuild.
0086   //! @return reference to the graph identity GUID
0087   [[nodiscard]] Standard_EXPORT const Standard_GUID& GraphGUID() const;
0088 
0089   //! Produce a version stamp for the given node.
0090   //! Combines the node's UID with its current OwnGen and graph Generation.
0091   //! @param[in] theNode node identifier
0092   //! @return version stamp, or invalid stamp if theNode is invalid, removed, or out of bounds
0093   [[nodiscard]] Standard_EXPORT BRepGraph_VersionStamp
0094     StampOf(const BRepGraph_NodeId theNode) const;
0095 
0096   //! Produce a version stamp for the given reference.
0097   //! Combines the reference's RefUID with its current OwnGen and graph Generation.
0098   //! @param[in] theRefId reference identifier
0099   //! @return version stamp, or invalid stamp if theRefId is invalid, removed, or out of bounds
0100   [[nodiscard]] Standard_EXPORT BRepGraph_VersionStamp
0101     StampOf(const BRepGraph_RefId theRefId) const;
0102 
0103   //! Produce a version stamp for an owner-scoped use record.
0104   //! Use records have no durable UID or mutation generation; the stamp uses the owning
0105   //! definition-node UID, OwnGen, and graph Generation.
0106   //! @param[in] theRepId use-record identifier
0107   //! @return version stamp, or invalid stamp if theRepId is invalid, removed, or out of bounds
0108   [[nodiscard]] Standard_EXPORT BRepGraph_VersionStamp
0109     StampOf(const BRepGraph_RepId theRepId) const;
0110 
0111   //! Produce a version stamp for the given definition-node or reference-entry item.
0112   [[nodiscard]] Standard_EXPORT BRepGraph_VersionStamp
0113     StampOf(const BRepGraph_ItemId theItem) const;
0114 
0115   //! Check if a previously-taken stamp is stale.
0116   //! A stamp is stale when the stamped item has been mutated,
0117   //! removed, or the graph was rebuilt since the stamp was taken.
0118   //! @param[in] theStamp version stamp to check
0119   //! @return true if the stamp no longer matches the current graph state
0120   [[nodiscard]] Standard_EXPORT bool IsStale(const BRepGraph_VersionStamp& theStamp) const;
0121 
0122 private:
0123   friend class BRepGraph;
0124   friend struct BRepGraph_Data;
0125 
0126   explicit UIDsView(BRepGraph* theGraph)
0127       : myGraph(theGraph)
0128   {
0129   }
0130 
0131   BRepGraph* myGraph;
0132 };
0133 
0134 #endif // _BRepGraph_UIDsView_HeaderFile