Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
OpaqueObject.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "AlignedStorage.h"
5namespace SC
6{
9
29template <typename Definition>
31{
32 using Object = typename Definition::Object;
33
34 OpaqueObject() { construct(buffer); }
35 ~OpaqueObject() { destruct(get()); }
36 OpaqueObject(OpaqueObject&& other) { moveConstruct(buffer, forward<Object>(other.get())); }
37 OpaqueObject& operator=(OpaqueObject&& other)
38 {
39 moveAssign(get(), forward<Object>(other.get()));
40 return *this;
41 }
42
43 // Disallow copy construction and copy assignment
44 OpaqueObject(const OpaqueObject&) = delete;
45 OpaqueObject& operator=(const OpaqueObject&) = delete;
46
47 Object& get() { return reinterpret_cast<Object&>(buffer); }
48 const Object& get() const { return reinterpret_cast<const Object&>(buffer); }
49
50 private:
51#if SC_PLATFORM_WINDOWS
52 static constexpr int Size = Definition::Windows;
53#elif SC_PLATFORM_APPLE
54 static constexpr int Size = Definition::Apple;
55#elif SC_PLATFORM_LINUX
56 static constexpr int Size = Definition::Linux;
57#else
58 static constexpr int Size = Definition::Default;
59#endif
60 static constexpr int Alignment = Definition::Alignment;
61
63
65 static void construct(Handle& buffer);
66 static void destruct(Object& obj);
67 static void moveConstruct(Handle& buffer, Object&& obj);
68 static void moveAssign(Object& selfPointer, Object&& obj);
69};
70
72} // namespace SC
constexpr T && forward(typename TypeTraits::RemoveReference< T >::type &value)
Forwards an lvalue or an rvalue as an rvalue reference.
Definition Compiler.h:260
A buffer of bytes with given alignment.
Definition AlignedStorage.h:29
Hides implementation details from public headers (static PIMPL).
Definition OpaqueObject.h:31