CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Private Member Functions | List of all members
CYB::Engine::Allocator Class Reference

Implements InteropAllocation for the public allocator. More...

#include <CYBInterop.hpp>

Inheritance diagram for CYB::Engine::Allocator:
Inheritance graph
[legend]
Collaboration diagram for CYB::Engine::Allocator:
Collaboration graph
[legend]

Public Member Functions

 Allocator (API::Heap &AHeap) noexcept
 Construct an Allocator. More...
 
template<class AObject , typename... AArgs>
AObject * RawObject (AArgs &&...AArguments)
 Allocates the Object specified by AAllocatable and returns a raw pointer which must be deleted using the Delete method of this object. More...
 
- Public Member Functions inherited from CYB::API::Interop::Allocator
template<class AObject , class AConstructor , typename... AArgs>
Object< AObject > ConstructObject (AArgs &&...AArguments)
 Allocates the Object specified by AObject using a specified Constructor. More...
 
template<class AObject , typename... AArgs>
Object< AObject > NewObject (AArgs &&...AArguments)
 Allocates the Object specified by AObject using the default constructor. More...
 
template<class AObject >
Object< AObject > NewObject (void)
 Allocates the Object specified by AObject using the empty constructor. More...
 
template<class AObject >
Object< AObject > CopyObject (const AObject &ACopy)
 Copys an Object of type AObject. More...
 
template<class AObject >
void DeleteObject (AObject *const AAllocated) noexcept
 Deletes an object allocated with the Allocator. More...
 

Private Member Functions

template<class AAllocatable >
AAllocatable * DoAllocation (API::Interop::Constructor< void > &AConstructor)
 Template allocator for Allocatables. More...
 
void * InteropAllocation (const API::Interop::Allocatable::ID AID, API::Interop::Constructor< void > &AConstructor) finaloverride
 Allocates the object specified by AID into FHeap. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CYB::API::Interop::Allocator
template<typename AType , typename... AArgs>
static AType * InPlaceAllocation (void *const ALocation, AArgs &&...AArguments)
 Wrapper for placement new. More...
 
- Public Attributes inherited from CYB::API::Interop::Allocator
HeapFHeap
 The Heap this allocator uses.
 
- Protected Member Functions inherited from CYB::API::Interop::Allocator
 Allocator (Heap &AHeap) noexcept
 Construct an Allocator. More...
 
template<class AObject , typename AConstructor , typename... AArgs>
AObject * AllocateObject (const std::true_type AIgnored, AArgs &&...AArguments)
 Allocate an Allocatable object through interop. More...
 
template<class AObject , typename AIgnoredConstructor , typename... AArgs>
AObject * AllocateObject (const std::false_type AIgnored, AArgs &&...AArguments)
 Allocate a concrete object. More...
 

Detailed Description

Implements InteropAllocation for the public allocator.

Definition at line 7 of file CYBInterop.hpp.

Constructor & Destructor Documentation

CYB::Engine::Allocator::Allocator ( API::Heap AHeap)
noexcept

Construct an Allocator.

Parameters
AHeapThe Heap the allocator will use
Thread Safety
This function requires no thread safety

Definition at line 30 of file CYBInterop.cpp.

30  :
31  API::Interop::Allocator(AHeap)
32 {}

Member Function Documentation

template<class AAllocatable >
AAllocatable * CYB::Engine::Allocator::DoAllocation ( API::Interop::Constructor< void > &  AConstructor)
private

Template allocator for Allocatables.

Template Parameters
AAllocatableThe Allocatable that inherits from an API Allocatable
Parameters
AConstructorThe Constructor for AAllocatable
Returns
A pointer to a context heap allocated AAllocatable
Thread Safety
Dependant on called constructors
Attention
Throws dependant on called constructor
Exceptions
CYB::Exception::SystemDataError code: CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE. Thrown if the current heap runs out of memory

Definition at line 5 of file CYBInterop.cpp.

5  {
6  if (!AConstructor.Valid<AAllocatable>())
7  throw Exception::Violation(Exception::Violation::INVALID_INTEROP_CONSTRUCTOR);
8 
9  auto& TrueConstructor(static_cast<typename AAllocatable::Constructor&>(AConstructor));
10 
11  API::UniquePointer<void> Location(FHeap.Alloc(sizeof(AAllocatable)));
12  TrueConstructor.template Construct<AAllocatable>(Location.get());
13  auto Result(static_cast<AAllocatable*>(Location.release()));
14  return Result;
15 }
Heap & FHeap
The Heap this allocator uses.
Definition: Allocator.hpp:10
A contructor passed to the engine was malformed.
Definition: Exception.hpp:37
virtual void * Alloc(const int ASize)=0
Allocate memory from the heap for use.

Here is the call graph for this function:

void * CYB::Engine::Allocator::InteropAllocation ( const API::Interop::Allocatable::ID  AID,
API::Interop::Constructor< void > &  AConstructor 
)
finaloverrideprivatevirtual

Allocates the object specified by AID into FHeap.

Parameters
AIDThe ID of the Allocatable to allocate
AConstructorA reference to the constructor required by the object
Returns
An Allocatable pointer which is the base class of the class indicated by AID
Thread Safety
Dependant on called constructor
Attention
Throws dependant on called constructor
Exceptions
CYB::Exception::SystemDataError code: CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE. Thrown if the current heap runs out of memory
CYB::Exception::ViolationError code: CYB::Exception::Violation::INVALID_ENUM. Thrown if AID is unknown to the engine.
CYB::Exception::ViolationError code: CYB::Exception::Violation::INVALID_INTEROP_CONSTRUCTOR. Thrown if AConstructor is malformed

Implements CYB::API::Interop::Allocator.

Definition at line 17 of file CYBInterop.cpp.

17  {
18  using namespace API::Interop;
19  switch (AID) {
20  case Allocatable::ID::File: return DoAllocation<Platform::System::File>(AConstructor);
21  case Allocatable::ID::Mutex: return DoAllocation<Platform::System::Mutex>(AConstructor);
22  case Allocatable::ID::Path: return DoAllocation<Platform::System::Path>(AConstructor);
23  case Allocatable::ID::Semaphore: return DoAllocation<Platform::System::Semaphore>(AConstructor);
24  case Allocatable::ID::NULL_ID:
25  default:
26  throw Exception::Violation(Exception::Violation::INVALID_ENUM);
27  }
28 }
An operation was attempted with an invalid enum code.
Definition: Exception.hpp:36
template<class AObject , typename... AArgs>
AObject* CYB::Engine::Allocator::RawObject ( AArgs &&...  AArguments)

Allocates the Object specified by AAllocatable and returns a raw pointer which must be deleted using the Delete method of this object.

Template Parameters
AObjectThe type of object to allocate
AArgsThe arguments types of AObject's constructor
Parameters
AArgumentsThe arguments of AObject's constructor
Returns
A pointer to an AObject allocated on this allocator's Heap
Thread Safety
This function requires no thread safety
Attention
Throws dependant on called constructor
Exceptions
CYB::Exception::SystemDataError code: CYB::Exception::SystemData::HEAP_ALLOCATION_FAILURE. Thrown if the Heap does not have the space for the allocation and more system memory cannot be requested

The documentation for this class was generated from the following files: