fields.h#

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.

Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when lib_onnx_proto uses hidden visibility by default.

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 utils#

Functions

inline bool is_inline_size(const PrintOptions &options, size_t size)#

Returns true if a repeated field of the given size should be printed inline on a single row.

bool enforce_short_repr_length(std::stringstream &ss, const PrintOptions &options)#

Enforces options.max_short_repr_length on the text already accumulated in ss. When the bound is exceeded, the stream content is truncated in place and terminated with an ellipsis.

Returns: True when the content was truncated, false otherwise.

template<typename T>
RepeatedFieldBackInsertIterator<T> RepeatedFieldBackInserter(RepeatedField<T> *field)#

Creates a back-insert iterator for a RepeatedField.

template<typename T>
class _OptionalField#
#include <fields.h>

Optional field wrapper for scalar values.

Public Functions

inline explicit _OptionalField()#

Constructs an empty optional field.

inline bool has_value() const#

Returns true if the field holds a value.

inline void reset()#

Releases the held value, leaving the field empty.

inline const T &operator*() const#

Dereferences to the held value (const).

inline T &operator*()#

Dereferences to the held value.

inline bool operator==(const _OptionalField<T> &v) const#

Returns true if the held value equals another optional field’s value.

inline bool operator==(const T &v) const#

Returns true if the held value equals v.

inline _OptionalField<T> &operator=(const T &other)#

Assigns a scalar value to the field.

inline void set_empty_value()#

Initializes the field with zero-cast value.

Protected Attributes

std::optional<T> value_#
template<typename T>
class OptionalEnumField#
#include <fields.h>

Optional field wrapper for enum values.

Public Functions

inline explicit OptionalEnumField()#

Constructs an empty optional enum field.

inline bool has_value() const#

Returns true if the field holds a value.

inline void reset()#

Releases the held value, leaving the field empty.

inline const T &operator*() const#

Dereferences to the held value (const).

inline T &operator*()#

Dereferences to the held value.

inline bool operator==(const OptionalEnumField<T> &v) const#

Returns true if the held value equals another optional enum field’s value.

inline bool operator==(const T &v) const#

Returns true if the held value equals v.

inline OptionalEnumField<T> &operator=(const T &other)#

Assigns an enum value to the field.

inline void set_empty_value()#

Initializes the field with zero-cast enum value.

Protected Attributes

std::optional<T> value_#
template<typename T>
class OptionalField#
#include <fields.h>

Optional field wrapper for message-like values.

Public Functions

inline explicit OptionalField()#

Constructs an empty optional field.

inline explicit OptionalField(const OptionalField<T> &copy)#

Constructs by copying another optional field.

inline OptionalField(OptionalField<T> &&move) noexcept#

Constructs by moving from another optional field.

inline bool has_value() const#

Returns true if the field holds a value.

inline void reset()#

Releases the held value, leaving the field empty.

T &operator*()#

Dereferences to the held value.

const T &operator*() const#

Dereferences to the held value (const).

OptionalField<T> &operator=(const T &other)#

Assigns a copy of the given value.

OptionalField<T> &operator=(T &&other)#

Assigns by moving the given value into the field.

OptionalField<T> &operator=(const OptionalField<T> &other)#

Assigns from another optional field.

inline OptionalField<T> &operator=(OptionalField<T> &&other) noexcept#

Moves from another optional field.

void set_empty_value()#

Initializes the field with a default-constructed value.

Private Members

simple_unique_ptr<T> value_#
template<>
class OptionalField<float> : public onnx_light::utils::_OptionalField<float>#
#include <fields.h>

Optional field specialization for float.

Public Functions

inline explicit OptionalField()#

Constructs an empty optional float field.

inline OptionalField<float> &operator=(const float &other)#

Assigns a float value to the field.

template<>
class OptionalField<int32_t> : public onnx_light::utils::_OptionalField<int32_t>#
#include <fields.h>

Optional field specialization for int32_t.

Public Functions

inline explicit OptionalField()#

Constructs an empty optional int32_t field.

inline OptionalField<int32_t> &operator=(const int32_t &other)#

Assigns an int32_t value to the field.

template<>
class OptionalField<int64_t> : public onnx_light::utils::_OptionalField<int64_t>#
#include <fields.h>

Optional field specialization for int64_t.

Public Functions

inline explicit OptionalField()#

Constructs an empty optional int64_t field.

inline OptionalField<int64_t> &operator=(const int64_t &other)#

Assigns an int64_t value to the field.

struct PrintOptions#
#include <fields.h>

Options that control how a proto message is printed.

Public Members

bool skip_raw_data = false#

If true, raw data will not be printed but skipped; tensors are not valid in that case but the model structure is still available.

int64_t raw_data_threshold = 1024#

If skip_raw_data is true, raw data will be printed only if it is larger than the threshold.

int64_t inline_threshold = 9#

Repeated fields with at most this many elements are printed as a bracketed list; all output is always flat (no newlines).

size_t max_short_repr_length = 0#

Maximum number of characters produced when printing a short representation (used by proto __repr__). Printing stops as soon as the output reaches this bound and the text is terminated with an ellipsis. Zero (the default) means no limit.

template<typename T>
class RepeatedField#
#include <fields.h>

Repeated primitive field storage.

Public Functions

inline explicit RepeatedField()#

Constructs an empty field.

template<typename Iter>
inline RepeatedField(Iter first, Iter last)#

Constructs from an iterator range.

inline RepeatedField &operator=(std::initializer_list<T> init)#
inline void reserve(size_t n)#

Reserves storage for at least n elements.

inline void Reserve(size_t n)#

Reserves storage for at least n elements (protobuf compat).

inline void clear()#

Removes all elements.

inline void Clear()#

Removes all elements.

inline std::vector<T>::const_iterator cbegin() const#

Returns a const iterator to the first element (protobuf compat).

inline std::vector<T>::const_iterator cend() const#

Returns a const iterator past the last element (protobuf compat).

inline bool empty() const#

Returns true if the field contains no elements.

inline size_t size() const#

Returns the number of elements.

inline T &operator[](size_t index)#

Returns a mutable reference to the element at the given index.

inline const T &Get(size_t index) const#

Returns a const reference to the element at the given index.

inline void Set(size_t index, const T &value)#

Sets the element at the given index (protobuf compat).

inline T *Mutable(size_t index)#

Returns a mutable reference to the owning pointer at the given index.

inline const std::vector<T> &values() const#

Returns a const reference to the underlying vector.

inline std::vector<T> &mutable_values()#

Returns a mutable reference to the underlying vector.

inline const T &operator[](size_t index) const#

Returns a const reference to the element at the given index.

inline void remove_range(size_t start, size_t stop, size_t step)#

Removes a contiguous range; currently only start=0, step=1, and stop=size() are supported.

inline void push_back(const T &v)#

Appends a copy of v at the end.

inline void extend(const std::vector<T> &v)#

Appends all elements from a vector.

inline void extend(const RepeatedField<T> &v)#

Appends all elements from another RepeatedField.

inline T &add()#
inline T *Add()#
template<class U>
inline void Add(U &&v)#

Appends a single value (protobuf compat). Accepts anything convertible to T, including types with an explicit conversion (e.g. std::string -> utils::String).

template<class InputIt>
inline void Add(InputIt first, InputIt last)#

Appends all elements in [first, last) (protobuf RepeatedField::Add range compat).

inline T &back()#

Returns a reference to the last element.

inline std::vector<T>::iterator begin()#

Returns a mutable iterator to the first element.

inline std::vector<T>::iterator end()#

Returns a mutable iterator past the last element.

inline std::vector<T>::const_iterator begin() const#

Returns a const iterator to the first element.

inline std::vector<T>::const_iterator end() const#

Returns a const iterator past the last element.

template<class ...Args>
inline void emplace_back(Args&&... args)#

Constructs a new element in-place at the end.

inline T *data()#

Returns a pointer to the underlying data array.

inline T *mutable_data()#

Returns a mutable pointer to the underlying data array (protobuf compat).

inline const T *data() const#

Returns a const pointer to the underlying data array.

inline void Resize(size_t n, const T &value)#

Resizes the field to n elements, filling new slots with value.

inline void resize(size_t n)#

Resizes the field to n elements, default-constructing new slots.

template<typename InputIt>
inline void Assign(InputIt first, InputIt last)#

Assigns the contents from an iterator range.

inline void CopyFrom(const RepeatedField<T> &other)#

Copies all elements from another RepeatedField.

inline int size_int() const#

Returns the number of elements as int (protobuf compat).

void PrintToStringStream(std::stringstream &ss, PrintOptions &options) const#

Writes string representations of the contained values to ss.

Private Members

std::vector<T> values_#
template<typename T>
class RepeatedFieldBackInsertIterator#
#include <fields.h>

Output iterator that appends to a RepeatedField via push_back. Mirrors std::back_insert_iterator so it can back google::protobuf::RepeatedFieldBackInsertIterator as a pure alias.

Public Types

using iterator_category = std::output_iterator_tag#
using value_type = void#
using difference_type = std::ptrdiff_t#
using pointer = void#
using reference = void#

Public Functions

inline explicit RepeatedFieldBackInsertIterator(RepeatedField<T> *field)#

Wraps field; appended values go to its end.

inline RepeatedFieldBackInsertIterator &operator=(const T &value)#

Appends a copy of value.

inline RepeatedFieldBackInsertIterator &operator=(T &&value)#

Appends value (moved).

inline RepeatedFieldBackInsertIterator &operator*()#
inline RepeatedFieldBackInsertIterator &operator++()#
inline RepeatedFieldBackInsertIterator operator++(int)#

Private Members

RepeatedField<T> *field_#
template<typename T>
class RepeatedProtoField#
#include <fields.h>

Repeated message field storage with owning pointers.

Public Functions

inline explicit RepeatedProtoField()#

Constructs an empty field.

inline RepeatedProtoField(const RepeatedField<T> &src)#

Constructs by copying elements from a value-storage RepeatedField<T>. This makes onnx-light’s value-based repeated fields (used for message entries such as StringStringEntryProto) usable wherever a protobuf RepeatedPtrField (== RepeatedProtoField) is expected by drop-in consumers such as onnxruntime, without changing the field’s own storage.

inline RepeatedProtoField(const std::vector<T> &src)#

Copies elements from a vector into a RepeatedProtoField.

inline RepeatedProtoField(std::vector<T> &&src)#

Move-constructs by moving each element from a vector into the field (no deep copy).

inline RepeatedProtoField(const RepeatedProtoField<T> &src)#

Deep-copies elements from another RepeatedProtoField (protobuf value semantics: each owned element is cloned rather than sharing ownership).

inline RepeatedProtoField(RepeatedProtoField<T> &&src) noexcept#

Move-constructs by stealing ownership from another RepeatedProtoField.

inline RepeatedProtoField &operator=(const RepeatedProtoField<T> &src)#

Deep-copies elements from another RepeatedProtoField (protobuf value semantics).

inline RepeatedProtoField &operator=(RepeatedProtoField<T> &&src) noexcept#

Move-assigns by stealing ownership from another RepeatedProtoField.

inline void reserve(size_t n)#

Reserves storage for at least n elements.

inline void Reserve(size_t n)#

Reserves storage for at least n elements (protobuf compat).

void resize(size_t n)#

Resizes the field to contain exactly n elements, appending default-constructed elements or removing trailing elements as needed.

inline bool empty() const#

Returns true if the field contains no elements.

inline size_t size() const#

Returns the number of elements.

inline T &operator[](size_t index)#

Returns a mutable reference to the element at the given index.

inline const T &operator[](size_t index) const#

Returns a const reference to the element at the given index.

inline std::shared_ptr<T> &get(size_t index)#

Returns a mutable reference to the owning pointer at the given index.

inline std::shared_ptr<T> shared_at(size_t index) const#

Returns the shared pointer at the given index (shared ownership copy).

inline const T &Get(size_t index) const#

Returns a mutable reference to the owning pointer at the given index.

inline const T &at(size_t index) const#

Returns a const reference to the element at the given index (bounds-checked, protobuf compat).

inline T &at(size_t index)#

Returns a mutable reference to the element at the given index (bounds-checked, protobuf compat).

inline T *Mutable(size_t index)#

Returns a mutable reference to the owning pointer at the given index.

inline void remove_range(size_t start, size_t stop, size_t step)#

Removes a contiguous range; currently only start=0, step=1, and stop=size() are supported.

void clear()#

Removes all elements.

inline void Clear()#

Removes all elements.

inline void RemoveLast()#
void push_back(const T &v)#

Appends a copy of v at the end.

void push_back(T &&v)#

Appends v at the end by stealing its contents (no copy).

void extend(const std::vector<T> &v)#

Appends all elements from a vector.

void extend(std::vector<T> &&v)#

Appends all elements from a vector by move (no per-element copy).

void extend(const RepeatedProtoField<T> &v)#

Appends all elements from another RepeatedProtoField by copy.

void extend(RepeatedProtoField<T> &&v)#

Appends all elements from another RepeatedProtoField by move (steals ownership).

T &add()#

Appends a default-constructed element and returns a reference to it.

inline T *Add()#

Appends a default-constructed element and returns a pointer to it.

inline void SwapElements(int i, int j)#

Swaps the elements at positions i and j (protobuf RepeatedPtrField::SwapElements compat).

template<class ...Args>
inline void emplace_back(Args&&... args)#

Constructs a new element in-place at the end.

T &back()#

Returns a reference to the last element.

void PrintToStringStream(std::stringstream &ss, PrintOptions &options) const#

Writes string representations of the contained values to ss.

inline iterator begin()#

Returns a mutable iterator to the first element.

inline iterator end()#

Returns a mutable iterator past the last element.

inline pointer_iterator pointer_begin()#

Returns a pointer iterator to the first element.

inline pointer_iterator pointer_end()#

Returns a pointer iterator past the last element.

inline iterator erase(iterator it)#

Removes the element at the given iterator position and returns an iterator to the next element.

inline iterator erase(iterator first, iterator last)#

Removes the elements in [first, last) and returns an iterator to the element that followed the last removed element (protobuf RepeatedPtrField::erase compat).

inline const_iterator begin() const#

Returns a const iterator to the first element.

inline const_iterator end() const#

Returns a const iterator past the last element.

inline const_iterator cbegin() const#

Returns a const iterator to the first element (protobuf compat).

inline const_iterator cend() const#

Returns a const iterator past the last element (protobuf compat).

Private Members

std::vector<std::shared_ptr<T>> values_#
class const_iterator#
#include <fields.h>

Const iterator for repeated proto fields.

Public Types

using iterator_category = std::random_access_iterator_tag#
using value_type = T#
using difference_type = std::ptrdiff_t#
using pointer = const T*#
using reference = const T&#

Public Functions

inline explicit const_iterator(const RepeatedProtoField<T> *parent, size_t pos = 0)#

Constructs a const iterator for parent starting at pos.

inline const_iterator &operator++()#

Advances the iterator to the next element.

inline bool operator==(const const_iterator &other) const#

Returns true if both iterators point to the same position in the same field.

inline bool operator!=(const const_iterator &other) const#

Returns true if the iterators differ.

inline difference_type operator-(const const_iterator &other) const#
inline const T &operator*() const#

Dereferences to the current element.

inline const T *operator->() const#

Private Members

const RepeatedProtoField<T> *parent_#
size_t pos_#
class iterator#
#include <fields.h>

Mutable iterator for repeated proto fields.

Public Types

using iterator_category = std::random_access_iterator_tag#
using value_type = T#
using difference_type = std::ptrdiff_t#
using pointer = T*#
using reference = T&#

Public Functions

inline iterator(RepeatedProtoField<T> *parent, size_t pos = 0)#

Constructs an iterator for parent starting at pos.

inline iterator &operator++()#

Advances the iterator to the next element.

inline bool operator==(const iterator &other) const#

Returns true if both iterators point to the same position in the same field.

inline bool operator!=(const iterator &other) const#

Returns true if the iterators differ.

inline difference_type operator-(const iterator &other) const#

Returns the distance between two iterators (random-access compat).

inline iterator operator-(std::ptrdiff_t n) const#

Returns an iterator advanced backwards by n positions (random-access compat).

inline iterator operator+(std::ptrdiff_t n) const#

Returns an iterator advanced forwards by n positions (random-access compat).

inline T &operator*() const#

Dereferences to the current element.

inline T *operator->() const#
inline size_t pos() const#

Returns the current position index.

Private Members

RepeatedProtoField<T> *parent_#
size_t pos_#
class pointer_iterator#
#include <fields.h>

Iterator over raw element pointers (protobuf pointer_begin/pointer_end compat).

Public Types

using iterator_category = std::forward_iterator_tag#
using value_type = T*#
using difference_type = std::ptrdiff_t#
using pointer = T**#
using reference = T*#

Public Functions

inline pointer_iterator(RepeatedProtoField<T> *parent, size_t pos = 0)#

Constructs a pointer iterator for parent starting at pos.

inline pointer_iterator &operator++()#

Advances the iterator to the next element.

inline pointer_iterator operator++(int)#

Advances the iterator to the next element (post-increment).

inline bool operator==(const pointer_iterator &other) const#

Returns true if both iterators point to the same position in the same field.

inline bool operator!=(const pointer_iterator &other) const#

Returns true if the iterators differ.

inline T *operator*() const#

Dereferences to the raw pointer of the current element.

inline size_t pos() const#

Returns the current position index.

Private Members

RepeatedProtoField<T> *parent_#
size_t pos_#
class RepeatedStringField : public onnx_light::utils::RepeatedField<utils::String>#
#include <fields.h>

Repeated field used by name-like string lists (for example NodeProto inputs/outputs).

template<typename T>
class simple_unique_ptr#
#include <fields.h>

Minimal unique_ptr-like holder used by generated proto containers.

Public Functions

inline explicit simple_unique_ptr(T *ptr = nullptr)#

Constructs from a raw pointer (defaults to null); takes ownership if non-null.

inline ~simple_unique_ptr()#

Releases owned memory.

inline simple_unique_ptr(simple_unique_ptr &&other) noexcept#

Constructs by taking ownership from another instance.

inline simple_unique_ptr &operator=(simple_unique_ptr &&other) noexcept#

Transfers ownership from another instance.

inline bool isnull() const#

Returns true if the held pointer is null.

inline bool operator==(const simple_unique_ptr &other) const#

Returns true if both instances hold the same pointer.

inline bool operator!=(const simple_unique_ptr &other) const#

Returns true if the instances hold different pointers.

inline simple_unique_ptr(const simple_unique_ptr&)#

Deleted copy constructor; use move semantics instead.

inline simple_unique_ptr &operator=(const simple_unique_ptr&)#

Deleted copy assignment; use move semantics instead.

inline T *get() const#

Returns the raw pointer without releasing ownership.

inline T &operator*() const#

Dereferences the held pointer.

inline T *operator->() const#

Provides member access through the held pointer.

inline T &reset_and(T *new_ptr)#

Replaces the held pointer and returns a reference to the new object.

inline void reset(T *new_ptr = nullptr)#

Deletes the held object and optionally takes a new pointer.

Private Members

T *ptr_#