Helpers#
Defines
-
ONNX_LIGHT_NAMESPACE#
-
EXT_THROW(...)#
Throws a
std::runtime_errorwhose message is built by MakeString from__VA_ARGS__, prefixed with “[onnx-light]”.
-
_THROW_DEFINED#
-
EXT_ENFORCE(cond, ...)#
Evaluates
condand throws astd::runtime_errorwhen it is false. The error message includes the stringified condition and the message built from__VA_ARGS__via MakeString, prefixed with “[onnx-light]”.
-
_ENFORCE_DEFINED#
-
EXT_THROW_INVALID(...)#
Throws a
std::invalid_argumentwhose message is built by MakeString from__VA_ARGS__, prefixed with “[onnx-light]”.
-
_THROW_INVALID_DEFINED#
-
EXT_ENFORCE_INVALID(cond, ...)#
Evaluates
condand throws astd::invalid_argumentwhen it is false. The error message includes the stringified condition and the message built from__VA_ARGS__via MakeString, prefixed with “[onnx-light]”. Behaves like EXT_ENFORCE but raises std::invalid_argument instead of std::runtime_error; intended to replaceif (cond) throw std::invalid_argument(...)patterns.
-
_ENFORCE_INVALID_DEFINED#
-
namespace onnx_light_helpers#
Functions
-
std::vector<std::string> SplitString(const std::string &input, char delimiter)#
Splits
inputinto substrings at each occurrence ofdelimiter.
-
void MakeStringInternalElement(StringStream &ss, const char *t)#
Appends a null-terminated C string to
ss.
-
void MakeStringInternalElement(StringStream &ss, const std::string &t)#
Appends a standard string to
ss.
-
void MakeStringInternalElement(StringStream &ss, const char &t)#
Appends a single character to
ss.
-
void MakeStringInternalElement(StringStream &ss, const uint16_t &t)#
Appends an unsigned 16-bit integer to
ss.
-
void MakeStringInternalElement(StringStream &ss, const uint32_t &t)#
Appends an unsigned 32-bit integer to
ss.
-
void MakeStringInternalElement(StringStream &ss, const uint64_t &t)#
Appends an unsigned 64-bit integer to
ss.
-
void MakeStringInternalElement(StringStream &ss, const int16_t &t)#
Appends a signed 16-bit integer to
ss.
-
void MakeStringInternalElement(StringStream &ss, const int32_t &t)#
Appends a signed 32-bit integer to
ss.
-
void MakeStringInternalElement(StringStream &ss, const int64_t &t)#
Appends a signed 64-bit integer to
ss.
-
void MakeStringInternalElement(StringStream &ss, const uint64_t *&t)#
Appends a textual description of the const uint64_t pointer reference to
ss; outputs a null marker when the pointer is null.
-
void MakeStringInternalElement(StringStream &ss, const uint64_t *t)#
Appends a textual description of the const uint64_t pointer to
ss; outputs a null marker when the pointer is null.
-
void MakeStringInternalElement(StringStream &ss, const float &t)#
Appends a single-precision floating-point value to
ss.
-
void MakeStringInternalElement(StringStream &ss, const double &t)#
Appends a double-precision floating-point value to
ss.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<uint16_t> &t)#
Appends each element of a uint16 vector to
ss, prefixed with “x”.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<uint32_t> &t)#
Appends each element of a uint32 vector to
ss, prefixed with “x”.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<uint64_t> &t)#
Appends each element of a uint64 vector to
ss, prefixed with “x”.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<int16_t> &t)#
Appends each element of an int16 vector to
ss, prefixed with “x”.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<int32_t> &t)#
Appends each element of an int32 vector to
ss, prefixed with “x”.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<int64_t> &t)#
Appends each element of an int64 vector to
ss, prefixed with “x”.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<float> &t)#
Appends each element of a float vector to
ss, prefixed with “x”.
-
void MakeStringInternalElement(StringStream &ss, const std::vector<double> &t)#
Appends each element of a double vector to
ss, prefixed with “x”.
-
template<typename T, std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value && !std::is_same<T, char>::value && !std::is_same<T, uint16_t>::value && !std::is_same<T, uint32_t>::value && !std::is_same<T, uint64_t>::value && !std::is_same<T, int16_t>::value && !std::is_same<T, int32_t>::value && !std::is_same<T, int64_t>::value, int> = 0>
inline void MakeStringInternalElement(StringStream &ss, const T &t)# Catch-all overload for integer types not covered by the explicit declarations above.
On POSIX platforms (macOS, Linux)
unsigned long(=size_t) andlong(=ssize_t) are distinct fromuint64_t(unsigned long long) andint64_t(long long). Without this overload the call would be ambiguous across the fixed-width integer overloads. Non-template overloads take priority, so on platforms where these types coincide (e.g. Windows wheresize_t==uint64_t) the explicit overloads remain selected.- Template Parameters:
T – An integral type that is not
bool,char, or any of the fixed-width types already covered by explicit overloads.- Parameters:
ss – The stream to append to.
t – The value to append.
-
void MakeStringInternal(StringStream &ss)#
Base case of MakeStringInternal: does nothing when there are no remaining arguments.
-
template<typename T, typename ...Args>
inline void MakeStringInternal(StringStream &ss, const T &t)# Appends the single value
ttoss.- Template Parameters:
T – Type of the value to append; must have a corresponding MakeStringInternalElement overload.
-
template<typename T, typename ...Args>
inline void MakeStringInternal(StringStream &ss, const T &t, const Args&... args)# Appends
tand all remainingargstoss.- Template Parameters:
T – Type of the first value.
Args – Types of the remaining values.
-
template<typename ...Args>
inline std::string MakeString(const Args&... args)# Formats all arguments as a single concatenated string.
Allocates a temporary StringStream, appends each argument via MakeStringInternal, and returns the resulting string.
- Template Parameters:
Args – Types of the values to format.
- Parameters:
args – Values to format.
- Returns:
The concatenated string representation of all arguments.
-
inline bool IsPowerOfTwo(int64_t value)#
Returns true when
valueis a power of two and strictly positive.
-
inline void ValidateAlignmentOption(int64_t alignment, const char *option_name)#
Validates an alignment option value.
- Parameters:
alignment – Alignment value to validate.
option_name – Name of the option used in error messages. Throws std::runtime_error when alignment is negative or not a power of two when positive.
-
class StringStream#
- #include <onnx_light_helpers.h>
Abstract string builder used by the MakeString helper functions. Concrete subclasses override each typed append method so that the same template-based formatting code can target different output sinks.
Public Functions
-
StringStream()#
Constructs an empty stream.
-
virtual ~StringStream()#
Destroys the stream and releases any owned resources.
-
virtual StringStream &append_uint16(const uint16_t &obj)#
Appends an unsigned 16-bit integer value.
-
virtual StringStream &append_uint32(const uint32_t &obj)#
Appends an unsigned 32-bit integer value.
-
virtual StringStream &append_uint64(const uint64_t &obj)#
Appends an unsigned 64-bit integer value.
-
virtual StringStream &append_int16(const int16_t &obj)#
Appends a signed 16-bit integer value.
-
virtual StringStream &append_int32(const int32_t &obj)#
Appends a signed 32-bit integer value.
-
virtual StringStream &append_int64(const int64_t &obj)#
Appends a signed 64-bit integer value.
-
virtual StringStream &append_float(const float &obj)#
Appends a single-precision floating-point value.
-
virtual StringStream &append_double(const double &obj)#
Appends a double-precision floating-point value.
-
virtual StringStream &append_char(const char &obj)#
Appends a single character.
-
virtual StringStream &append_string(const std::string &obj)#
Appends a standard string.
-
virtual StringStream &append_charp(const char *obj)#
Appends a null-terminated character array.
Public Static Functions
-
static StringStream *NewStream()#
Allocates and returns a new concrete StringStream instance.
-
StringStream()#
-
std::vector<std::string> SplitString(const std::string &input, char delimiter)#