2018-08-06 22:36:12 +08:00
|
|
|
/*
|
2023-12-04 18:51:53 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2018-08-06 22:36:12 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-08-06 22:36:12 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-08-06 22:36:12 +08:00
|
|
|
|
|
|
|
template <typename T>
|
2019-02-04 20:08:47 +08:00
|
|
|
struct ReleaseObject {
|
|
|
|
void operator()(T *t) {
|
|
|
|
if (t != nullptr) {
|
|
|
|
t->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using ReleaseableObjectPtr = std::unique_ptr<T, ReleaseObject<T>>;
|
2018-08-06 22:36:12 +08:00
|
|
|
|
|
|
|
template <typename T>
|
2019-01-29 21:57:59 +08:00
|
|
|
static ReleaseableObjectPtr<T> clUniquePtr(T *object) {
|
2019-02-04 20:08:47 +08:00
|
|
|
return ReleaseableObjectPtr<T>{object};
|
2018-08-06 22:36:12 +08:00
|
|
|
}
|
2019-02-06 15:49:35 +08:00
|
|
|
|
2023-12-04 18:51:53 +08:00
|
|
|
template <class Type, class... Types>
|
|
|
|
inline ReleaseableObjectPtr<Type> makeReleaseable(Types &&...args) {
|
|
|
|
return (ReleaseableObjectPtr<Type>(new Type(std::forward<Types>(args)...)));
|
2019-02-06 15:49:35 +08:00
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|