1 | ------------------------------------------------------------------------------ |
---|---|
2 | --: Copyright © 2003 … 2023 Martin Krischik «krischik@users.sourceforge.net» |
3 | ------------------------------------------------------------------------------ |
4 | --: This library is free software; you can redistribute it and/or modify it |
5 | --: under the terms of the GNU Library General Public License as published by |
6 | --: the Free Software Foundation; either version 2 of the License, or (at your |
7 | --: option) any later version. |
8 | --: |
9 | --: This library is distributed in the hope that it will be useful, but |
10 | --: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
11 | --: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | --: License for more details. |
13 | --: |
14 | --: You should have received a copy of the GNU Library General Public License |
15 | --: along with this library; if not, write to the Free Software Foundation, |
16 | --: Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | ---------------------------------------------------------------------------- |
18 | |
19 | pragma License (Modified_Gpl); |
20 | pragma Ada_2022; |
21 | |
22 | with Ada.Unchecked_Deallocation; |
23 | with AdaCL.Pointer.Shared_With_Delete; |
24 | |
25 | --- |
26 | -- @summary |
27 | -- AdaCL: Ada Class Library — smart pointer. |
28 | -- |
29 | -- @description |
30 | -- Smart pointer with which can share an access. The referenced element is deleted when the last reference is removed. |
31 | -- |
32 | -- Simplified version which only need the element type |
33 | -- |
34 | --: Element_Type the element which are handled by the pointer |
35 | generic |
36 | type Element_Type (<>) is limited private; |
37 | package AdaCL.Pointer.Shared is |
38 | type Pointer is access Element_Type; |
39 | |
40 | procedure Deleter is new Ada.Unchecked_Deallocation (Object => Element_Type, Name => Pointer); |
41 | |
42 | package Delegate is new AdaCL.Pointer.Shared_With_Delete (Element_Type => Element_Type, Pointer => Pointer); |
43 | |
44 | subtype Object is Delegate.Object; |
45 | |
46 | --- |
47 | -- Creates a new unique smart pointer from normal pointer. |
48 | -- |
49 | --: @param Referent Pointer to reference counted object |
50 | --: @return New smart pointer |
51 | function Create (Referent : in Pointer := null) return Object renames Delegate.Create; |
52 | |
53 | --- |
54 | -- Checks if a pointers is set |
55 | -- |
56 | --: @param This Object itself. |
57 | --: @return true when pointer is not null |
58 | function Exist (This : in Object) return Boolean renames Delegate.Exist; |
59 | |
60 | --- |
61 | -- gets pointer to element to perform operations on. Do not save the pointer. |
62 | -- |
63 | --: @param This Object itself. |
64 | --: @return pointer to element |
65 | function Get (This : in Object) return not null Pointer renames Delegate.Get; |
66 | |
67 | --- |
68 | -- Replaces the managed object. |
69 | -- |
70 | --: @param This Object itself. |
71 | --: @param Referent new pointer to manage |
72 | procedure Reset (This : in out Object; Referent : in Pointer := null) renames Delegate.Reset; |
73 | |
74 | --- |
75 | -- swaps the managed objects |
76 | -- |
77 | --: @param This Object itself. |
78 | --: @param Other Object to swap Referents with |
79 | procedure Swap (This : in out Object; Other : in out Object) renames Delegate.Swap; |
80 | |
81 | end AdaCL.Pointer.Shared; |
82 | |
83 | ---------------------------------------------------------------- {{{ ---------- |
84 | --: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab : |
85 | --: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr : |
86 | --: vim: set spell spelllang=en_gb : |