Banuba SDK
Loading...
Searching...
No Matches
Utils

Classes

class  bnb::interfaces::egl_context
 
class  bnb::interfaces::image_releaser
 Only android interface. More...
 
class  bnb::interfaces::log_record_callback
 
struct  bnb::subscription_request_t
 
class  bnb::base_event_iface
 
class  bnb::base_event< Event, MaxElements >
 
class  bnb::time_stamped_event< Event >
 
class  bnb::simple_event< T, Count >
 
class  bnb::empty_event< Count >
 
class  bnb::effect_event
 
class  bnb::identified_class< IdType, T >
 
class  bnb::spin_lock
 
class  bnb::spin_mutex
 
struct  bnb::static_pool_allocator< T, MAX_ELEMENTS >
 Doesn't support N allocs (std::vector) More...
 
struct  bnb::static_pool_allocator< T, MAX_ELEMENTS >::rebind< U >
 
class  bnb::static_pool_allocator_fallback< T, MAX_ELEMENTS, Alloc_fallback >
 
class  bnb::singleton< T >
 Base class for all scoped singletons. More...
 

Macros

#define BNB_EXPORT   __attribute__((__visibility__("default")))
 
#define BNB_OS_ANDROID   0
 
#define BNB_OS_IOS   0
 
#define BNB_OS_LINUX   0
 
#define BNB_OS_MACOS   0
 
#define BNB_OS_EMSCRIPTEN   0
 
#define BNB_OS_UNIX   0
 
#define BNB_OS_WINDOWS   0
 
#define BNB_OS_WINDOWS_ARM64   0
 
#define BNB_APPLE   0
 
#define BNB_ASSERT(expr)
 
#define BNB_ASSERT_MSG(expr, msg)
 
#define BNB_CHECK(expr)
 
#define BNB_CHECK_MSG(expr, msg)
 

Typedefs

using bnb::event_id_t = size_t
 
using bnb::handler_id_t = size_t
 
using bnb::base_event_ptr = std::shared_ptr<const base_event_iface>
 
using bnb::base_event_deleter = std::function<void(const bnb::base_event_iface*)>
 
template<typename T >
using bnb::event_uptr = std::unique_ptr<T, base_event_deleter>
 
using bnb::base_event_uptr = event_uptr<const base_event_iface>
 
typedef char char8_t
 

Functions

template<typename T , typename... Args>
std::unique_ptr< T, base_event_deleter > bnb::make_unique_event (Args &&... args)
 
template<typename T , typename Alloc , typename D , typename... Args>
std::unique_ptr< T, D > bnb::allocate_unique (Alloc alloc, Args &&... args)
 
template<typename Class >
size_t bnb::class_unique_id ()
 
T * bnb::static_pool_allocator< T, MAX_ELEMENTS >::allocate (std::size_t n)
 
T * bnb::static_pool_allocator< T, MAX_ELEMENTS >::allocate (std::size_t n, const std::nothrow_t &) noexcept
 
void bnb::static_pool_allocator< T, MAX_ELEMENTS >::deallocate (T *p, std::size_t n)
 
bool bnb::static_pool_allocator< T, MAX_ELEMENTS >::is_mine (T *p)
 

Detailed Description

Macro Definition Documentation

◆ BNB_APPLE

#define BNB_APPLE   0

Definition at line 126 of file defs.hpp.

◆ BNB_ASSERT

#define BNB_ASSERT ( expr)
Value:
assert(expr)

Definition at line 11 of file assert.hpp.

◆ BNB_ASSERT_MSG

#define BNB_ASSERT_MSG ( expr,
msg )
Value:
assert((expr) && (msg))

Definition at line 12 of file assert.hpp.

◆ BNB_CHECK

#define BNB_CHECK ( expr)
Value:
if (!(expr)) { \
BNB_THROW(std::logic_error, #expr); \
}

Definition at line 14 of file assert.hpp.

14#define BNB_CHECK(expr) \
15 if (!(expr)) { \
16 BNB_THROW(std::logic_error, #expr); \
17 }

◆ BNB_CHECK_MSG

#define BNB_CHECK_MSG ( expr,
msg )
Value:
if (!(expr)) { \
BNB_THROW(std::logic_error, std::string(msg) + ": " + #expr); \
}

Definition at line 19 of file assert.hpp.

19#define BNB_CHECK_MSG(expr, msg) \
20 if (!(expr)) { \
21 BNB_THROW(std::logic_error, std::string(msg) + ": " + #expr); \
22 }

◆ BNB_EXPORT

#define BNB_EXPORT   __attribute__((__visibility__("default")))

Definition at line 22 of file defs.hpp.

◆ BNB_OS_ANDROID

#define BNB_OS_ANDROID   0

Definition at line 27 of file defs.hpp.

◆ BNB_OS_EMSCRIPTEN

#define BNB_OS_EMSCRIPTEN   0

Definition at line 83 of file defs.hpp.

◆ BNB_OS_IOS

#define BNB_OS_IOS   0

Definition at line 41 of file defs.hpp.

◆ BNB_OS_LINUX

#define BNB_OS_LINUX   0

Definition at line 55 of file defs.hpp.

◆ BNB_OS_MACOS

#define BNB_OS_MACOS   0

Definition at line 69 of file defs.hpp.

◆ BNB_OS_UNIX

#define BNB_OS_UNIX   0

Definition at line 97 of file defs.hpp.

◆ BNB_OS_WINDOWS

#define BNB_OS_WINDOWS   0

Definition at line 110 of file defs.hpp.

◆ BNB_OS_WINDOWS_ARM64

#define BNB_OS_WINDOWS_ARM64   0

Definition at line 111 of file defs.hpp.

Typedef Documentation

◆ base_event_deleter

using bnb::base_event_deleter = std::function<void(const bnb::base_event_iface*)>

Definition at line 111 of file event.hpp.

◆ base_event_ptr

using bnb::base_event_ptr = std::shared_ptr<const base_event_iface>

Definition at line 110 of file event.hpp.

◆ base_event_uptr

using bnb::base_event_uptr = event_uptr<const base_event_iface>

Definition at line 116 of file event.hpp.

◆ char8_t

typedef char char8_t

Definition at line 144 of file defs.hpp.

◆ event_id_t

using bnb::event_id_t = size_t

Definition at line 22 of file event.hpp.

◆ event_uptr

template<typename T >
using bnb::event_uptr = std::unique_ptr<T, base_event_deleter>

Definition at line 114 of file event.hpp.

◆ handler_id_t

using bnb::handler_id_t = size_t

Definition at line 23 of file event.hpp.

Function Documentation

◆ allocate() [1/2]

template<typename T , size_t MAX_ELEMENTS>
T * bnb::static_pool_allocator< T, MAX_ELEMENTS >::allocate ( std::size_t n)
inline

Definition at line 103 of file static_pool_allocator.hpp.

104 {
105 spin_lock l(static_data.pool_lock);
106
107 if (!_have_free() || n > 1)
108 throw std::bad_alloc();
109
110 return _allocate();
111 }

◆ allocate() [2/2]

template<typename T , size_t MAX_ELEMENTS>
T * bnb::static_pool_allocator< T, MAX_ELEMENTS >::allocate ( std::size_t n,
const std::nothrow_t &  )
inlinenoexcept

Definition at line 114 of file static_pool_allocator.hpp.

115 {
116 spin_lock l(static_data.pool_lock);
117
118 if (!_have_free() || n > 1)
119 return nullptr;
120
121 return _allocate();
122 }

◆ allocate_unique()

template<typename T , typename Alloc , typename D , typename... Args>
std::unique_ptr< T, D > bnb::allocate_unique ( Alloc alloc,
Args &&... args )
inline

Definition at line 13 of file allocate_unique.hpp.

14 {
15 using traits = std::allocator_traits<Alloc>;
16 auto ptr = traits::allocate(alloc, 1);
17 try {
18 traits::construct(alloc, ptr, std::forward<Args>(args)...);
19 } catch (...) {
20 traits::deallocate(alloc, ptr, 1);
21 throw;
22 }
23
24
25 return std::unique_ptr<T, D>(
26 ptr,
27 [alloc = std::move(alloc)](auto p) mutable {
28 auto ptr = const_cast<T*>(reinterpret_cast<const T*>(p));
29 traits::destroy(alloc, ptr);
30 traits::deallocate(alloc, ptr, 1);
31 }
32 );
33 }

◆ class_unique_id()

template<typename Class >
size_t bnb::class_unique_id ( )

Definition at line 11 of file class_unique_id.hpp.

12 {
13 static const char registrar_slot = 0;
14 return reinterpret_cast<size_t>(&registrar_slot);
15 }

◆ deallocate()

template<typename T , size_t MAX_ELEMENTS>
void bnb::static_pool_allocator< T, MAX_ELEMENTS >::deallocate ( T * p,
std::size_t n )
inline

Definition at line 136 of file static_pool_allocator.hpp.

137 {
138 (void) n;
139 spin_lock l(static_data.pool_lock);
140
141 const size_t slot = (reinterpret_cast<unsigned char*>(p) - reinterpret_cast<unsigned char*>(static_data.pool)) / sizeof(T);
142 *static_data.free_slots_end = slot;
143 ++static_data.free_slots_end;
144 }

◆ is_mine()

template<typename T , size_t MAX_ELEMENTS>
bool bnb::static_pool_allocator< T, MAX_ELEMENTS >::is_mine ( T * p)
inline

Definition at line 155 of file static_pool_allocator.hpp.

156 {
157 if (reinterpret_cast<char*>(p) < reinterpret_cast<char*>(static_data.pool) || reinterpret_cast<char*>(p) > reinterpret_cast<char*>(static_data.pool) + sizeof(static_data.pool))
158 return false;
159 return true;
160 }

◆ make_unique_event()

template<typename T , typename... Args>
std::unique_ptr< T, base_event_deleter > bnb::make_unique_event ( Args &&... args)
inline

Definition at line 120 of file event.hpp.

121 {
122 return allocate_unique<T, typename T::allocator, base_event_deleter, Args&&...>(
123 typename T::allocator(),
124 std::forward<Args>(args)...
125 );
126 }

◆ static_data_t()

template<typename T , size_t MAX_ELEMENTS>
bnb::static_pool_allocator< T, MAX_ELEMENTS >::static_data_t::static_data_t ( )

Definition at line 92 of file static_pool_allocator.hpp.

93 : pool(bnb::static_pool<T, MAX_ELEMENTS>)
94 {
95 int i = 0;
96 std::generate(free_slots.begin(), free_slots.end(), [i]() mutable { return i++; });
97 free_slots_end = free_slots.end();
98 pool_lock.clear();
99 }