cpp-common/bt2: add `bt2::BorrowedObjectProxy`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 5 Dec 2023 14:46:25 +0000 (09:46 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 14 Dec 2023 15:57:04 +0000 (10:57 -0500)
commit3b1517b9a60ae6da454c188ad1961a339bb9ce70
tree8449e1687a86e90ed8cd4049dff637b0dcec35c6
parent8047a1755063eb23e5a07b3b96441e50c366ea87
cpp-common/bt2: add `bt2::BorrowedObjectProxy`

When bt2::Something::operator->() would need to return the address of
some `ObjT` instance, but none is available (because it only keeps the
libbabeltrace2 object pointer, not a built wrapper), then it can use
this new `bt2::BorrowedObjectProxy`.

This new class template accepts a library pointer at construction time,
constructs an internal `ObjT` instance, and its own operator->() method
returns the address of the latter.

Example:

    class Something
    {
        // ...

    public:
        BorrowedObjectProxy<SomeObject> operator->() const noexcept
        {
            return BorrowedObjectProxy<SomeObject> {_mLibObjPtr};
        }

    private:
        const bt_some_object *_mLibObjPtr;
    };

Then, with a `Something` instance `something`:

    something->methodOfSomeObject(...);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I67d63591fb6593080a15e2ab6804a53bd2d2aba8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11487
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/Makefile.am
src/cpp-common/bt2/borrowed-object-proxy.hpp [new file with mode: 0644]
This page took 0.023988 seconds and 4 git commands to generate.