CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBInterop.cpp
Go to the documentation of this file.
1 #include "CYB.hpp"
3 
4 //Allocator
5 template <class AAllocatable> AAllocatable* CYB::Engine::Allocator::DoAllocation(API::Interop::Constructor<void>& AConstructor) {
6  if (!AConstructor.Valid<AAllocatable>())
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 }
16 
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:
27  }
28 }
29 
32 {}
33 //Context
34 
36  return Core().CurrentContext();
37 }
38 
39 CYB::Engine::Context::Context(API::Heap& AHeap, API::Logger& ALogger, const bool AMakeCurrent) noexcept :
40  API::Interop::Context(FAllocatorObject, ALogger),
41  FAllocatorObject(AHeap)
42 {
43  if (AMakeCurrent)
44  MakeCurrent();
45 }
46 
47 void CYB::Engine::Context::MakeCurrent(void) noexcept {
49 }
50 
52  FOldContext(static_cast<Context&>(Context::GetContext()))
53 {
54  ANewContext.MakeCurrent();
55 }
56 
58  FOldContext.MakeCurrent();
59 }
Context & CurrentContext(void) noexcept
Get the current Context.
Definition: CYBCore.cpp:57
bool Valid(void) const noexcept
A best effort validation for the integrity of a Constructor for a given Allocatable.
API::Interop::Context & Context(void) noexcept
Get the API's Context.
ID
Defines the IDs of allocatable engine objects.
Definition: Allocatable.hpp:10
Heap & FHeap
The Heap this allocator uses.
Definition: Allocator.hpp:10
void * InteropAllocation(const API::Interop::Allocatable::ID AID, API::Interop::Constructor< void > &AConstructor) finaloverride
Allocates the object specified by AID into FHeap.
Definition: CYBInterop.cpp:17
Used as a base class by all constructors.
Definition: Constructor.hpp:56
AAllocatable * DoAllocation(API::Interop::Constructor< void > &AConstructor)
Template allocator for Allocatables.
Definition: CYBInterop.cpp:5
Class which is used as an API for the engine.
Definition: Context.hpp:7
void SetCurrentContext(Context &ANewContext) noexcept
Set the current Context.
Definition: CYBCore.cpp:61
Used for allocating objects within and without the engine.
Definition: Allocator.hpp:7
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.
Implements the engine level functions for API::Interop::Contexts.
Definition: CYBInterop.hpp:41
Precompiled header for inter-engine operations.
~PushContext()
Calls MakeCurrent on FOldContext.
Definition: CYBInterop.cpp:57
Engine::Core & Core(void) noexcept
Retrieve the Core singleton.
Definition: CYBCore.cpp:69
An interface which can allocate memory.
Definition: Heap.hpp:5
UniquePointer that uses our Allocator.
static Core & GetCore(void) noexcept
Retrieve the Core singleton.
Definition: CYBCore.cpp:45
The interface for writing safe logs.
Definition: Logger.hpp:7
Exceptions indicating an API contract violation. Should not be anticipated.
Definition: Exception.hpp:32
Context(API::Heap &AHeap, API::Logger &ALogger, const bool AMakeCurrent) noexcept
Setup the Context, optionally making it the current one.
Definition: CYBInterop.cpp:39
Allocator(API::Heap &AHeap) noexcept
Construct an Allocator.
Definition: CYBInterop.cpp:30
void MakeCurrent(void) noexcept
Set the current thread's Context singleton to this Context.
Definition: CYBInterop.cpp:47
static Context & GetContext(void) noexcept
Get the API's Context.
Definition: CYBInterop.cpp:35
PushContext(Context &ANewContext) noexcept
Saves the current Context and calls MakeCurrent on ANewContext.
Definition: CYBInterop.cpp:51
An operation was attempted with an invalid enum code.
Definition: Exception.hpp:36