| 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: |
| 21 | explicit BorrowedObjectProxy(typename ObjT::LibObjPtr libObjPtr) noexcept : _mObj {libObjPtr} |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | ObjT *operator->() noexcept |
| 26 | { |
| 27 | return &_mObj; |
| 28 | } |
| 29 | |
| 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 */ |