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 Visitor but receives non-const pointers, allowing in-place modification of the visited elements. Subclasses may override ProcessX methods to mutate elements or VisitX methods to change traversal order.

Subclassed by ONNX_LIGHT_NAMESPACE::internal::AttributeBinder

Public Functions

inline virtual void VisitGraph(GraphProto *graph)#

Visits all nodes of graph if ProcessGraph returns true.

Parameters:

graph – Mutable pointer to the graph to traverse.

inline virtual void VisitFunction(FunctionProto *function)#

Visits all nodes of function if ProcessFunction returns true.

Parameters:

function – Mutable pointer to the function to traverse.

inline virtual void VisitNode(NodeProto *node)#

Visits all attributes of node if ProcessNode returns true.

Parameters:

node – Mutable pointer to the node to traverse.

inline virtual void VisitAttribute(AttributeProto *attr)#

Visits graph-valued attribute sub-graphs if ProcessAttribute returns true.

Parameters:

attr – Mutable pointer to the attribute to traverse.

inline virtual bool ProcessGraph(GraphProto*)#

Called for each graph; returns true to visit child nodes.

Parameters:

graph – Mutable pointer to the current graph.

Returns:

true to descend into child nodes; false to skip them.

inline virtual bool ProcessFunction(FunctionProto*)#

Called for each function; returns true to visit child nodes.

Parameters:

function – Mutable pointer to the current function.

Returns:

true to descend into child nodes; false to skip them.

inline virtual bool ProcessNode(NodeProto*)#

Called for each node; returns true to visit child attributes.

Parameters:

node – Mutable pointer to the current node.

Returns:

true to descend into child attributes; false to skip them.

inline virtual bool ProcessAttribute(AttributeProto*)#

Called for each attribute; returns true to visit sub-graphs.

Parameters:

attr – Mutable pointer to the current attribute.

Returns:

true to descend into sub-graphs; false to skip them.

virtual ~MutableVisitor() = default#
struct Visitor#
#include <visitor.h>

Read-only visitor for ONNX proto objects.

Covers Nodes, Graphs, Attributes, and Functions. Each VisitX method calls the corresponding ProcessX virtual method; if ProcessX returns true the traversal continues into the children of the visited element.

Subclasses should override one or more ProcessX methods to observe elements during traversal, and may override VisitX methods to change how children are enumerated.

Public Functions

inline virtual void VisitGraph(const GraphProto &graph)#

Visits all nodes of graph if ProcessGraph returns true.

Parameters:

graphGraph to traverse.

inline virtual void VisitFunction(const FunctionProto &function)#

Visits all nodes of function if ProcessFunction returns true.

Parameters:

function – Function to traverse.

inline virtual void VisitNode(const NodeProto &node)#

Visits all attributes of node if ProcessNode returns true.

Parameters:

nodeNode to traverse.

inline virtual void VisitAttribute(const AttributeProto &attr)#

Visits graph-valued attribute sub-graphs if ProcessAttribute returns true.

Parameters:

attr – Attribute to traverse.

inline virtual bool ProcessGraph(const GraphProto&)#

Called for each graph; returns true to visit child nodes.

Parameters:

graph – The current graph.

Returns:

true to descend into child nodes; false to skip them.

inline virtual bool ProcessFunction(const FunctionProto&)#

Called for each function; returns true to visit child nodes.

Parameters:

function – The current function.

Returns:

true to descend into child nodes; false to skip them.

inline virtual bool ProcessNode(const NodeProto&)#

Called for each node; returns true to visit child attributes.

Parameters:

node – The current node.

Returns:

true to descend into child attributes; false to skip them.

inline virtual bool ProcessAttribute(const AttributeProto&)#

Called for each attribute; returns true to visit sub-graphs.

Parameters:

attr – The current attribute.

Returns:

true to descend into sub-graphs; false to skip them.

virtual ~Visitor() = default#