blob: 3231d33c6c1624209fd07ad3796c2d33b821b1d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/* ========================================
Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
======================================== */
#pragma once
#ifndef INC_KERNEL_HEAP_H
#include <KernelKit/HeapMgr.h>
#endif // !INC_KERNEL_HEAP_H
namespace Kernel {
/// @brief Allocate C++ class.
/// @param cls The class to allocate.
/// @param args The args to pass.
template <typename T, typename... Args>
inline BOOL mm_new_class(_Input _Output T** cls, _Input Args&&... args) {
if (*cls) {
err_global_get() = Kernel::kErrorInvalidData;
return NO;
}
*cls = new T(move(args)...);
return *cls;
}
/// @brief Delete and nullify C++ class.
/// @param cls The class to delete.
template <typename T>
inline Void mm_delete_class(_Input _Output T** cls) {
delete *cls;
*cls = nullptr;
}
} // namespace Kernel
|