Index: src/natools-references.adb ================================================================== --- src/natools-references.adb +++ src/natools-references.adb @@ -72,10 +72,30 @@ 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; Index: src/natools-references.ads ================================================================== --- src/natools-references.ads +++ src/natools-references.ads @@ -36,10 +36,13 @@ 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) @@ -49,10 +52,20 @@ 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 @@ -90,13 +103,10 @@ type Counter is new Natural; type Counter_Access is access Counter; for Counter_Access'Storage_Pool use Counter_Pool; - type Data_Access is access Held_Data; - for Data_Access'Storage_Pool use Data_Pool; - type Immutable_Reference is new Ada.Finalization.Controlled with record Count : Counter_Access := null; Data : Data_Access := null; end record;