Sunshine latest
Self-hosted game stream host for Moonlight.
utility.h File Reference

Declarations for utility functions. More...

#include <algorithm>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include <type_traits>
#include <variant>
#include <vector>
Include dependency graph for utility.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  util::__either< false, X, Y >
 
struct  util::__either< true, X, Y >
 
struct  util::__false_v< T, std::enable_if_t< instantiation_of_v< std::optional, T > > >
 
struct  util::__false_v< T, std::enable_if_t< is_pointer_v< T > > >
 
struct  util::__false_v< T, std::enable_if_t< std::is_same_v< T, bool > > >
 
struct  util::__instantiation_of< X, Y >
 
struct  util::__instantiation_of< X, X< Y... > >
 
struct  argument_type< T(U)>
 
class  util::buffer_t< T >
 
struct  util::Destroy< T, ReturnType, function >
 
class  util::Either< X, Y >
 
struct  util::endian::endian_helper< T, S >
 
struct  util::endian::endian_helper< T, std::enable_if_t< instantiation_of_v< std::optional, T > > >
 
struct  util::endian::endian_helper< T, std::enable_if_t<!(instantiation_of_v< std::optional, T >)> >
 
struct  util::endian::endianness< T >
 
class  util::FailGuard< T >
 
struct  util::Function< ReturnType, Args >
 
class  util::hash< T >
 
class  util::Hex< T >
 
struct  util::overloaded< Ts >
 
struct  util::point_t
 
class  util::uniq_ptr< T, D >
 
class  util::wrap_ptr< T >
 

Macros

#define KITTY_DECL_CONSTR(x)
 
#define KITTY_DEFAULT_CONSTR(x)
 
#define KITTY_DEFAULT_CONSTR_MOVE(x)
 
#define KITTY_DEFAULT_CONSTR_MOVE_THROW(x)
 
#define KITTY_USING_MOVE_T(move_t, t, init_val, z)
 
#define KITTY_WHILE_LOOP(x, y, z)
 
#define TUPLE_2D(a, b, expr)
 
#define TUPLE_2D_REF(a, b, expr)
 
#define TUPLE_3D(a, b, c, expr)
 
#define TUPLE_3D_REF(a, b, c, expr)
 
#define TUPLE_EL(a, b, expr)
 
#define TUPLE_EL_REF(a, b, expr)    auto &a = std::get<b>(expr)
 

Typedefs

template<class T >
using util::c_ptr = safe_ptr<T, c_free<T>>
 
template<class T , void(**)(T *) function>
using util::dyn_safe_ptr = safe_ptr<T, dynamic<T, void, function>>
 
template<class T , class ReturnType , ReturnType(**)(T *) function>
using util::dyn_safe_ptr_v2 = safe_ptr<T, dynamic<T, ReturnType, function>>
 
template<bool V, class X , class Y >
using util::either_t = typename __either<V, X, Y>::type
 
template<class T >
using util::optional_t
 
template<class T , typename Function< void, T * >::type function>
using util::safe_ptr = uniq_ptr<T, Destroy<T *, void, function>>
 
template<class T , class ReturnType , typename Function< ReturnType, T * >::type function>
using util::safe_ptr_v2 = uniq_ptr<T, Destroy<T *, ReturnType, function>>
 
template<class P >
using util::shared_t = std::shared_ptr<typename P::element_type>
 

Functions

template<class T >
void util::append_struct (std::vector< uint8_t > &buf, const T &_struct)
 
template<class T >
auto util::endian::big (T x)
 
template<class T >
void util::c_free (T *p)
 
template<class T , class ReturnType , ReturnType(**)(T *) function>
void util::dynamic (T *p)
 
template<class T >
util::either (std::optional< T > &&l, T &&r)
 
template<class T >
auto util::enm (const T &val) -> const std::underlying_type_t< T > &
 
template<class T >
auto util::enm (T &val) -> std::underlying_type_t< T > &
 
template<class T >
auto util::fail_guard (T &&f)
 
std::int64_t util::from_chars (const char *begin, const char *end)
 
template<class T >
util::from_hex (const std::string_view &hex, bool rev=false)
 
std::string util::from_hex_vec (const std::string &hex, bool rev=false)
 
std::int64_t util::from_view (const std::string_view &number)
 
template<class T >
Hex< T > util::hex (const T &elem, bool rev=false)
 
template<class C >
std::string util::hex_vec (C &&c, bool rev=false)
 
template<class It >
std::string util::hex_vec (It begin, It end, bool rev=false)
 
template<class T >
auto util::endian::little (T x)
 
template<typename T >
std::string util::log_hex (const T &value)
 
template<class P , class T >
shared_t< P > util::make_shared (T *pointer)
 
template<class T1 , class D1 , class T2 , class D2 >
bool util::operator!= (const std::unique_ptr< T1, D1 > &x, const uniq_ptr< T2, D2 > &y)
 
template<class T , class D >
bool util::operator!= (const uniq_ptr< T, D > &x, std::nullptr_t)
 
template<class T1 , class D1 , class T2 , class D2 >
bool util::operator!= (const uniq_ptr< T1, D1 > &x, const std::unique_ptr< T1, D1 > &y)
 
template<class T1 , class D1 , class T2 , class D2 >
bool util::operator!= (const uniq_ptr< T1, D1 > &x, const uniq_ptr< T2, D2 > &y)
 
template<class T , class D >
bool util::operator!= (std::nullptr_t, const uniq_ptr< T, D > &y)
 
template<class T1 , class D1 , class T2 , class D2 >
bool util::operator== (const std::unique_ptr< T1, D1 > &x, const uniq_ptr< T2, D2 > &y)
 
template<class T , class D >
bool util::operator== (const uniq_ptr< T, D > &x, std::nullptr_t)
 
template<class T1 , class D1 , class T2 , class D2 >
bool util::operator== (const uniq_ptr< T1, D1 > &x, const std::unique_ptr< T1, D1 > &y)
 
template<class T1 , class D1 , class T2 , class D2 >
bool util::operator== (const uniq_ptr< T1, D1 > &x, const uniq_ptr< T2, D2 > &y)
 
template<class T , class D >
bool util::operator== (std::nullptr_t, const uniq_ptr< T, D > &y)
 
template<class... Ts>
 util::overloaded (Ts...) -> overloaded< Ts... >
 
template<class T >
std::string_view util::view (const T &data)
 
template<class It >
std::string_view util::view (It begin, It end)
 

Variables

template<class T >
constexpr bool util::is_pointer_v
 

Detailed Description

Declarations for utility functions.

Macro Definition Documentation

◆ KITTY_DECL_CONSTR

#define KITTY_DECL_CONSTR ( x)
Value:
x(x &&) noexcept = default; \
x &operator=(x &&) noexcept = default; \
x();

◆ KITTY_DEFAULT_CONSTR

#define KITTY_DEFAULT_CONSTR ( x)
Value:
KITTY_DEFAULT_CONSTR_MOVE(x) \
x(const x &) noexcept = default; \
x &operator=(const x &) = default;

◆ KITTY_DEFAULT_CONSTR_MOVE

#define KITTY_DEFAULT_CONSTR_MOVE ( x)
Value:
x(x &&) noexcept = default; \
x &operator=(x &&) noexcept = default;

◆ KITTY_DEFAULT_CONSTR_MOVE_THROW

#define KITTY_DEFAULT_CONSTR_MOVE_THROW ( x)
Value:
x(x &&) = default; \
x &operator=(x &&) = default; \
x() = default;

◆ KITTY_WHILE_LOOP

#define KITTY_WHILE_LOOP ( x,
y,
z )
Value:
{ \
x; \
while (y) z \
}

◆ TUPLE_2D

#define TUPLE_2D ( a,
b,
expr )
Value:
decltype(expr) a##_##b = expr; \
auto &a = std::get<0>(a##_##b); \
auto &b = std::get<1>(a##_##b)

◆ TUPLE_2D_REF

#define TUPLE_2D_REF ( a,
b,
expr )
Value:
auto &a##_##b = expr; \
auto &a = std::get<0>(a##_##b); \
auto &b = std::get<1>(a##_##b)

◆ TUPLE_3D

#define TUPLE_3D ( a,
b,
c,
expr )
Value:
decltype(expr) a##_##b##_##c = expr; \
auto &a = std::get<0>(a##_##b##_##c); \
auto &b = std::get<1>(a##_##b##_##c); \
auto &c = std::get<2>(a##_##b##_##c)

◆ TUPLE_3D_REF

#define TUPLE_3D_REF ( a,
b,
c,
expr )
Value:
auto &a##_##b##_##c = expr; \
auto &a = std::get<0>(a##_##b##_##c); \
auto &b = std::get<1>(a##_##b##_##c); \
auto &c = std::get<2>(a##_##b##_##c)

◆ TUPLE_EL

#define TUPLE_EL ( a,
b,
expr )
Value:
decltype(expr) a##_ = expr; \
auto &a = std::get<b>(a##_)

Typedef Documentation

◆ optional_t

template<class T >
using util::optional_t
Initial value:
either_t<
(std::is_same_v<T, bool> || is_pointer_v<T>),
T,
std::optional<T>>

Variable Documentation

◆ is_pointer_v

template<class T >
constexpr bool util::is_pointer_v
constexpr
Initial value:
=
instantiation_of_v<std::unique_ptr, T> ||
instantiation_of_v<std::shared_ptr, T> ||
instantiation_of_v<uniq_ptr, T> ||
std::is_pointer_v<T>