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_NAMESPACEso 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 withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_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 fromonnx.-
namespace internal#
-
struct MutableVisitor#
- #include <visitor.h>
Mutable visitor for ONNX proto objects.
Identical in structure to
Visitorbut receives non-const references, allowing in-place modification of the visited elements. Subclasses may overrideProcessXmethods to mutate elements orVisitXmethods to change traversal order.Subclassed by onnx_light::internal::AttributeBinder
Public Functions
-
inline virtual void VisitGraph(GraphProto &graph)#
Visits all nodes of
graphifProcessGraphreturnstrue.- Parameters:
graph – Mutable reference to the graph to traverse.
-
inline virtual void VisitFunction(FunctionProto &function)#
Visits all nodes of
functionifProcessFunctionreturnstrue.- Parameters:
function – Mutable reference to the function to traverse.
-
inline virtual void VisitNode(NodeProto &node)#
Visits all attributes of
nodeifProcessNodereturnstrue.- Parameters:
node – Mutable reference to the node to traverse.
-
inline virtual void VisitAttribute(AttributeProto &attr)#
Visits graph-valued attribute sub-graphs if
ProcessAttributereturnstrue.- Parameters:
attr – Mutable reference to the attribute to traverse.
-
inline virtual bool ProcessGraph(GraphProto&)#
Called for each graph; returns
trueto visit child nodes.- Parameters:
graph – Mutable reference 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 reference 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 reference 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 reference 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#