From 421db65331663304466577b7187780d9eba18077 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 28 Sep 2024 19:13:46 +0200 Subject: feat: Add common XPCOM controls directory, restructure project, and introduce API breaking changes - Added a new directory for common XPCOM controls to organize reusable components. - Restructured project layout for better modularity and maintainability. - Introduced API breaking changes in the process, requiring adjustments for backward compatibility. Signed-off-by: Amlal --- dev/crt/base_alloc.hxx | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 dev/crt/base_alloc.hxx (limited to 'dev/crt/base_alloc.hxx') diff --git a/dev/crt/base_alloc.hxx b/dev/crt/base_alloc.hxx new file mode 100644 index 00000000..de157866 --- /dev/null +++ b/dev/crt/base_alloc.hxx @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include + +namespace std::base_alloc +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template + inline KindClass* allocate(Args&&... args) + { + return new KindClass(forward(args)...); + } + + /// @brief allocate a new class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template + inline KindClass* allocate_nothrow(Args&&... args) noexcept + { + return allocate(forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template + inline void release(KindClass ptr) + { + if (!ptr) + return; + + delete ptr; + } + + /// @brief destroy and free a class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template + inline void release_nothrow(KindClass ptr) noexcept + { + release(ptr); + } +} // namespace std::base_alloc -- cgit v1.2.3