]> www.infradead.org Git - users/dhowells/kafs-utils.git/commit
Implement a magic-pointer
authorDavid Howells <dhowells@redhat.com>
Wed, 26 Aug 2020 08:57:22 +0000 (09:57 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 4 May 2021 13:43:57 +0000 (14:43 +0100)
commit07db9a8f641c04e4e8c595b92c98296a51faf12e
tree13ebecda0f10d066bd0df7cae6cc6f890c45d8f4
parent2c71a3e9bfb39061e4415944e05848e33d34cfc6
Implement a magic-pointer

Implement a magic-pointer that manages objects based on a refcount held in
the pointed-to object.

The following classes are implemented:

 (*) refcount

     This class holds the refcount and is intended to be subclassed by any
     object that will be pointed to.

 (*) ref<to_class>

     This is a template pointer class that pins a reference on the object
     it points to, which must be of or derived from type to_class.
     to_class must be derived from class refcount.

 (*) pointer<to_class>

     This is like ref<to_class> but doesn't pin a reference.  It has no
     copy constructor, thereby allowing it to be passed in a register as an
     argument or a return value.

 (*) opaque_ref

     This class points to any object derived from class refcount and will
     pin a reference on the object.

 (*) opaque_pointer

     This is like class opaque_ref, but doesn't pin a reference.  It has no
     copy constructor, thereby allowing it to be passed in a register as an
     argument or a return value.

Objects can be assigned between any pair of classes.  Assigning from an
opaque ref/pointer to a template-typed ref/pointer will dynamic_cast the
value (if it's not NULL).

Signed-off-by: David Howells <dhowells@redhat.com>
lib/pointer.H [new file with mode: 0644]