Overview
Comment: | references: add constructors with user-provided access value, to allow zero-copy initialization of non-limited types |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
55bbe4642d7c4c5299d5699c4e38219a |
User & Date: | nat on 2014-07-10 18:27:16 |
Other Links: | manifest | tags |
Context
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 | |
2014-07-09
| ||
17:52 | Update LICENSE and add README check-in: 41ff0e3319 user: nat tags: trunk | |
Changes
Modified src/natools-references.adb from [ced30f8c32] to [9b02b7f3d7].
︙ | ︙ | |||
70 71 72 73 74 75 76 77 78 79 80 81 82 83 | Constructor : not null access function return Held_Data) is begin Finalize (Ref); Ref.Data := new Held_Data'(Constructor.all); Ref.Count := new Counter'(1); end Replace; procedure Reset (Ref : in out Immutable_Reference) is begin Finalize (Ref); end Reset; | > > > > > > > > > > > > > > > > > > > > | 70 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 | Constructor : not null access function return Held_Data) is 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 begin return (Ada.Finalization.Controlled with Data => Constructor.all, Count => new Counter'(1)); end Create; procedure Replace (Ref : in out Immutable_Reference; Constructor : not null access function return Data_Access) is begin Finalize (Ref); Ref.Data := Constructor.all; Ref.Count := new Counter'(1); end Replace; procedure Reset (Ref : in out Immutable_Reference) is begin Finalize (Ref); end Reset; |
︙ | ︙ |
Modified src/natools-references.ads from [5708cf8da3] to [5b3dc9598c].
︙ | ︙ | |||
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | pragma Preelaborate (References); type Accessor (Data : not null access constant Held_Data) is limited private; type Mutator (Data : not null access Held_Data) is limited private; type Immutable_Reference is new Ada.Finalization.Controlled with private; function Create (Constructor : not null access function return Held_Data) return Immutable_Reference; -- 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 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 function "=" (Left, Right : Immutable_Reference) return Boolean; | > > > > > > > > > > > > > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | pragma Preelaborate (References); type Accessor (Data : not null access constant Held_Data) is limited private; type Mutator (Data : not null access Held_Data) is limited private; type Data_Access is access Held_Data; for Data_Access'Storage_Pool use Data_Pool; type Immutable_Reference is new Ada.Finalization.Controlled with private; function Create (Constructor : not null access function return Held_Data) return Immutable_Reference; -- 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 procedure Replace (Ref : in out Immutable_Reference; Constructor : not null access function return Data_Access); -- Replace the object held in Ref with a newly created object 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 function "=" (Left, Right : Immutable_Reference) return Boolean; |
︙ | ︙ | |||
88 89 90 91 92 93 94 | private type Counter is new Natural; type Counter_Access is access Counter; for Counter_Access'Storage_Pool use Counter_Pool; | < < < | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | private type Counter is new Natural; type Counter_Access is access Counter; for Counter_Access'Storage_Pool use Counter_Pool; type Immutable_Reference is new Ada.Finalization.Controlled with record Count : Counter_Access := null; Data : Data_Access := null; end record; overriding procedure Adjust (Object : in out Immutable_Reference); -- Increate reference counter |
︙ | ︙ |