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_UsagePath_HeaderFile
0015 #define _BRepGraph_UsagePath_HeaderFile
0016 
0017 #include <BRepGraph_NodeId.hxx>
0018 #include <BRepGraph_RefId.hxx>
0019 #include <NCollection_LinearVector.hxx>
0020 
0021 #include <cstddef>
0022 #include <functional>
0023 
0024 //! Explicit identity of a concrete usage from traversal root to selected node.
0025 //!
0026 //! A usage path is an ordered sequence of steps that records the exact
0027 //! traversal from a root node down to a specific graph entity. Each step
0028 //! captures the node reached, the reference through which it was reached,
0029 //! and the sibling order (step index) at that level.
0030 //!
0031 //! Paths are used to disambiguate multiple occurrences of the same
0032 //! definition reachable through different references or sibling positions.
0033 class BRepGraph_UsagePath
0034 {
0035 public:
0036   //! One concrete traversal step in a usage path.
0037   //!
0038   //! Ref is valid for reference-owned links and invalid for structural links
0039   //! such as CoEdge -> Edge or Occurrence -> Product/topology-root. Step keeps
0040   //! sibling order explicit, so coincident or structurally-linked usages remain
0041   //! distinguishable without relying on location or hashes.
0042   struct Step
0043   {
0044     BRepGraph_NodeId Node;
0045     BRepGraph_RefId  Ref;
0046     int              StepIndex = -1;
0047 
0048     bool operator==(const Step& theOther) const
0049     {
0050       return Node == theOther.Node && Ref == theOther.Ref && StepIndex == theOther.StepIndex;
0051     }
0052   };
0053 
0054 public:
0055   //! Creates an empty usage path.
0056   BRepGraph_UsagePath() = default;
0057 
0058   //! Creates a usage path with pre-allocated capacity.
0059   //! @param[in] theCapacity number of steps to pre-allocate
0060   explicit BRepGraph_UsagePath(const size_t theCapacity)
0061       : mySteps(theCapacity)
0062   {
0063   }
0064 
0065   //! Returns the number of steps in the path.
0066   size_t Size() const { return mySteps.Size(); }
0067 
0068   //! Returns true if the path has no steps.
0069   bool IsEmpty() const { return mySteps.IsEmpty(); }
0070 
0071   //! Returns the step at the given index.
0072   //! @param[in] theIdx zero-based index
0073   const Step& Value(const size_t theIdx) const { return mySteps.Value(theIdx); }
0074 
0075   //! Returns the first step in the path.
0076   const Step& First() const { return mySteps.First(); }
0077 
0078   //! Returns the last step in the path.
0079   const Step& Last() const { return mySteps.Last(); }
0080 
0081   //! Appends a step to the end of the path.
0082   //! @param[in] theStep step to append
0083   void Append(Step theStep) { mySteps.Append(std::move(theStep)); }
0084 
0085   //! Inserts a step before the given index.
0086   //! @param[in] theIdx zero-based index to insert before
0087   //! @param[in] theStep step to insert
0088   void InsertBefore(const size_t theIdx, Step theStep)
0089   {
0090     mySteps.InsertBefore(theIdx, std::move(theStep));
0091   }
0092 
0093   //! Removes all steps from the path.
0094   void Clear() { mySteps.Clear(); }
0095 
0096   //! Returns true if this path is equal to the other path.
0097   //! @param[in] theOther path to compare with
0098   bool IsEqual(const BRepGraph_UsagePath& theOther) const;
0099 
0100   //! Returns true if this path is equal to the other path.
0101   //! @param[in] theOther path to compare with
0102   bool operator==(const BRepGraph_UsagePath& theOther) const { return IsEqual(theOther); }
0103 
0104   //! Returns a hash code for this path.
0105   //! Uses first step, last step, and size for O(1) computation.
0106   size_t HashCode() const;
0107 
0108 private:
0109   NCollection_LinearVector<Step> mySteps;
0110 };
0111 
0112 //! std::hash specialization for BRepGraph_UsagePath.
0113 template <>
0114 struct std::hash<BRepGraph_UsagePath>
0115 {
0116   size_t operator()(const BRepGraph_UsagePath& thePath) const noexcept
0117   {
0118     return thePath.HashCode();
0119   }
0120 };
0121 
0122 #endif // _BRepGraph_UsagePath_HeaderFile