-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathHandleBase.hpp
More file actions
42 lines (35 loc) · 1.49 KB
/
Copy pathHandleBase.hpp
File metadata and controls
42 lines (35 loc) · 1.49 KB
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
42
/*******************************************************
* Copyright (c) 2016, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#pragma once
namespace arrayfire {
namespace common {
template<typename T, typename H>
class HandleBase {
H handle_;
public:
HandleBase() : handle_(0) { static_cast<T*>(this)->createHandle(&handle_); }
~HandleBase() { static_cast<T*>(this)->destroyHandle(handle_); }
operator H() { return handle_; }
H* get() { return &handle_; }
HandleBase(HandleBase const&) = delete;
void operator=(HandleBase const&) = delete;
HandleBase(HandleBase&& h) = default;
HandleBase& operator=(HandleBase&& h) = default;
};
} // namespace common
} // namespace arrayfire
#define CREATE_HANDLE(NAME, TYPE, CREATE_FUNCTION, DESTROY_FUNCTION, \
CHECK_FUNCTION) \
class NAME : public common::HandleBase<NAME, TYPE> { \
public: \
void createHandle(TYPE* handle) { \
CHECK_FUNCTION(CREATE_FUNCTION(handle)); \
} \
void destroyHandle(TYPE handle) { DESTROY_FUNCTION(handle); } \
};