visitor.h#
Read-only and mutable visitor base classes for ONNX proto objects.
Provides two CRTP-style base structs — Visitor and MutableVisitor — for traversing the ONNX proto object graph (graphs, functions, nodes, and attributes). Override the ProcessX virtual methods to react to each element; override VisitX to change the traversal itself.
This header is adapted from onnx/common/visitor.h for the onnx-light proto API (ref_* accessors instead of the standard protobuf mutable_* pattern).
-
namespace ONNX_LIGHT_NAMESPACE
-
namespace internal#
-
struct MutableVisitor#
- #include <visitor.h>
Mutable visitor for ONNX proto objects.
Identical in structure to
Visitorbut receives non-const pointers, allowing in-place modification of the visited elements. Subclasses may overrideProcessXmethods to mutate elements orVisitXmethods to change traversal order.Subclassed by ONNX_LIGHT_NAMESPACE::internal::AttributeBinder
Public Functions
-
inline virtual void VisitGraph(GraphProto *graph)#
Visits all nodes of
graphifProcessGraphreturnstrue.- Parameters:
graph – Mutable pointer to the graph to traverse.
-
inline virtual void VisitFunction(FunctionProto *function)#
Visits all nodes of
functionifProcessFunctionreturnstrue.- Parameters:
function – Mutable pointer to the function to traverse.
-
inline virtual void VisitNode(NodeProto *node)#
Visits all attributes of
nodeifProcessNodereturnstrue.- Parameters:
node – Mutable pointer to the node to traverse.
-
inline virtual void VisitAttribute(AttributeProto *attr)#
Visits graph-valued attribute sub-graphs if
ProcessAttributereturnstrue.- Parameters:
attr – Mutable pointer to the attribute to traverse.
-
inline virtual bool ProcessGraph(GraphProto*)#
Called for each graph; returns
trueto visit child nodes.- Parameters:
graph – Mutable pointer to the current graph.
- Returns:
trueto descend into child nodes;falseto skip them.
-
inline virtual bool ProcessFunction(FunctionProto*)#
Called for each function; returns
trueto visit child nodes.- Parameters:
function – Mutable pointer to the current function.
- Returns:
trueto descend into child nodes;falseto skip them.
-
inline virtual bool ProcessNode(NodeProto*)#
Called for each node; returns
trueto visit child attributes.- Parameters:
node – Mutable pointer to the current node.
- Returns:
trueto descend into child attributes;falseto skip them.
-
inline virtual bool ProcessAttribute(AttributeProto*)#
Called for each attribute; returns
trueto visit sub-graphs.- Parameters:
attr – Mutable pointer to the current attribute.
- Returns:
trueto descend into sub-graphs;falseto skip them.
-
virtual ~MutableVisitor() = default#
-
inline virtual void VisitGraph(GraphProto *graph)#
-
struct Visitor#
- #include <visitor.h>
Read-only visitor for ONNX proto objects.
Covers Nodes, Graphs, Attributes, and Functions. Each
VisitXmethod calls the correspondingProcessXvirtual method; ifProcessXreturnstruethe traversal continues into the children of the visited element.Subclasses should override one or more
ProcessXmethods to observe elements during traversal, and may overrideVisitXmethods to change how children are enumerated.Public Functions
-
inline virtual void VisitGraph(const GraphProto &graph)#
Visits all nodes of
graphifProcessGraphreturnstrue.- Parameters:
graph – Graph to traverse.
-
inline virtual void VisitFunction(const FunctionProto &function)#
Visits all nodes of
functionifProcessFunctionreturnstrue.- Parameters:
function – Function to traverse.
-
inline virtual void VisitNode(const NodeProto &node)#
Visits all attributes of
nodeifProcessNodereturnstrue.- Parameters:
node – Node to traverse.
-
inline virtual void VisitAttribute(const AttributeProto &attr)#
Visits graph-valued attribute sub-graphs if
ProcessAttributereturnstrue.- Parameters:
attr – Attribute to traverse.
-
inline virtual bool ProcessGraph(const GraphProto&)#
Called for each graph; returns
trueto visit child nodes.- Parameters:
graph – The current graph.
- Returns:
trueto descend into child nodes;falseto skip them.
-
inline virtual bool ProcessFunction(const FunctionProto&)#
Called for each function; returns
trueto visit child nodes.- Parameters:
function – The current function.
- Returns:
trueto descend into child nodes;falseto skip them.
-
inline virtual bool ProcessNode(const NodeProto&)#
Called for each node; returns
trueto visit child attributes.- Parameters:
node – The current node.
- Returns:
trueto descend into child attributes;falseto skip them.
-
inline virtual bool ProcessAttribute(const AttributeProto&)#
Called for each attribute; returns
trueto visit sub-graphs.- Parameters:
attr – The current attribute.
- Returns:
trueto descend into sub-graphs;falseto skip them.
-
virtual ~Visitor() = default#
-
inline virtual void VisitGraph(const GraphProto &graph)#
-
struct MutableVisitor#
-
namespace internal#