L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
cxx::Weak_ref< T > Class Template Reference

Typed weak reference to an object of type T. More...

#include <weak_ref>

+ Inheritance diagram for cxx::Weak_ref< T >:
+ Collaboration diagram for cxx::Weak_ref< T >:

Additional Inherited Members

- Public Member Functions inherited from cxx::H_list_item_t< Weak_ref_base >
 H_list_item_t ()
 Constructor.
 
 ~H_list_item_t () noexcept
 Destructor.
 

Detailed Description

template<typename T>
class cxx::Weak_ref< T >

Typed weak reference to an object of type T.

Template Parameters
TThe type of the referenced object.

A weak reference is a reference that is invalidated when the referenced object is about to be deleted. All weak references to an object are kept in a linked list (see Weak_ref_base::List) and all the weak references are iterated and reset by the Weak_ref_base::List destructor or Weak_ref_base::List::reset().

The type T must provide two methods that handle the housekeeping of weak references: remove_weak_ref(Weak_ref_base *) and add_weak_ref(Weak_ref_base *). These functions must handle the insertion and removal of the weak reference into the respective Weak_ref_base::List object. For convenience one can use the cxx::Weak_ref_obj as a base class that handles weak references for you.

For example:

class C : public cxx::Weak_ref_obj {};
int main()
{
cxx::Weak_ref<C> r; // r is nullptr
{
C c;
r = &c; // now r points to c
} // c is destructed, which implies resetting all weak references to c
// now r is nullptr
return 0;
}
Typed weak reference to an object of type T.
Definition weak_ref:97
Note
Weak references have no effect on the lifetime of the referenced object. Hence, a referenced object is not deleted when all weak references for it are gone. If automatic deletion is needed, see cxx::Ref_ptr.

Definition at line 96 of file weak_ref.


The documentation for this class was generated from the following file: