Natools

Diff
Login

Differences From Artifact [9b02b7f3d7]:

To Artifact [4a7ba030d7]:


1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







------------------------------------------------------------------------------
-- Copyright (c) 2013, Natacha Porté                                        --
-- Copyright (c) 2013-2014, Natacha Porté                                   --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
71
72
73
74
75
76
77
78
79
80

81



82
83
84




85
86
87
88
89
90

91
92


93
94



95
96
97
98
99
100
101
71
72
73
74
75
76
77



78
79
80
81
82



83
84
85
86
87
88
89
90
91

92
93
94
95
96


97
98
99
100
101
102
103
104
105
106







-
-
-
+

+
+
+
-
-
-
+
+
+
+





-
+


+
+
-
-
+
+
+







   begin
      Finalize (Ref);
      Ref.Data := new Held_Data'(Constructor.all);
      Ref.Count := new Counter'(1);
   end Replace;


   function Create
     (Constructor : not null access function return Data_Access)
      return Immutable_Reference is
   function Create (Data : in Data_Access) return Immutable_Reference is
   begin
      if Data = null then
         return Null_Immutable_Reference;
      else
      return (Ada.Finalization.Controlled with
         Data => Constructor.all,
         Count => new Counter'(1));
         return (Ada.Finalization.Controlled with
            Data => Data,
            Count => new Counter'(1));
      end if;
   end Create;


   procedure Replace
     (Ref : in out Immutable_Reference;
      Constructor : not null access function return Data_Access) is
      Data : in Data_Access) is
   begin
      Finalize (Ref);

      if Data /= null then
      Ref.Data := Constructor.all;
      Ref.Count := new Counter'(1);
         Ref.Data := Data;
         Ref.Count := new Counter'(1);
      end if;
   end Replace;


   procedure Reset (Ref : in out Immutable_Reference) is
   begin
      Finalize (Ref);
   end Reset;