6#ifndef MATERIALX_TRAVERSAL_H
7#define MATERIALX_TRAVERSAL_H
14MATERIALX_NAMESPACE_BEGIN
32 Edge(ElementPtr elemDown, ElementPtr elemConnect, ElementPtr elemUp) :
34 _elemConnect(elemConnect),
40 bool operator==(
const Edge& rhs)
const
42 return _elemDown == rhs._elemDown &&
43 _elemConnect == rhs._elemConnect &&
44 _elemUp == rhs._elemUp;
46 bool operator!=(
const Edge& rhs)
const
48 return !(*
this == rhs);
50 bool operator<(
const Edge& rhs)
const
52 return std::tie(_elemDown, _elemConnect, _elemUp) < std::tie(rhs._elemDown, rhs._elemConnect, rhs._elemUp);
55 operator bool()
const;
80 ElementPtr _elemConnect;
100 using StackFrame = std::pair<ElementPtr, size_t>;
105 return _elem == rhs._elem &&
106 _stack == rhs._stack &&
107 _prune == rhs._prune;
111 return !(*
this == rhs);
141 return _stack.size();
171 _holdCount = holdCount;
182 vector<StackFrame> _stack;
199 _pathElems.insert(elem);
204 using ElementSet = std::set<ElementPtr>;
205 using StackFrame = std::pair<ElementPtr, size_t>;
210 return _upstreamElem == rhs._upstreamElem &&
211 _stack == rhs._stack &&
212 _prune == rhs._prune;
216 return !(*
this == rhs);
222 return Edge(getDownstreamElement(),
223 getConnectingElement(),
224 getUpstreamElement());
237 return !_stack.empty() ? _stack.back().first :
ElementPtr();
243 return _connectingElem;
249 return _upstreamElem;
256 return !_stack.empty() ? _stack.back().second : 0;
267 return _stack.size();
307 _holdCount = holdCount;
317 void extendPathUpstream(ElementPtr upstreamElem, ElementPtr connectingElem);
318 void returnPathDownstream(ElementPtr upstreamElem);
321 ElementPtr _upstreamElem;
322 ElementPtr _connectingElem;
323 ElementSet _pathElems;
324 vector<StackFrame> _stack;
340 _pathElems.insert(elem);
345 using ConstElementSet = std::set<ConstElementPtr>;
350 return _elem == rhs._elem;
354 return !(*
this == rhs);
372 _holdCount = holdCount;
380 ConstElementPtr _elem;
381 ConstElementSet _pathElems;
390 using Exception::Exception;
393extern MX_CORE_API
const Edge NULL_EDGE;
395extern MX_CORE_API
const TreeIterator NULL_TREE_ITERATOR;
399MATERIALX_NAMESPACE_END
shared_ptr< const Element > ConstElementPtr
A shared pointer to a const Element.
Definition: Element.h:33
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
An edge between two connected Elements, returned during graph traversal.
Definition: Traversal.h:30
string getName() const
Return the name of this edge, if any.
ElementPtr getDownstreamElement() const
Return the downstream element of the edge.
Definition: Traversal.h:58
ElementPtr getConnectingElement() const
Return the connecting element of the edge, if any.
Definition: Traversal.h:64
ElementPtr getUpstreamElement() const
Return the upstream element of the edge.
Definition: Traversal.h:70
The base class for MaterialX elements.
Definition: Element.h:80
An exception that is thrown when a traversal call encounters a cycle.
Definition: Traversal.h:388
The base class for exceptions that are propagated from the MaterialX library to the client applicatio...
Definition: Exception.h:22
An iterator object representing the state of an upstream graph traversal.
Definition: Traversal.h:192
GraphIterator & operator++()
Iterate to the next edge in the traversal.
ElementPtr getDownstreamElement() const
Return the downstream element of the current edge.
Definition: Traversal.h:235
size_t getNodeDepth() const
Return the node depth of the current traversal, where a single edge between two nodes represents a de...
size_t getUpstreamIndex() const
Return the index of the current edge within the range of upstream edges available to the downstream e...
Definition: Traversal.h:254
bool getPruneSubgraph() const
Return the prune subgraph flag, which controls whether the current subgraph is pruned from traversal.
Definition: Traversal.h:288
Edge operator*() const
Dereference this iterator, returning the current edge in the traversal.
Definition: Traversal.h:220
ElementPtr getConnectingElement() const
Return the connecting element, if any, of the current edge.
Definition: Traversal.h:241
static const GraphIterator & end()
Return the sentinel end iterator for this class.
ElementPtr getUpstreamElement() const
Return the upstream element of the current edge.
Definition: Traversal.h:247
void setPruneSubgraph(bool prune)
Set the prune subgraph flag, which controls whether the current subgraph is pruned from traversal.
Definition: Traversal.h:281
size_t getElementDepth() const
Return the element depth of the current traversal, where a single edge between two elements represent...
Definition: Traversal.h:265
GraphIterator & begin(size_t holdCount=0)
Interpret this object as an iteration range, and return its begin iterator.
Definition: Traversal.h:299
An iterator object representing the current state of an inheritance traversal.
Definition: Traversal.h:334
InheritanceIterator & begin(size_t holdCount=0)
Interpret this object as an iteration range, and return its begin iterator.
Definition: Traversal.h:370
InheritanceIterator & operator++()
Iterate to the next element in the traversal.
ConstElementPtr operator*() const
Dereference this iterator, returning the current element in the traversal.
Definition: Traversal.h:359
static const InheritanceIterator & end()
Return the sentinel end iterator for this class.
An iterator object representing the state of a tree traversal.
Definition: Traversal.h:89
TreeIterator & begin(size_t holdCount=0)
Interpret this object as an iteration range, and return its begin iterator.
Definition: Traversal.h:169
static const TreeIterator & end()
Return the sentinel end iterator for this class.
ElementPtr operator*() const
Dereference this iterator, returning the current element in the traversal.
Definition: Traversal.h:116
void setPruneSubtree(bool prune)
Set the prune subtree flag, which controls whether the current subtree is pruned from traversal.
Definition: Traversal.h:151
ElementPtr getElement() const
Return the current element in the traversal.
Definition: Traversal.h:128
size_t getElementDepth() const
Return the element depth of the current traversal, where the starting element represents a depth of z...
Definition: Traversal.h:139
TreeIterator & operator++()
Iterate to the next element in the traversal.
bool getPruneSubtree() const
Return the prune subtree flag, which controls whether the current subtree is pruned from traversal.
Definition: Traversal.h:158