1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
| with Ada.Finalization;
package Libmy is
type My_Type is
abstract new Ada.Finalization.Controlled with null record;
procedure Initialize(My : in out My_Type'Class) is abstract;
procedure Finalize(My : in out My_Type'Class) is abstract;
procedure Print(My : in My_Type'class) is abstract;
end Libmy;
with Libmy;
with Ada.Calendar;
package Liblife is
use Ada;
type Life_type is new Libmy.My_Type with
record
Birth : Calendar.Time;
Death : Calendar.Time;
end record;
procedure Print(Life : in Life_Type);
private
procedure Initialize(Life : in out Life_Type);
procedure finalize(Life : in out Life_Type);
end Liblife;
with Ada.Text_Io;
with Ada.Calendar.Formatting;
package body Liblife is
procedure Initialize(Life : in out Life_Type) is
begin
null;
end Initialize;
procedure finalize(Life : in out Life_Type) is
begin
null;
end Finalize;
procedure Print(Life : in Life_Type) is
begin
Text_Io.Put("Birth:" & Calendar.Formatting.Image(Life.Birth) &
", death:" & Calendar.Formatting.Image(Life.Death));
end Print;
end Liblife;
with Liblife;
with Ada.Strings.Unbounded;
package Libhuman is
use Ada.Strings;
type human_type is new Liblife.Life_Type with
record
Name : Unbounded.Unbounded_String;
end record;
procedure Print(Human : in Human_Type);
private
procedure Initialize(Human : in out Human_Type);
procedure finalize(Human : in out Human_Type);
end Libhuman;
with Ada.Text_Io;
package body Libhuman is
use Ada;
procedure Initialize(Human : in out Human_Type) is
begin
null;
end Initialize;
procedure finalize(Human : in out Human_Type) is
begin
null;
end Finalize;
procedure Print(Human : in Human_Type) is
begin
Liblife.Life_Type(Human).Print;
Text_Io.Put("Name:" & Unbounded.To_String(Human.Name));
end Print;
end Libhuman;
with Gnat.Sockets;
use Gnat.Sockets;
package Arche is
type Class_Type is (Life, human);
type Request_Type is (Full_List, Create);
Service_Port : Port_Type := 5870;
end Arche;
with Libmy, LibLife, LibHuman;
use LibLife, LibHuman;
with Ada.Containers.Doubly_Linked_Lists;
use Ada.Containers;
package Arche.Manager is
procedure Create(Class : in Class_Type);
procedure Print(Class : in Class_Type);
Limit_Error : exception;
Usage_Error : exception;
type My_Access is access all Libmy.My_Type'Class;
package My_DLL Is new Ada.Containers.Doubly_Linked_Lists(My_Access,
"=");
My_Manager : My_Dll.List;
end Arche.Manager;
with Ada.Calendar;
with Ada.Strings.Unbounded;
with Ada.Text_Io;
package body Arche.Manager is
use Ada, Ada.Strings;
procedure Create(Class : in Class_Type) is
The_Cursor : My_Dll.Cursor;
Date : constant Calendar.Time := Calendar.Clock;
Name : Unbounded.Unbounded_String;
The_Life : My_Access;
The_Human : My_Access;
begin
The_Cursor := My_Dll.Last(My_Manager);
case Class is
when Life =>
The_Life := new Life_Type;
Life_Type(The_Life.all).Birth := Date;
Life_Type(The_Life.all).Death := Date;
My_Dll.Insert(My_Manager, The_Cursor, The_Life);
when Human =>
Life_Type(The_Life.all).Birth := Date;
Life_Type(The_Life.all).Death := Date;
Text_Io.Put("Enter Name:");
Name := Unbounded.To_Unbounded_String(Text_Io.Get_Line);
The_human := new Human_Type '(The_Life.all with Name => Name);
My_Dll.Insert(My_Manager, The_Cursor, The_Human);
end case;
end Create;
procedure Print(Class : in Class_Type) is
The_Cursor : My_Dll.Cursor;
begin
if My_Dll.Is_Empty(My_Manager) then
raise Usage_Error;
end if;
The_Cursor := My_Dll.First(My_Manager);
case Class is
when Life =>
for I in 1..My_Dll.Length(My_Manager) loop
if My_Dll.Element(The_Cursor).all in Liblife.Life_Type then
Life_Type(My_Dll.Element(The_Cursor).all).Print;
end if;
My_Dll.Next(The_Cursor);
Text_Io.New_Line;
end loop;
when Human =>
for I in 1..My_Dll.Length(My_Manager) loop
if My_Dll.Element(The_Cursor).all in Human_Type then
Human_Type(My_Dll.Element(The_cursor).all).print;
end if;
My_Dll.Next(The_Cursor);
Text_Io.New_Line;
end loop;
end case;
end Print;
end Arche.Manager;
with Arche.Manager;
procedure Main is
use Arche, Arche.Manager;
begin
-- Arche.Create(Arche.Life);
-- Arche.Print(Arche.Life);
Create(Arche.Human);
Print(Arche.human);
end Main; |
Partager