agpl_1.0.0_b5da3320/src/agpl-streams-filter.adb

 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
 

--  Abstract class; A filter stream takes an access to a back stream from
--  which it can read/write, performing some extra operation/filtering if
--  needed.

with Agpl.Exceptions;

package body Agpl.Streams.Filter is

   ------------------------------------------------------------------------
   -- Create                                                             --
   ------------------------------------------------------------------------
   --  The default creation procedure assigns the back filter to the stream.
   procedure Create (
      This : in out Stream_Type;
      Back : access Ada.Streams.Root_Stream_Type'Class) is
   begin
      This.Back := Agpl.Streams.Stream_Access (Back);
   end Create;

   ------------------------------------------------------------------------
   -- Read                                                               --
   ------------------------------------------------------------------------
   procedure Read (
      This : in out Stream_Type;
      Item :    out Ada.Streams.Stream_Element_Array;
      Last :    out Ada.Streams.Stream_Element_Offset)
   is
   begin
      Ada.Streams.Read (This.Back.all, Item, Last);
   end Read;

   ------------------------------------------------------------------------
   -- Write                                                              --
   ------------------------------------------------------------------------
   procedure Write (
      This : in out Stream_Type;
      Item : in     Ada.Streams.Stream_Element_Array) is
   begin
      Ada.Streams.Write (This.Back.all, Item);
   end Write;

   ------------------------------------------------------------------------
   -- Prefetch                                                           --
   ------------------------------------------------------------------------
   --  A "pull" procedure to get data into de filter from the "read" end,
   --  but without needing the data to be actually read from the filter.
   --  Unimplemented for the default filter. (It hasn't caching capabilities).
   procedure Prefetch (
      This  : in out Stream_Type;
      Count : in     Stream_Element_Count)
   is
      pragma Unreferenced (This);
      pragma Unreferenced (Count);
   begin
      raise Exceptions.Unimplemented;
   end Prefetch;

   ------------------------------------------------------------------------
   -- Available_Read                                                     --
   ------------------------------------------------------------------------
   --  Unlimited
   function Available_Read (This : in Stream_Type)
      return Stream_Element_Count
   is
   pragma Unreferenced (This);
   begin
      return Stream_Element_Count'Last;
   end Available_Read;

   ------------------------------------------------------------------------
   -- Available_Write                                                    --
   ------------------------------------------------------------------------
   --  Unlimited
   function Available_Write (This: in Stream_Type)
      return Stream_Element_Count is
      pragma Unreferenced (This);
   begin
      return Stream_Element_Count'Last;
   end Available_Write;

end Agpl.Streams.Filter;