- Basic RTTI type data with inheritance.

This commit is contained in:
2025-11-28 12:58:23 -05:00
parent b9026ec8da
commit fe8c3a4602
126 changed files with 2158 additions and 979 deletions

View File

@@ -19,7 +19,7 @@
#ifndef FENNEC_MEMORY_POINTERS_H
#define FENNEC_MEMORY_POINTERS_H
#include <fennec/lang/type_traits.h>
#include <fennec/langcpp/type_traits.h>
namespace fennec
{
@@ -45,7 +45,7 @@ struct default_delete
/// \param ptr Memory resource to delete
constexpr void operator()(TypeT* ptr) const noexcept {
static_assert(not is_void_v<TypeT>, "cannot delete a pointer to an incomplete type");
static_assert(not sizeof(TypeT) > 0, "cannot delete a pointer to an incomplete type");
static_assert(is_complete_v<TypeT>, "cannot delete a pointer to an incomplete type");
delete ptr;
}
};
@@ -70,7 +70,7 @@ struct default_delete<TypeT[]>
template<class ArrT> requires requires { is_convertible_v<ArrT(*)[], TypeT(*)[]> == true; }
constexpr void operator()(TypeT* ptr) const noexcept {
static_assert(not is_void_v<TypeT>, "cannot delete a pointer to an incomplete type");
static_assert(not sizeof(TypeT) > 0, "cannot delete a pointer to an incomplete type");
static_assert(is_complete_v<TypeT>, "cannot delete a pointer to an incomplete type");
delete[] ptr;
}
};
@@ -91,6 +91,9 @@ public:
/// \brief pointer to element type
using pointer_t = element_t*;
/// \brief pointer to element type
using const_pointer_t = const element_t*;
/// \brief the deleter
using delete_t = DeleteT;
@@ -100,7 +103,7 @@ public:
///
/// \brief Nullptr Constructor, creates a unique_ptr that owns nothing.
constexpr unique_ptr(nullptr_t) noexcept : unique_ptr(nullptr) {}
constexpr unique_ptr(nullptr_t) noexcept : unique_ptr(nullptr, delete_t()) {}
///
/// \brief Pointer Constructor, creates a unique_ptr that owns `ptr` with deleter `del`
@@ -115,7 +118,7 @@ public:
/// \brief Pointer Constructor, creates a unique_ptr that owns `ptr` with deleter `del`
/// \param ptr The resource to own
/// \param del The deleter
explicit constexpr unique_ptr(pointer_t ptr, delete_t&& del)
explicit constexpr unique_ptr(pointer_t ptr, delete_t&& del = delete_t())
: _delete(del)
, _handle(ptr) {
}
@@ -152,12 +155,39 @@ public:
return retval;
}
pointer_t get() {
return _handle;
}
bool empty() {
return _handle == nullptr;
}
pointer_t operator->() {
return _handle;
}
const_pointer_t operator->() const {
return _handle;
}
private:
delete_t _delete;
pointer_t _handle;
};
///
/// \brief Creates a unique pointer holding an object of type `TypeT`
/// \tparam TypeT The type
/// \tparam ArgsT The constructor arguments, automatically deduced
/// \param args The constructor arguments
/// \returns A unique pointer holding a heap allocated object of type `TypeT` constructed with arguments `args`
template<typename TypeT, typename...ArgsT>
unique_ptr<TypeT> make_unique(ArgsT&&...args) {
return unique_ptr<TypeT>(new TypeT(fennec::forward<ArgsT>(args)...));
}
}
#endif // FENNEC_MEMORY_POINTERS_H