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

Alias that makes onnx-light headers compatible with code that references ONNX_LIGHT_NAMESPACE (the macro used in the standard onnx package).

Set to ONNX_LIGHT_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Defined as empty because onnx-light does not require explicit __declspec(dllexport) or __attribute__((visibility("default"))) annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations with ONNX_API compile without modification.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_light (via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs from onnx.

namespace internal#
struct MutableVisitor#
#include <visitor.h>

Mutable visitor for ONNX proto objects.

Identical in structure to Visitor but receives non-const references, 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::internal::AttributeBinder

Public Functions

inline virtual void VisitGraph(GraphProto &graph)#

Visits all nodes of graph if ProcessGraph returns true.

Parameters:

graph – Mutable reference to the graph to traverse.

inline virtual void VisitFunction(FunctionProto &function)#

Visits all nodes of function if ProcessFunction returns true.

Parameters:

function – Mutable reference to the function to traverse.

inline virtual void VisitNode(NodeProto &node)#

Visits all attributes of node if ProcessNode returns true.

Parameters:

node – Mutable reference to the node to traverse.

inline virtual void VisitAttribute(AttributeProto &attr)#

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

Parameters:

attr – Mutable reference to the attribute to traverse.

inline virtual bool ProcessGraph(GraphProto&)#

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

Parameters:

graph – Mutable reference 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 reference 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 reference 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 reference 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#