MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / CachedWorkspaceMem

Class CachedWorkspaceMem

python/mod_cvcuda/WorkspaceCache.hpp:46–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45template<MemoryKind kind>
46class CachedWorkspaceMem : public cvcuda::WorkspaceMem
47{
48public:
49 CachedWorkspaceMem()
50 : cvcuda::WorkspaceMem({})
51 {
52 assert(data == nullptr);
53 assert(ready == nullptr);
54 }
55
56 CachedWorkspaceMem(const cvcuda::WorkspaceMem &mem, WorkspaceMemDestructor_t destructor)
57 : cvcuda::WorkspaceMem(mem)
58 , m_destructor(std::move(destructor))
59 {
60 }
61
62 CachedWorkspaceMem(CachedWorkspaceMem &&mem)
63 {
64 *this = std::move(mem);
65 }
66
67 CachedWorkspaceMem &operator=(CachedWorkspaceMem &&mem)
68 {
69 std::swap(wsMem(), mem.wsMem());
70 std::swap(m_destructor, mem.m_destructor);
71 mem.reset();
72 return *this;
73 }
74
75 ~CachedWorkspaceMem()
76 {
77 reset();
78 }
79
80 void reset()
81 {
82 if (m_destructor)
83 {
84 m_destructor(*this);
85 m_destructor = {};
86 }
87 wsMem() = {};
88 }
89
90 explicit operator bool() const noexcept
91 {
92 return data != nullptr;
93 }
94
95private:
96 cvcuda::WorkspaceMem &wsMem() &
97 {
98 return static_cast<cvcuda::WorkspaceMem &>(*this);
99 }
100
101 const cvcuda::WorkspaceMem &wsMem() const &
102 {
103 return static_cast<const cvcuda::WorkspaceMem &>(*this);

Callers

nothing calls this directly

Calls 2

swapFunction · 0.85
resetMethod · 0.45

Tested by

no test coverage detected