Utilities

This page documents some of the utilities found in oead/util/.

Warning

Anything that is not explicitly documented on this page should be considered an implementation detail that is not to be relied upon.

Swap utils

#include <oead/util/swap.h>

enum oead::util::Endianness

Values:

Big
Little
template<typename T>
T oead::util::SwapValue(T data)

Byte swap a value.

template<typename T, Endianness Endian>
struct EndianInt

A wrapper that stores an integer in the specified endianness and automatically bytes swap when reading/writing the value.

Public Functions

EndianInt()
EndianInt(T val)
operator T() const
EndianInt &operator=(T v)
using oead::util::BeInt = EndianInt<T, Endianness::Big>
using oead::util::LeInt = EndianInt<T, Endianness::Little>

For the Python API:

class oead.Endianness
Big
Little

Variant utils

#include <oead/util/variant_utils.h>

template<typename EnumType, typename ...Types>
struct Variant

A std::variant wrapper that transparently dereferences unique_ptrs. This is intended for be used for variants that can contain possibly large values.

Public Types

template<>
using Storage = std::variant<Types...>

Public Functions

Variant()
Variant(const Variant &other)
Variant(Variant &&other)
template<typename T, std::enable_if_t<IsAnyOfType<std::decay_t<T>, Types...>() || IsAnyOfType<std::unique_ptr<std::decay_t<T>>, Types...>()> * = nullptr>
Variant(const T &value)
template<typename T, std::enable_if_t<IsAnyOfType<std::decay_t<T>, Types...>() || IsAnyOfType<std::unique_ptr<std::decay_t<T>>, Types...>()> * = nullptr>
Variant(T &&value)
Variant &operator=(const Variant &other)
Variant &operator=(Variant &&other)
constexpr EnumType GetType() const
template<EnumType type>
const auto &Get() const
template<EnumType type>
auto &Get()

Public Members

Storage v

Friends

template<typename H>
H AbslHashValue(H h, const Variant &self)
template<typename Visitor, typename ...Variants>
constexpr auto oead::util::Visit(Visitor &&visitor, Variants&&... variants)

Helper function to visit a std::variant efficiently.

template<typename Variant, typename ...Ts>
constexpr auto oead::util::Match(Variant &&variant, Ts&&... lambdas)

Helper function to visit a std::variant efficiently. More convenient to use in most cases.