Nebula
Loading...
Searching...
No Matches
Util Namespace Reference

Detailed Description

A pinned array is an array which manages its own virtual memory.

@function TypePunning

Tuple helper functions and typedefs.

Function to implement type-punning, explanation here: http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Optimize-Options.html#Optimize-Options

Classes

struct  _smallvector
 
struct  _smallvector< TYPE, 0 >
 
struct  AllocatorLock
 
class  Array
 Nebula's dynamic array class. More...
 
class  ArrayAllocator
 The ArrayAllocator provides a variadic list of types which is to be contained in the allocator and fetching each value by providing the index into the list of types, which means the members are nameless. More...
 
class  ArrayAllocatorSafe
 The ArrayAllocatorSafe provides a thread safe variadic list of types which is to be contained in the allocator and fetching each value by providing the index into the list of types, which means the members are nameless. More...
 
class  ArrayQueue
 
class  ArrayStack
 Nebula's small vector optimized array. More...
 
class  BitField
 Implements large bit field. More...
 
class  Blob
 The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied, compared and hashed. More...
 
class  Bvh
 
class  Color
 For now just a wrapper around Math::vec4 for type safety. More...
 
class  CommandLineArgs
 A universal cmd line argument parser. More...
 
class  Crc
 Compute CRC checksums over a range of memory. More...
 
class  Delegate
 Nebula delegate class, allows to store a function, method or lambda call into a C++ object for later execution. More...
 
class  Delegate< RETTYPE(ARGTYPES...)>
 
class  Dictionary
 A collection of key/value pairs with quick value retrieval by key at roughly O(log n). More...
 
class  FixedArray
 Implements a fixed size one-dimensional array. More...
 
class  FixedPool
 Implements a fixed size pool, from which objects of a specific type can be allocated and freed for reuse. More...
 
class  FixedTable
 A fixed-size 2-dimensional array. More...
 
class  FourCC
 A four-character-code is a quasi-human-readable 32-bit-id. More...
 
struct  get_template_type
 
struct  get_template_type< C< I, T > & >
 Get inner type of two types. More...
 
struct  get_template_type< C< I, T > >
 Get inner type of two types. More...
 
struct  get_template_type< C< T > >
 Get inner type of two types. More...
 
struct  get_template_type< C< T, I > & >
 Get inner type of two types. More...
 
struct  get_template_type< C< T, I > >
 Get inner type of two types. More...
 
struct  get_template_type< const C< T > & >
 Get inner type of a constant ref outer type. More...
 
class  GlobalStringAtomTable
 Global string atom table. More...
 
class  HashTable
 Organizes key/value pairs by a hash code. More...
 
class  KeyValuePair
 Key/Value pair objects are used by most assiociative container classes, like Dictionary or HashTable. More...
 
class  List
 Implements a doubly linked list. More...
 
class  LocalStringAtomTable
 Implements a thread-local string atom table which is used as a cache to prevent excessive locking when creating string atoms. More...
 
class  PinnedArray
 
class  PriorityArray
 
class  QuadTree
 
class  Queue
 Nebula's queue class (a FIFO container). More...
 
class  RandomNumberTable
 A table-based random-number generator. More...
 
union  RandomUnion
 
class  RingBuffer
 A ring buffer stores up to a maximum number of elements in a circular fashion. More...
 
class  Round
 
class  RunLengthCodec
 A simple byte-based runlength encoder/decoder. More...
 
class  Set
 A collection of unique values with quick lookup. More...
 
class  SimpleTree
 A simple tree class which stores its nodes in Util::Arrays. More...
 
class  SparseTable
 A 2D sparse table where many entries may be redundant and support for multiple entries per cell. More...
 
class  Stack
 Nebula's stack class (a FILO container). More...
 
class  String
 Nebula's universal string class. More...
 
class  StringAtom
 A StringAtom. More...
 
class  StringAtomTableBase
 This implements the base class for thread-local and global string atom table classes. More...
 
class  StringBuffer
 Global string buffer for the StringAtom system. More...
 
class  StringMarshaler
 
class  TrivialArray
 Array class based on Util::Array for trivial and POD types that avoids any per element copying and constructor/destructor calls. More...
 
class  Variant
 An "any type" variable. More...
 

Typedefs

template<class TYPE , int STACK_SIZE>
using StackArray = Array<TYPE, STACK_SIZE>
 
template<typename... T>
using Tuple = std::tuple<T...>
 Wrap std::tuple.
 
template<typename A , typename B >
using Pair = std::pair<A, B>
 Wrap std::pair.
 
template<typename C >
using get_template_type_t = typename get_template_type<C>::type
 Helper typedef so that the above expression can be used like decltype.
 
template<int MEMBER, class ... TYPES>
using tuple_array_t = get_template_type_t<std::tuple_element_t<MEMBER, std::tuple<Util::Array<TYPES>...>>>
 Get type of contained element in Util::Array stored in std::tuple.
 

Functions

constexpr uint64 SetBit (uint64 mask, uint8 bit)
 
constexpr bool HasBit (uint64 mask, uint8 bit)
 
constexpr uint32 SetBit (uint32 mask, uint8 bit)
 
constexpr bool HasBit (uint32 mask, uint8 bit)
 
constexpr uint16 SetBit (uint16 mask, uint8 bit)
 
constexpr bool HasBit (uint16 mask, uint8 bit)
 
constexpr int64 SetBit (int64 mask, uint8 bit)
 
constexpr bool HasBit (int64 mask, uint8 bit)
 
constexpr int32 SetBit (int32 mask, uint8 bit)
 
constexpr bool HasBit (int32 mask, uint8 bit)
 
constexpr int16 SetBit (int16 mask, uint8 bit)
 
constexpr bool HasBit (int16 mask, uint8 bit)
 
constexpr uint32 CountBits (uint32 i)
 
template<typename T >
void HashCombine (uint32_t &s, const T &v)
 Combine hashes.
 
uint PopCnt (uint value)
 
uint64 PopCnt (uint64 value)
 
uint FirstOne (uint value)
 
uint FirstOne (uint64 value)
 
uint LastOne (uint value)
 
uint LastOne (uint64 value)
 
uint Lsb (uint value, byte bit)
 
uint BitmaskConvert (uint mask, const uint *table, const uint numEntries=0xFFFFFFFF)
 
 __ImplementInterfaceSingleton (Util::GlobalStringAtomTable)
 
 __ImplementSingleton (Util::LocalStringAtomTable)
 
uint FastRandom ()
 XorShift128 implementation.
 
float RandomFloat ()
 Thanks to Nic Werneck (https://xor0110.wordpress.com/2010/09/24/how-to-generate-floating-point-random-numbers-efficiently/)
 
float RandomFloatNTP ()
 Produces an xorshift128 psuedo based floating point random number in range -1..1 Note that this is not a truely random random number generator.
 
bool operator== (const String &a, const String &b)
 
bool operator== (const String &a, const char *cStr)
 
bool operator== (const char *cStr, const String &b)
 
bool operator== (const String &a, std::nullptr_t)
 
bool operator!= (const String &a, const String &b)
 
bool operator< (const String &a, const String &b)
 
bool operator> (const String &a, const String &b)
 
bool operator<= (const String &a, const String &b)
 
bool operator>= (const String &a, const String &b)
 
static String operator+ (const String &s0, const String &s1)
 
Util::StringAtom operator""_atm (const char *c)
 
template<typename... T>
constexpr Tuple< T... > MakeTuple (const T &... args)
 
template<int INDEX, typename... T>
constexpr const std::tuple_element_t< INDEX, std::tuple< T... > > & Get (const Tuple< T... > &tuple)
 
template<typename A , typename B >
constexpr Pair< A, B > MakePair (const A &a, const B &b)
 
template<int INDEX, typename A , typename B >
constexpr const std::tuple_element_t< INDEX, std::tuple< A, B > > & Get (const Pair< A, B > &pair)
 
template<class... Ts, std::size_t... Is>
void alloc_for_each_in_tuple (std::tuple< Ts... > &tuple, std::index_sequence< Is... >)
 Unpacks allocations for each member in a tuble.
 
template<class... Ts>
void alloc_for_each_in_tuple (std::tuple< Ts... > &tuple)
 Entry point for above expansion function.
 
template<class... Ts, std::size_t... Is>
void clear_for_each_in_tuple (std::tuple< Ts... > &tuple, std::index_sequence< Is... >)
 Unpacks allocations for each member in a tuple.
 
template<class... Ts>
void clear_for_each_in_tuple (std::tuple< Ts... > &tuple)
 Entry point for above expansion function.
 
template<class... Ts, std::size_t... Is>
void move_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t to, uint32_t from, std::index_sequence< Is... >)
 Entry point for moving an element between two indices.
 
template<class... Ts>
void move_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t to, uint32_t from)
 Entry point for moving an element between two indices.
 
template<class... Ts, std::size_t... Is>
void erase_index_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t i, std::index_sequence< Is... >)
 Entry point for erasing an element.
 
template<class... Ts>
void erase_index_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t i)
 Entry point for erasing an element.
 
template<class... Ts, std::size_t... Is>
void erase_index_swap_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t i, std::index_sequence< Is... >)
 Entry point for erasing an element by swapping with the last and reducing size.
 
template<class... Ts>
void erase_index_swap_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t i)
 Entry point for erasing an element by swapping with the last and reducing size.
 
template<class... Ts, std::size_t... Is>
void erase_range_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t start, uint32_t end, std::index_sequence< Is... >)
 
template<class... Ts>
void erase_range_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t start, uint32_t end)
 Entry point for erasing a range of elements the last and reducing size.
 
template<class... Ts, std::size_t... Is, class... TYPES>
void set_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t i, std::index_sequence< Is... >, TYPES const &... values)
 Entry point for setting values in each array at an index.
 
template<class... Ts, class... TYPES>
void set_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t i, TYPES const &... values)
 Entry point for setting values in each array at an index.
 
template<class... Ts, std::size_t... Is>
void reserve_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t size, std::index_sequence< Is... >)
 Entry point for reserving in each array.
 
template<class... Ts>
void reserve_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t size)
 Entry point for reserving in each array.
 
template<class... Ts, std::size_t... Is>
void set_size_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t size, std::index_sequence< Is... >)
 Entry point for reserving in each array.
 
template<class... Ts>
void set_size_for_each_in_tuple (std::tuple< Ts... > &tuple, uint32_t size)
 Entry point for reserving in each array.
 
template<typename A , typename B >
A & TypePunning (B &v)
 
template<typename A , typename B >
const A & TypePunning (const B &v)
 

Variables

auto Format = &String::Sprintf
 

Typedef Documentation

◆ get_template_type_t

template<typename C >
using Util.get_template_type_t = typename get_template_type<C>::type

Helper typedef so that the above expression can be used like decltype.

◆ Pair

template<typename A , typename B >
using Util.Pair = std::pair<A, B>

Wrap std::pair.

◆ StackArray

template<class TYPE , int STACK_SIZE>
using Util.StackArray = Array<TYPE, STACK_SIZE>

◆ Tuple

template<typename... T>
using Util.Tuple = std::tuple<T...>

Wrap std::tuple.

◆ tuple_array_t

template<int MEMBER, class ... TYPES>
using Util.tuple_array_t = get_template_type_t<std::tuple_element_t<MEMBER, std::tuple<Util::Array<TYPES>...>>>

Get type of contained element in Util::Array stored in std::tuple.

Function Documentation

◆ __ImplementInterfaceSingleton()

Util::__ImplementInterfaceSingleton ( Util::GlobalStringAtomTable )

◆ __ImplementSingleton()

Util::__ImplementSingleton ( Util::LocalStringAtomTable )

◆ alloc_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::alloc_for_each_in_tuple ( std::tuple< Ts... > & tuple)

Entry point for above expansion function.

◆ alloc_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::alloc_for_each_in_tuple ( std::tuple< Ts... > & tuple,
std::index_sequence< Is... >  )

Unpacks allocations for each member in a tuble.

◆ BitmaskConvert()

uint Util::BitmaskConvert ( uint mask,
const uint * table,
const uint numEntries = 0xFFFFFFFF )
inline

◆ clear_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::clear_for_each_in_tuple ( std::tuple< Ts... > & tuple)

Entry point for above expansion function.

◆ clear_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::clear_for_each_in_tuple ( std::tuple< Ts... > & tuple,
std::index_sequence< Is... >  )

Unpacks allocations for each member in a tuple.

◆ CountBits()

uint32 Util::CountBits ( uint32 i)
constexpr

◆ erase_index_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::erase_index_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t i )

Entry point for erasing an element.

Keeps sorting but is generally slow due to shifting all element at i + 1 one step left.

◆ erase_index_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::erase_index_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t i,
std::index_sequence< Is... >  )

Entry point for erasing an element.

Keeps sorting but is generally slow due to shifting all element at i + 1 one step left.

◆ erase_index_swap_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::erase_index_swap_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t i )

Entry point for erasing an element by swapping with the last and reducing size.

Note
Destroys sorting!

◆ erase_index_swap_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::erase_index_swap_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t i,
std::index_sequence< Is... >  )

Entry point for erasing an element by swapping with the last and reducing size.

Note
Destroys sorting!

◆ erase_range_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::erase_range_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t start,
uint32_t end )

Entry point for erasing a range of elements the last and reducing size.

◆ erase_range_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::erase_range_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t start,
uint32_t end,
std::index_sequence< Is... >  )

◆ FastRandom()

uint Util::FastRandom ( )

XorShift128 implementation.

Produces an xorshift128 pseudo random number.

◆ FirstOne() [1/2]

uint Util::FirstOne ( uint value)
inline

◆ FirstOne() [2/2]

uint Util::FirstOne ( uint64 value)
inline

◆ Get() [1/2]

template<int INDEX, typename A , typename B >
const std::tuple_element_t< INDEX, std::tuple< A, B > > & Util::Get ( const Pair< A, B > & pair)
constexpr

◆ Get() [2/2]

template<int INDEX, typename... T>
const std::tuple_element_t< INDEX, std::tuple< T... > > & Util::Get ( const Tuple< T... > & tuple)
constexpr

◆ HasBit() [1/6]

bool Util::HasBit ( int16 mask,
uint8 bit )
constexpr

◆ HasBit() [2/6]

bool Util::HasBit ( int32 mask,
uint8 bit )
constexpr

◆ HasBit() [3/6]

bool Util::HasBit ( int64 mask,
uint8 bit )
constexpr

◆ HasBit() [4/6]

bool Util::HasBit ( uint16 mask,
uint8 bit )
constexpr

◆ HasBit() [5/6]

bool Util::HasBit ( uint32 mask,
uint8 bit )
constexpr

◆ HasBit() [6/6]

bool Util::HasBit ( uint64 mask,
uint8 bit )
constexpr

◆ HashCombine()

template<typename T >
void Util::HashCombine ( uint32_t & s,
const T & v )
inline

Combine hashes.

◆ LastOne() [1/2]

uint Util::LastOne ( uint value)
inline

◆ LastOne() [2/2]

uint Util::LastOne ( uint64 value)
inline

◆ Lsb()

uint Util::Lsb ( uint value,
byte bit )
inline

◆ MakePair()

template<typename A , typename B >
Pair< A, B > Util::MakePair ( const A & a,
const B & b )
constexpr

◆ MakeTuple()

template<typename... T>
Tuple< T... > Util::MakeTuple ( const T &... args)
constexpr

◆ move_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::move_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t to,
uint32_t from )

Entry point for moving an element between two indices.

◆ move_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::move_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t to,
uint32_t from,
std::index_sequence< Is... >  )

Entry point for moving an element between two indices.

◆ operator!=()

bool Util::operator!= ( const String & a,
const String & b )

◆ operator""_atm()

Util::StringAtom Util::operator""_atm ( const char * c)

◆ operator+()

static String Util::operator+ ( const String & s0,
const String & s1 )
inlinestatic

◆ operator<()

bool Util::operator< ( const String & a,
const String & b )

◆ operator<=()

bool Util::operator<= ( const String & a,
const String & b )

◆ operator==() [1/4]

bool Util::operator== ( const char * cStr,
const String & b )

◆ operator==() [2/4]

bool Util::operator== ( const String & a,
const char * cStr )

◆ operator==() [3/4]

bool Util::operator== ( const String & a,
const String & b )

◆ operator==() [4/4]

bool Util::operator== ( const String & a,
std::nullptr_t  )

◆ operator>()

bool Util::operator> ( const String & a,
const String & b )

◆ operator>=()

bool Util::operator>= ( const String & a,
const String & b )

◆ PopCnt() [1/2]

uint Util::PopCnt ( uint value)
inline

◆ PopCnt() [2/2]

uint64 Util::PopCnt ( uint64 value)
inline

◆ RandomFloat()

float Util::RandomFloat ( )

Thanks to Nic Werneck (https://xor0110.wordpress.com/2010/09/24/how-to-generate-floating-point-random-numbers-efficiently/)

Produces an xorshift128 psuedo based floating point random number in range 0..1 Note that this is not a truely random random number generator.

◆ RandomFloatNTP()

float Util::RandomFloatNTP ( )

Produces an xorshift128 psuedo based floating point random number in range -1..1 Note that this is not a truely random random number generator.

◆ reserve_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::reserve_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t size )

Entry point for reserving in each array.

◆ reserve_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::reserve_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t size,
std::index_sequence< Is... >  )

Entry point for reserving in each array.

◆ set_for_each_in_tuple() [1/2]

template<class... Ts, std::size_t... Is, class... TYPES>
void Util::set_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t i,
std::index_sequence< Is... > ,
TYPES const &... values )

Entry point for setting values in each array at an index.

◆ set_for_each_in_tuple() [2/2]

template<class... Ts, class... TYPES>
void Util::set_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t i,
TYPES const &... values )

Entry point for setting values in each array at an index.

◆ set_size_for_each_in_tuple() [1/2]

template<class... Ts>
void Util::set_size_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t size )

Entry point for reserving in each array.

◆ set_size_for_each_in_tuple() [2/2]

template<class... Ts, std::size_t... Is>
void Util::set_size_for_each_in_tuple ( std::tuple< Ts... > & tuple,
uint32_t size,
std::index_sequence< Is... >  )

Entry point for reserving in each array.

◆ SetBit() [1/6]

int16 Util::SetBit ( int16 mask,
uint8 bit )
constexpr

◆ SetBit() [2/6]

int32 Util::SetBit ( int32 mask,
uint8 bit )
constexpr

◆ SetBit() [3/6]

int64 Util::SetBit ( int64 mask,
uint8 bit )
constexpr

◆ SetBit() [4/6]

uint16 Util::SetBit ( uint16 mask,
uint8 bit )
constexpr

◆ SetBit() [5/6]

uint32 Util::SetBit ( uint32 mask,
uint8 bit )
constexpr

◆ SetBit() [6/6]

uint64 Util::SetBit ( uint64 mask,
uint8 bit )
constexpr

◆ TypePunning() [1/2]

template<typename A , typename B >
A & Util::TypePunning ( B & v)

◆ TypePunning() [2/2]

template<typename A , typename B >
const A & Util::TypePunning ( const B & v)

Variable Documentation

◆ Format

auto Util.Format = &String::Sprintf
inline