Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.69 KB | None | 0 0
  1. --table ads file
  2. generic
  3.     type Item is private;
  4.     type Table_Array is array (Positive range <>) of Item;
  5. package Table is
  6.     type Table_Type (Capacity: Positive) is limited private;     
  7.     function Size(T: Table_Type) return Natural;
  8.     function Get_Table(T: Table_Type) return Table_Array;
  9.     procedure Insert(T: in out Table_Type; I: in Item);
  10.     generic
  11.         with function Op( A: in Item ) return Boolean;
  12.     procedure Table_Where (T: in Table_Type; TA: out Table_Array; N: out Natural);
  13.     generic
  14.         with function "<" ( A, B: Item ) return Boolean is <>;
  15.     procedure Table_Sort ( T: in out Table_Type);
  16. private
  17.     type Table_Type(Capacity: Positive ) is record
  18.         datas: Table_Array(1..Capacity);
  19.         size: Natural := 0;
  20.     end record;
  21. end Table;
  22.  
  23. --table adb file
  24.  
  25. procedure Table_Where (T: in Table_Type; TA: out Table_Array; N: out Natural) is
  26. begin
  27.     N:=0;
  28.     for I in T'Range loop
  29.         if Op(T(I)) then
  30.             N:= N + 1;
  31.             TA(N):= T(I);
  32.         end if;
  33.     end loop;
  34. end;
  35.  
  36. procedure Table_Sort ( T: in out Table_Type) is
  37.        procedure Sort is new TableSort(Item, Index, Table_Array,"<");
  38. begin
  39.     Sort(T);
  40. end;
  41.  
  42. --selects ads file
  43.  
  44. with Table;
  45. generic
  46.     type OldItem is private;
  47.     type OldTable_Array is array (Positive range <>) of OldItem;
  48.     type NewItem is private;
  49.     type NewTable_Array is array (Positive range <>) of NewItem;
  50.     with package OldTable_Type is new Table(OldItem , OldTable_Array);
  51.     with package NewTable_Type is new Table(NewItem, NewTable_Array);
  52.     with function Transfer (I: in OldItem) return NewItem;
  53. procedure Selects ( IT: in In_Table; OT: out Out_Table);
  54.  
  55. --selects adb file
  56.  
  57. procedure Selects ( IT: in In_Table; OT: out Out_Table) is
  58. begin
  59.     OT := Transfer(IT);
  60. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement