2018-08-06 22:36:12 +08:00
|
|
|
/*
|
2019-01-29 21:57:59 +08:00
|
|
|
* Copyright (C) 2018-2019 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
|
|
|
|
|
|
|
template <class _Ty, class... _Types>
|
|
|
|
inline ReleaseableObjectPtr<_Ty> make_releaseable(_Types &&... _Args) {
|
|
|
|
return (ReleaseableObjectPtr<_Ty>(new _Ty(std::forward<_Types>(_Args)...)));
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|