Commit | Line | Data |
---|---|---|
3b1517b9 PP |
1 | /* |
2 | * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: MIT | |
5 | */ | |
6 | ||
7 | #ifndef BABELTRACE_CPP_COMMON_BT2_BORROWED_OBJECT_PROXY_HPP | |
8 | #define BABELTRACE_CPP_COMMON_BT2_BORROWED_OBJECT_PROXY_HPP | |
9 | ||
10 | namespace bt2 { | |
11 | ||
12 | /* | |
13 | * A proxy containing a valid borrowed object instance of `ObjT` to make | |
14 | * Something::operator->() work when only a libbabeltrace2 object | |
15 | * pointer is available. | |
16 | */ | |
17 | template <typename ObjT> | |
18 | class BorrowedObjectProxy final | |
19 | { | |
20 | public: | |
d246c457 | 21 | explicit BorrowedObjectProxy(typename ObjT::LibObjPtr libObjPtr) noexcept : _mObj {libObjPtr} |
3b1517b9 PP |
22 | { |
23 | } | |
24 | ||
81c7f242 SM |
25 | ObjT *operator->() noexcept |
26 | { | |
27 | return &_mObj; | |
28 | } | |
29 | ||
3b1517b9 PP |
30 | const ObjT *operator->() const noexcept |
31 | { | |
32 | return &_mObj; | |
33 | } | |
34 | ||
35 | private: | |
36 | ObjT _mObj; | |
37 | }; | |
38 | ||
39 | } /* namespace bt2 */ | |
40 | ||
41 | #endif /* BABELTRACE_CPP_COMMON_BT2_BORROWED_OBJECT_PROXY_HPP */ |