Guest User

tupplespacepackage-realtupples.adb

a guest
May 11th, 2026
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 3.20 KB | None | 0 0
  1. pragma Ada_2022;
  2. with Ada.Unchecked_Deallocation;
  3. with Ada.Text_io;
  4. use Ada.text_io;
  5.  
  6. package body tupplespacepackage.RealTupples is
  7.     function Encode (I: Integer; Pos: Positive; A: String) return Integer_Positive_String_Tupple is (I,Pos,To_Unbounded_String(A));
  8.     function Encode (A, B: String) return String_String_Tupple is (String_String_Tupple'(To_Unbounded_String(A),To_Unbounded_String(B)));
  9.     procedure Decode (the_Tupple: Integer_Positive_String_Tupple; I: out Integer; Pos: out Positive; A: out Ada.Strings.Unbounded.Unbounded_String) is
  10.         use Ada.Strings.Unbounded;
  11.     begin
  12.         I := the_Tupple.I;
  13.         Pos := the_Tupple.Pos;
  14.         A := the_Tupple.A;
  15.     end Decode;
  16.     procedure Decode (the_Tupple: String_String_Tupple; A, B: out Ada.Strings.Unbounded.Unbounded_String) is
  17.         use Ada.Strings.Unbounded;
  18.     begin
  19.         A := the_Tupple.A;
  20.         B := the_Tupple.B;
  21.     end Decode;
  22.     procedure Copy_Into (A: Tupple'Class; B: out Integer_Positive_String_Tupple) is
  23.     begin
  24.         B := Integer_Positive_String_Tupple (A);
  25.     end Copy_Into;
  26.     procedure Copy_Into (A: Tupple'Class; B: out String_String_Tupple) is
  27.     begin
  28.         B := String_String_Tupple (A);
  29.     end Copy_Into;
  30.     protected body RealtuppleSpace is
  31.         procedure Matches (T: Tupple'Class; QueueAccess: out AccessToProtected)  is
  32.         begin
  33.             if not The_Map.Contains (T'Tag) then
  34.                 The_Map.Insert (Key => T'Tag, New_Item => new LockedQueue);
  35.             end if;
  36.             QueueAccess := The_Map.Element(T'Tag);
  37.         end Matches;
  38.         procedure Out_Operation (T: Tupple'Class) is
  39.             M: AccessToProtected;
  40.         begin
  41.             Matches (T, M);
  42.             M.Out_Operation (T);
  43.         end Out_Operation;
  44.         entry In_Operation (Result: out Tupple'Class) when True is
  45.             M: AccessToProtected;
  46.         begin
  47.             Matches (Result, M);
  48.             requeue M.In_Operation with abort;
  49.         end In_Operation;
  50.  
  51.         entry RD_Operation
  52.             (Result  : out Tupple'Class) when True is
  53.             M: AccessToProtected;
  54.         begin
  55.             Matches (Result, M);
  56.             requeue M.RD_Operation with abort;
  57.         end RD_Operation;
  58.  
  59.        procedure Inp_Operation
  60.          (Result  : out Tupple'Class) is
  61.             M: AccessToProtected;
  62.         begin
  63.             Matches (Result, M);
  64.             select
  65.                 M.In_Operation (Result);
  66.             else
  67.                 raise No_Immediate_Message;
  68.             end select;
  69.         end Inp_Operation;
  70.  
  71.         procedure RDP_Operation (Result  : out Tupple'Class) is
  72.             M: AccessToProtected;
  73.         begin
  74.             Matches (Result, M);
  75.             select
  76.                 M.RD_Operation (Result);
  77.             else
  78.                 raise No_Immediate_Message;
  79.             end select;
  80.         end RDP_Operation;
  81.     end RealtuppleSpace;
  82.  
  83.     protected body  LockedQueue is
  84.         procedure Out_Operation (T: Tupple'Class) is
  85.         begin
  86.             Put_line(T'Image);
  87.             PatternQueue.Prepend (new Tupple'Class'(T));
  88.         end Out_Operation;
  89.        
  90.         entry In_Operation (Result: out Tupple'Class) when not PatternQueue.Is_Empty is
  91.             procedure Free is new Ada.Unchecked_Deallocation (Tupple'Class, AccessToClass);
  92.             Var_To_Delete: AccessToClass := PatternQueue.Last_Element;
  93.         begin
  94.             Var_To_Delete.Copy_Into (Result);
  95.  
  96.             Free (Var_To_Delete);
  97.             PatternQueue.Delete_Last;
  98.         end In_Operation;
  99.  
  100.         entry RD_Operation (Result: out Tupple'Class) when not PatternQueue.Is_Empty is
  101.         begin
  102.             PatternQueue.Last_Element.Copy_Into (Result);
  103.         end RD_Operation;
  104.        
  105.     end LockedQueue;
  106.        
  107. end tupplespacepackage.RealTupples;
Advertisement
Add Comment
Please, Sign In to add comment