AdaCL Reference counted smart pointer.
More...Element_Class |
Object |
Initialize |
Adjust | |
Create | |
Exist | |
Finalize | |
Get | |
Get_Base | |
Object_Image | |
Reset | |
Reset |
Element and Holder: A reference counted smart pointer for tagged types where the reference count is kept inside the tagged type. This is slightly faster, uses less memory and is more reliable. However it can only be uses for limited tagged types. Holder class for the actual element @formal Element_Type Type for which we want to supply a reference counter. Since, in Ada one can not overload the
1 | ":=" operator the type need to be limited so the counter is not damaged by assignment. |
---|---|
2 | Mind you, in C++ I almost always make the operator = private in Reference counted classes as |
3 | well. |
50 | type Element_Class is access Element_Type'Class; |
---|
an access type to match the element type.
62 | type Object is new AdaCL.Base.Object with private; |
---|
Parametrized Class AdaCL.Pointer.Reference : Object Access for Reference Counted Instances. Most smart pointer library's keep the counter inside the smart pointer. While this implementations allows the use with existing classes it is also very error prune: The counted instance always need to be handled with the smart pointer and is never allowed to be used any other way. I prefer to count inside the instance itself. This keeps the pointer far more reliable.
Inherits Object
Inherited by Protected_Object
118 | procedure Initialize (Object : in out Ada.Finalization.Controlled) renames Ada.Finalization.Initialize; |
---|
124 | overriding procedure Adjust (This : in out Object); |
---|
When adjusting we need to increase the counter.
Object itself.
68 | function Create (Referent : in Element_Class := null) return Object; |
---|
Creates a new smart pointer from normal pointer. Pointer to reference counted object
75 | function Exist (This : in Object) return Boolean; |
---|
Checks if a pointers is set
Object itself.
true when pointer is not null
130 | overriding procedure Finalize (This : in out Object); |
---|
When finalizing we need to decrease the counter. When the counter reaches 0 we delete the insanz.
Object itself.
81 | function Get (This : in Object) return Element_Class; |
---|
Returns the Pointer to the counted Object. Object itself.
87 | function Get_Base (This : in Object) return AdaCL.Limited_Base.Object_Class; |
---|
Returns the Pointer to the counted Object as base. Object itself.
116 | procedure Object_Image (Output : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; This : Object); |
---|
95 | procedure Reset (This : in out Object; Referent : Element_Class := null); |
---|
Set a new Pointer. This decreases the counter for the previous instance and increases the Pointer to the newly set instance.
Object itself.
The Object. Set to null to clean the pointer.
103 | procedure Reset (This : in out Object; Reference : Object); |
---|
Set a new Pointer. This decreases the counter for the previous instance and increases the Pointer to the newly set instance.
Object itself.
The Object. Set to null to clean the pointer.