Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,34 +0,0 @@
|
|||
private with Ada.Containers.Indefinite_Vectors;
|
||||
generic
|
||||
type Item_Type (<>) is private;
|
||||
package History_Variables is
|
||||
|
||||
type Variable is tagged limited private;
|
||||
|
||||
-- set and get current value
|
||||
procedure Set(V: in out Variable; Item: Item_Type);
|
||||
function Get(V: Variable) return Item_Type;
|
||||
|
||||
-- number of items in history (including the current one)
|
||||
function Defined(V: Variable) return Natural;
|
||||
|
||||
-- non-destructively search for old values
|
||||
function Peek(V: Variable; Generation: Natural := 1) return Item_Type;
|
||||
-- V.Peek(0) returns current value; V.Peek(1) the previous value, etc.
|
||||
-- when calling V.Peek(i), i must be in 0 .. V.Defined-1, else Constraint_Error is raised
|
||||
|
||||
-- destructively restore previous value
|
||||
procedure Undo(V: in out Variable);
|
||||
-- old V.Peek(0) is forgotten, old V.Peek(i) is new V.Peek(i-1), etc.
|
||||
-- accordingly, V.Defined decrements by 1
|
||||
-- special case: if V.Defined=0 then V.Undo does not change V
|
||||
|
||||
private
|
||||
package Vectors is new Ada.Containers.Indefinite_Vectors
|
||||
(Index_Type => Positive,
|
||||
Element_Type => Item_Type);
|
||||
|
||||
type Variable is tagged limited record
|
||||
History: Vectors.Vector;
|
||||
end record;
|
||||
end History_Variables;
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package body History_Variables is
|
||||
|
||||
-- set and get
|
||||
procedure Set(V: in out Variable; Item: Item_Type) is
|
||||
begin
|
||||
V.History.Prepend(Item);
|
||||
end Set;
|
||||
|
||||
function Get(V: Variable) return Item_Type is
|
||||
begin
|
||||
return V.History.First_Element;
|
||||
end Get;
|
||||
|
||||
-- number of items in history (including the current one)
|
||||
function Defined(V: Variable) return Natural is
|
||||
begin
|
||||
return (1 + V.History.Last_Index) - V.History.First_Index;
|
||||
end Defined;
|
||||
|
||||
-- non-destructively search
|
||||
function Peek(V: Variable; Generation: Natural := 1) return Item_Type is
|
||||
Index: Positive := V.History.First_Index + Generation;
|
||||
begin
|
||||
if Index > V.History.Last_Index then
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
return V.History.Element(Index);
|
||||
end Peek;
|
||||
|
||||
procedure Undo(V: in out Variable) is
|
||||
begin
|
||||
V.History.Delete_First;
|
||||
end Undo;
|
||||
|
||||
end History_Variables;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
with Ada.Text_IO, History_Variables;
|
||||
|
||||
procedure Test_History is
|
||||
|
||||
package Int_With_Hist is new History_Variables(Integer);
|
||||
|
||||
-- define a history variable
|
||||
I: Int_With_Hist.Variable;
|
||||
|
||||
Sum: Integer := 0;
|
||||
|
||||
begin
|
||||
|
||||
-- assign three values
|
||||
I.Set(3);
|
||||
I.Set(I.Get + 4);
|
||||
I.Set(9);
|
||||
|
||||
-- non-destructively display the history
|
||||
for N in reverse 0 .. I.Defined-1 loop
|
||||
Ada.Text_IO.Put(Integer'Image(I.Peek(N)));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
|
||||
-- recall the three values
|
||||
while I.Defined > 0 loop
|
||||
Sum := Sum + I.Get;
|
||||
I.Undo;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(Integer'Image(Sum));
|
||||
|
||||
end Test_History;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
with Ada.Text_IO, History_Variables;
|
||||
|
||||
procedure Test_History is
|
||||
|
||||
package Str_With_Hist is new History_Variables(String);
|
||||
|
||||
-- define a history variable
|
||||
S: Str_With_Hist.Variable;
|
||||
|
||||
Sum: Integer := 0;
|
||||
|
||||
begin
|
||||
|
||||
-- assign three values
|
||||
S.Set("one");
|
||||
S.Set(S.Get & S.Get); --"oneone"
|
||||
S.Set("three");
|
||||
|
||||
-- non-destructively display the history
|
||||
for N in reverse 0 .. S.Defined-1 loop
|
||||
Ada.Text_IO.Put(S.Peek(Generation => N) &" ");
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
|
||||
-- recall the three values
|
||||
while S.Defined > 0 loop
|
||||
Sum := Sum + S.Get'Length;
|
||||
S.Undo;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(Integer'Image(Sum));
|
||||
|
||||
end Test_History;
|
||||
Loading…
Add table
Add a link
Reference in a new issue