Singleton: Difference between revisions

482 bytes removed ,  16 years ago
Line 38:
===Thread Safe===
<ada>package Protected_Singleton is
procedure Set_Data (Value : Integer);
type Singleton is limited private;
procedurefunction Set_Data(ItemGet_Data : out Singleton; Value :return Integer);
function Get_Data(Item : Singleton) return Integer;
function Create return Singleton;
private
protected type Instance_TypeInstance is
procedure Set(Value : Integer);
function Get return Integer;
Line 49 ⟶ 47:
Data : Integer := 0;
end Instance_Type;
type Singleton is access all Instance_Type;
Instance : aliased Instance_Type;
end Protected_Singleton;</ada>
 
Line 59 ⟶ 55:
--------------
 
procedure Set_Data (Item : out Singleton; Value : Integer) is
begin
if Item = null then
Item := Create;
end if;
Instance.Set(Value);
end Set_Data;
Line 71 ⟶ 64:
--------------
 
function Get_Data (Item : Singleton) return Integer is
begin
return Instance.Get;
end Get_Data;
 
--------------
-- CreateInstance --
--------------
 
functionprotected Createbody return SingletonInstance is
begin
return Instance'access;
end Create;
 
-------------------
-- Instance_Type --
-------------------
 
protected body Instance_Type is
 
---------
Line 109 ⟶ 93:
end Get;
 
end Instance_TypeInstance;
 
end Protected_Singleton;</ada>
Anonymous user