Natools

Check-in [c104c5befa]
Login
Overview
Comment:references: use access value directly in new constructors, instead of access to functions returning access value
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c104c5befa28f534a34eae20996c774bd23c2827
User & Date: nat on 2014-07-11 20:37:15
Other Links: manifest | tags
Context
2014-07-12
16:08
reference_tests: use the new access-based constructors, to reach full coverage again check-in: 2d7c2f8e09 user: nat tags: trunk
2014-07-11
20:37
references: use access value directly in new constructors, instead of access to functions returning access value check-in: c104c5befa user: nat tags: trunk
2014-07-10
18:27
references: add constructors with user-provided access value, to allow zero-copy initialization of non-limited types check-in: 55bbe4642d user: nat tags: trunk
Changes

Modified src/natools-references.adb from [9b02b7f3d7] to [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;

Modified src/natools-references.ads from [5b3dc9598c] to [8f5373a61a].

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         --
50
51
52
53
54
55
56
57
58
59
60




61
62
63


64
65


66
67
68
69
70
71
72
50
51
52
53
54
55
56




57
58
59
60
61


62
63


64
65
66
67
68
69
70
71
72







-
-
-
-
+
+
+
+

-
-
+
+
-
-
+
+







      --  Create a new held object and return a reference to it

   procedure Replace
     (Ref : in out Immutable_Reference;
      Constructor : not null access function return Held_Data);
      --  Replace the object held in Ref with a newly created object

   function Create
     (Constructor : not null access function return Data_Access)
      return Immutable_Reference;
      --  Create a new held object and return a reference to it
   function Create (Data : in Data_Access) return Immutable_Reference;
      --  Create a new reference from Data.
      --  From this point the referred object is owned by this
      --  package and must NOT be freed or changed or accessed.

   procedure Replace
     (Ref : in out Immutable_Reference;
   procedure Replace (Ref : in out Immutable_Reference; Data : in Data_Access);
      --  Integrate Data into Ref.
      Constructor : not null access function return Data_Access);
      --  Replace the object held in Ref with a newly created object
      --  From this point the referred object is owned by this
      --  package and must NOT be freed or changed or accessed.

   procedure Reset (Ref : in out Immutable_Reference);
      --  Empty Ref

   function Is_Empty (Ref : Immutable_Reference) return Boolean;
      --  Check whether Ref refers to an actual object