Foundation
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
Foundation::Core Namespace Reference

Allocators, Data Structures and introspection implementations. More...

Classes

class  Allocator
 General Purpose Allocator (GPA) interface. More...
 
struct  Arena
 A memory arena allocated from an Allocator. More...
 
class  HeapAllocator
 General purpose heap allocator. More...
 
class  Pool
 Unbounded object pool with O(1) value mapping. More...
 
struct  ScopedArena
 RAII wrapper for an arena allocated from an Allocator. More...
 
class  Span
 std::span with relaxed constructors for pointer-aliasing types and common containers. More...
 
class  StackAllocator
 Implements an atomic stack-based bump allocator. More...
 
struct  StackArena
 A fixed-size stack memory arena. More...
 
class  StlAllocator
 std::allocator adaptor for Foundation::Core::Allocator More...
 
struct  StlDeleter
 Custom deleter for Foundation::Core::UniquePtr and Foundation::Core::SharedPtr that uses a Foundation::Core::Allocator to deallocate memory. More...
 

Typedefs

using size_type = std::size_t
 
using pointer = void *
 
template<typename T >
using UniquePtr = std::unique_ptr< T, StlDeleter< T > >
 std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
 
template<typename T >
using SharedPtr = std::shared_ptr< T >
 std::shared_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
 
template<typename T >
using Optional = std::optional< T >
 Alias for std::optional
 
template<typename First , typename Second >
using Pair = std::pair< First, Second >
 Alias for std::pair
 
template<typename ... Args>
using Tuple = std::tuple< Args... >
 Alias for std::tuple
 
template<typename T , size_t Size>
using Array = std::array< T, Size >
 Alias for std::array
 
template<size_t Size>
using Bitset = std::bitset< Size >
 Alias for std::bitset
 
using StringView = std::basic_string_view< char >
 Alias for std::basic_string_view<char>
 
using String = std::basic_string< char >
 Alias for std::basic_string<char>, without an explicit allocator constructor.
 
using StringAlloc = std::basic_string< char, std::char_traits< char >, StlAllocator< char > >
 std::basic_string<char> with explicit Foundation::Core::StlAllocator constructor
 
template<typename T >
using Vector = std::vector< T, StlAllocator< T > >
 std::vector with explicit Foundation::Core::StlAllocator constructor
 
template<typename T , typename Predicate = std::less<T>>
using Set = std::set< T, Predicate, StlAllocator< T > >
 std::set with explicit Foundation::Core::StlAllocator constructor
 
template<typename K , typename V , typename Predicate = std::less<K>>
using Map = std::map< K, V, Predicate, StlAllocator< Pair< const K, V > > >
 std::map with explicit Foundation::Core::StlAllocator constructor
 
template<typename T >
using Deque = std::deque< T, StlAllocator< T > >
 std::deque with explicit Foundation::Core::StlAllocator constructor
 
template<typename T >
using List = std::list< T, StlAllocator< T > >
 std::list with explicit Foundation::Core::StlAllocator constructor
 
template<typename T , typename Container = Deque<T>>
using Queue = std::queue< T, Container >
 std::queue with explicit Foundation::Core::StlAllocator constructor
 
template<typename T , typename Predicate = std::less<T>, typename Container = Vector<T>>
using PriorityQueue = std::priority_queue< T, Container, Predicate >
 std::priority_queue with explicit Foundation::Core::StlAllocator constructor
 
using DefaultAllocator = HeapAllocator
 Alias for HeapAllocator with tracking enabled.
 

Functions

uintptr_t AlignUp (uintptr_t value, uintptr_t alignment)
 
uintptr_t AlignDown (uintptr_t value, uintptr_t alignment)
 
template<typename Base , typename Derived , typename ... Args>
BaseConstructBase (Allocator *resource, Args &&...args)
 Placement new helper for constructing an object of type Derived (which can be a subclass of Base) using a Foundation::Core::Allocator.
 
template<typename T , typename ... Args>
TConstruct (Allocator *resource, Args &&...args)
 Convenience placement new with object of type T using a Foundation::Core::Allocator.
 
template<typename T >
void Destruct (Allocator *resource, T *obj)
 Convenience destructor for objects allocated with Construct or ConstructBase.
 
template<typename Base , typename Derived , typename ... Args>
UniquePtr< BaseConstructUniqueBase (Allocator *resource, Args &&...args)
 Helper function for constructing a pinned resource with a Foundation::Core::Allocator.
 
template<typename T , typename ... Args>
UniquePtr< TConstructUnique (Allocator *resource, Args &&...args)
 Convenience wrapper for calling ConstructUniqueBase when Base and Derived are the same type.
 
template<typename Base , typename Derived , typename ... Args>
SharedPtr< BaseConstructSharedBase (Allocator *resource, Args &&...args)
 Helper function for constructing a ref-counted resource with a Foundation::Core::Allocator.
 
template<typename T , typename ... Args>
SharedPtr< TConstructShared (Allocator *resource, Args &&...args)
 Convenience wrapper for calling ConstructSharedBase when Base and Derived are the same type.
 
template<typename T , typename ... Args>
Span< TConstructSpan (Allocator *resource, size_t size, Args &&...args)
 Convenience function for constructing a Span with memory allocated from a Foundation::Core::Allocator. Possibly constructs objects in-place if they are not trivially constructible (e.g. non-PODs)
 
template<typename T >
void DestructSpan (Allocator *resource, Span< T > span)
 Convenience function for destructing a Span allocated with ConstructSpan. Calls destructors in-place if the type is not trivially destructible (e.g. non-PODs)
 
std::shared_ptr< spdlog::sinks::dist_sink_mt > getLoggingSink ()
 
std::shared_ptr< spdlog::sinks::ringbuffer_sink_mt > getBacktraceSink ()
 
spdlog::logger * getLogger (const char *name)
 

Variables

constexpr size_t kDefaultStackArenaSize = 12 * 1024
 
static bool g_Initialized = false
 
static std::shared_ptr< spdlog::sinks::dist_sink_mt > g_LoggingSink = nullptr
 
static std::shared_ptr< spdlog::sinks::ringbuffer_sink_mt > g_BacktraceSink = nullptr
 
std::recursive_mutex g_LoggingSinkMutex
 
std::recursive_mutex g_LoggerMutex
 
const size_t kMaxBacktraceLogMessages = 1000
 

Detailed Description

Allocators, Data Structures and introspection implementations.

Typedef Documentation

◆ Array

template<typename T , size_t Size>
using Foundation::Core::Array = typedef std::array<T, Size>

Alias for std::array

◆ Bitset

template<size_t Size>
using Foundation::Core::Bitset = typedef std::bitset<Size>

Alias for std::bitset

◆ DefaultAllocator

Alias for HeapAllocator with tracking enabled.

◆ Deque

std::deque with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ List

std::list with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ Map

std::map with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ Optional

template<typename T >
using Foundation::Core::Optional = typedef std::optional<T>

Alias for std::optional

◆ Pair

Alias for std::pair

◆ pointer

◆ PriorityQueue

template<typename T , typename Predicate = std::less<T>, typename Container = Vector<T>>
using Foundation::Core::PriorityQueue = typedef std::priority_queue<T, Container, Predicate>

std::priority_queue with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ Queue

template<typename T , typename Container = Deque<T>>
using Foundation::Core::Queue = typedef std::queue<T, Container>

std::queue with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ Set

template<typename T , typename Predicate = std::less<T>>
using Foundation::Core::Set = typedef std::set<T, Predicate, StlAllocator<T> >

std::set with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ SharedPtr

template<typename T >
using Foundation::Core::SharedPtr = typedef std::shared_ptr<T>

std::shared_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.

◆ size_type

◆ String

Alias for std::basic_string<char>, without an explicit allocator constructor.

Allocation of strings on heap is done with the default global allocator.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ StringAlloc

using Foundation::Core::StringAlloc = typedef std::basic_string<char, std::char_traits<char>, StlAllocator<char> >

std::basic_string<char> with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

◆ StringView

using Foundation::Core::StringView = typedef std::basic_string_view<char>

Alias for std::basic_string_view<char>

◆ Tuple

template<typename ... Args>
using Foundation::Core::Tuple = typedef std::tuple<Args...>

Alias for std::tuple

◆ UniquePtr

template<typename T >
using Foundation::Core::UniquePtr = typedef std::unique_ptr<T, StlDeleter<T> >

std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.

Construction without a Foundation::Core::Allocator pointer is disallowed, and will result in a compile-time error.

◆ Vector

std::vector with explicit Foundation::Core::StlAllocator constructor

Construction without an allocator is disallowed, and will result in a compile-time error.

Note
Thread-safety is not guaranteed as with other STL containers.

Function Documentation

◆ AlignDown()

uintptr_t Foundation::Core::AlignDown ( uintptr_t  value,
uintptr_t  alignment 
)
inline

◆ AlignUp()

uintptr_t Foundation::Core::AlignUp ( uintptr_t  value,
uintptr_t  alignment 
)
inline

◆ Construct()

template<typename T , typename ... Args>
T * Foundation::Core::Construct ( Allocator resource,
Args &&...  args 
)

Convenience placement new with object of type T using a Foundation::Core::Allocator.

◆ ConstructBase()

template<typename Base , typename Derived , typename ... Args>
Base * Foundation::Core::ConstructBase ( Allocator resource,
Args &&...  args 
)

Placement new helper for constructing an object of type Derived (which can be a subclass of Base) using a Foundation::Core::Allocator.

◆ ConstructShared()

template<typename T , typename ... Args>
SharedPtr< T > Foundation::Core::ConstructShared ( Allocator resource,
Args &&...  args 
)

Convenience wrapper for calling ConstructSharedBase when Base and Derived are the same type.

Template Parameters
Tis the class type to be templated on.

◆ ConstructSharedBase()

template<typename Base , typename Derived , typename ... Args>
SharedPtr< Base > Foundation::Core::ConstructSharedBase ( Allocator resource,
Args &&...  args 
)

Helper function for constructing a ref-counted resource with a Foundation::Core::Allocator.

Template Parameters
Baseis the base class type be templated on.
Derivedcan be a subclass of Base, with destruction handled correctly.

◆ ConstructSpan()

template<typename T , typename ... Args>
Span< T > Foundation::Core::ConstructSpan ( Allocator resource,
size_t  size,
Args &&...  args 
)

Convenience function for constructing a Span with memory allocated from a Foundation::Core::Allocator. Possibly constructs objects in-place if they are not trivially constructible (e.g. non-PODs)

Note
Data is not guaranteed to be zero-initialized. Pass in constructor args if needed.
Constructor args are only used if T is not trivially constructible, or if more than 0 args are passed in.

◆ ConstructUnique()

template<typename T , typename ... Args>
UniquePtr< T > Foundation::Core::ConstructUnique ( Allocator resource,
Args &&...  args 
)

Convenience wrapper for calling ConstructUniqueBase when Base and Derived are the same type.

Template Parameters
Tis the class type to be templated on.

◆ ConstructUniqueBase()

template<typename Base , typename Derived , typename ... Args>
UniquePtr< Base > Foundation::Core::ConstructUniqueBase ( Allocator resource,
Args &&...  args 
)

Helper function for constructing a pinned resource with a Foundation::Core::Allocator.

Template Parameters
Baseis the base class type be templated on.
Derivedcan be a subclass of Base, with destruction handled correctly.

◆ Destruct()

template<typename T >
void Foundation::Core::Destruct ( Allocator resource,
T obj 
)

Convenience destructor for objects allocated with Construct or ConstructBase.

◆ DestructSpan()

template<typename T >
void Foundation::Core::DestructSpan ( Allocator resource,
Span< T span 
)

Convenience function for destructing a Span allocated with ConstructSpan. Calls destructors in-place if the type is not trivially destructible (e.g. non-PODs)

◆ getBacktraceSink()

std::shared_ptr< spdlog::sinks::ringbuffer_sink_mt > Foundation::Core::getBacktraceSink ( )

◆ getLogger()

spdlog::logger * Foundation::Core::getLogger ( const char name)

◆ getLoggingSink()

std::shared_ptr< spdlog::sinks::dist_sink_mt > Foundation::Core::getLoggingSink ( )

Variable Documentation

◆ g_BacktraceSink

std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> Foundation::Core::g_BacktraceSink = nullptr
static

◆ g_Initialized

bool Foundation::Core::g_Initialized = false
static

◆ g_LoggerMutex

std::recursive_mutex Foundation::Core::g_LoggerMutex

◆ g_LoggingSink

std::shared_ptr<spdlog::sinks::dist_sink_mt> Foundation::Core::g_LoggingSink = nullptr
static

◆ g_LoggingSinkMutex

std::recursive_mutex Foundation::Core::g_LoggingSinkMutex

◆ kDefaultStackArenaSize

constexpr size_t Foundation::Core::kDefaultStackArenaSize = 12 * 1024
constexpr

◆ kMaxBacktraceLogMessages

const size_t Foundation::Core::kMaxBacktraceLogMessages = 1000