2018-08-06 16:36:12 +02:00
|
|
|
/*
|
2022-05-16 14:06:56 +00:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2018-08-06 16:36:12 +02:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-08-06 16:36:12 +02:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-08-06 16:36:12 +02:00
|
|
|
|
|
|
|
|
template <typename T>
|
2019-02-04 13:08:47 +01: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 16:36:12 +02:00
|
|
|
|
|
|
|
|
template <typename T>
|
2019-01-29 14:57:59 +01:00
|
|
|
static ReleaseableObjectPtr<T> clUniquePtr(T *object) {
|
2019-02-04 13:08:47 +01:00
|
|
|
return ReleaseableObjectPtr<T>{object};
|
2018-08-06 16:36:12 +02:00
|
|
|
}
|
2019-02-06 08:49:35 +01:00
|
|
|
|
|
|
|
|
template <class _Ty, class... _Types>
|
2022-05-16 14:06:56 +00:00
|
|
|
inline ReleaseableObjectPtr<_Ty> makeReleaseable(_Types &&...args) {
|
2019-11-20 12:23:06 +01:00
|
|
|
return (ReleaseableObjectPtr<_Ty>(new _Ty(std::forward<_Types>(args)...)));
|
2019-02-06 08:49:35 +01:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|