procedure Save_Object (Object : Abstracted_Access;
File : W_Io.File_Type;
Index : Natural := 0) is
O : Abstracted_Access := Object;
New_Index : Natural := Index;
begin
O.all.Write(File);
W_Io.Put_Line(File, To_Wide_String(Integer'Image(Integer(Abstracted_Vectors.Length(O.Vector)))));
W_Io.Put_Line(File, Wide_Character'Val(7) & "" );
if not Is_Empty(O.Vector) then
for I in 1..Last_Index(O.Vector) loop
declare
E : constant Abstracted_Access :=
Abstracted_Vectors.Element(O.Vector, I);
begin
Save_Object(E, File, New_Index+1);
end;
end loop;
for I in 0..Index loop
W_Io.Put_Line(File, Wide_Character'Val(7) & "" );
end loop;
end if;
end Save_Object;
procedure Save (Object : in Abstracted_Access;
Filename : in String) is
File : W_Io.File_Type;
begin
W_Io.Create(File, W_Io.Out_File, Filename);
Save_Object(Object, File);
W_Io.Close(File);
end Save;
Restauration
procedure Restore_Vector(T : in out Terminal_Record;
File : W_Io.File_Type) is
Line_Index : positive := 1;
Is_End : Boolean := False;
Wchar : Wide_Character;
Prompt : Name_Type;
Success : Boolean := True;
O : Abstracted_Access;
End_Of_File : Boolean := False;
P : Natural := 0;
Child_Numb : Natural := 0;
begin
declare
Children : Wide_String := W_Io.Get_Line(File);
begin
Child_Numb := Natural'Value(To_String(Children));
if Child_Numb /= 0 then
for I in 1..Child_Numb loop
if not W_Io.End_Of_File(File) then
-- ici on cherche le caractère bell
while not W_Io.End_Of_File(File) loop
begin
W_Io.Look_ahead(File, Wchar, Is_end);
if Is_Graphic(To_Character(Wchar)) then
exit;
end if;
W_Io.Get_Immediate(File, Wchar);
if Wchar = Wide_Character'Val(7) then
P := P + 1;
end if;
end;
end loop;
Global_Read(File, End_Of_File, O);
Global_Print(O, Win, Line_index);
if P > 0 and P <= Natural(Length(T.V_Switch)) then
for I in 1..P-1 loop
Parent(T, Prompt);
end loop;
Success := False;
elsif P > 0 then
for I in 1..P loop
Parent(T, Prompt);
end loop;
end if;
Line_Index := 1;
if not Success then
if O.Index /= 1 then
T.Obj_Cur.Vector := T.Obj_Cur.Vector & O;
elsif not Is_Empty (T.Obj_Cur.Vector) and O.Index = 1 then
Switch(T, Last_Index(T.Obj_Cur.Vector), Prompt, Success);
T.Obj_Cur.Vector := T.Obj_Cur.Vector & O;
end if;
elsif not Is_Empty (T.Obj_Cur.Vector) and O.Index = 1 then
Switch(T, Last_Index(T.Obj_Cur.Vector), Prompt, Success);
if Success then
T.Obj_Cur.Vector := T.Obj_Cur.Vector & O;
else
raise Program_Error;
end if;
else
T.Obj_Cur.Vector := T.Obj_Cur.Vector & O;
end if;
if not W_Io.End_Of_File(File) then
Restore_Vector(T, File);
end if;
end if;
end loop;
end if;
-- le code ci-dessous est peut-être inutile.
if not W_Io.End_Of_File(File) then
Restore_Vector(T, File);
end if;
exception
when others =>
Put("Error when restore object" );
end;
end Restore_Vector;
procedure Restore_Object (T : in out Terminal_Record;
File : W_Io.File_Type) is
End_Of_File : Boolean := False;
Vector : Objects_Vector;
begin
if not W_Io.End_Of_File(File) then
Global_Read(File, End_Of_File, T.Obj);
end if;
T.Obj_Cur := T.Obj;
if not W_Io.End_Of_File(File) then
Restore_Vector(T, File);
end if;
end Restore_Object;
procedure Restore(T : in out Terminal_Record;
Filename : in String) is
File : W_Io.File_Type;
begin
W_Io.Open(File, W_Io.in_File, Filename);
if not W_Io.End_Of_File(File) then
Restore_Object(T, File);
end if;
W_Io.Close(File);
end Restore;