forked from wang-xinyu/tensorrtx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
holder.h
executable file
·41 lines (38 loc) · 1.04 KB
/
holder.h
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
36
37
38
39
40
41
#pragma once
template <typename T>
class TensorRTHolder {
T* holder;
public:
explicit TensorRTHolder(T* holder_) : holder(holder_) {}
~TensorRTHolder() {
if (holder)
holder->destroy();
}
TensorRTHolder(const TensorRTHolder&) = delete;
TensorRTHolder& operator=(const TensorRTHolder&) = delete;
TensorRTHolder(TensorRTHolder && rhs) noexcept{
holder = rhs.holder;
rhs.holder = nullptr;
}
TensorRTHolder& operator=(TensorRTHolder&& rhs) noexcept {
if (this == &rhs) {
return *this;
}
if (holder) holder->destroy();
holder = rhs.holder;
rhs.holder = nullptr;
return *this;
}
T* operator->() {
return holder;
}
T* get() { return holder; }
explicit operator bool() { return holder != nullptr; }
T& operator*() noexcept { return *holder; }
};
template <typename T>
TensorRTHolder<T> make_holder(T* holder) {
return TensorRTHolder<T>(holder);
}
template <typename T>
using TensorRTNonHolder = T*;