Natools

Check-in [a209bfec77]
Login
Overview
Comment:s_expressions-atom_buffers: add a stream interface to atom buffers
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a209bfec77a9f91c191cc3ff91bc0d0fbec446e9
User & Date: nat on 2014-08-30 20:33:48
Other Links: manifest | tags
Context
2014-08-31
14:45
s_expressions-atom_buffers-tests: add a test for the new stream interface check-in: 3c45cf38af user: nat tags: trunk
2014-08-30
20:33
s_expressions-atom_buffers: add a stream interface to atom buffers check-in: a209bfec77 user: nat tags: trunk
2014-08-29
20:37
s_expressions-atom_buffers: rename Read procedure to Peek, to make room for stream primitives check-in: a2fd0fbfb6 user: nat tags: trunk
Changes

Modified src/natools-s_expressions-atom_buffers.adb from [f4f287ab4e] to [34dcf49f16].

214
215
216
217
218
219
220
























221


   procedure Soft_Reset (Buffer : in out Atom_Buffer) is
   begin
      Buffer.Used := 0;
   end Soft_Reset;

























end Natools.S_Expressions.Atom_Buffers;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245


   procedure Soft_Reset (Buffer : in out Atom_Buffer) is
   begin
      Buffer.Used := 0;
   end Soft_Reset;


   overriding procedure Write
     (Buffer : in out Atom_Buffer;
      Item : in Ada.Streams.Stream_Element_Array)
     renames Append;


   overriding procedure Read
     (Buffer : in out Atom_Buffer;
      Item : out Ada.Streams.Stream_Element_Array;
      Last : out Ada.Streams.Stream_Element_Offset) is
   begin
      if Item'Length < Buffer.Used then
         Last := Item'Last;
         Item := Buffer.Ref.Query.Data.all (1 .. Item'Length);
         Buffer.Used := Buffer.Used - Item'Length;
      else
         Last := Item'First + Buffer.Used - 1;
         Item (Item'First .. Last)
           := Buffer.Ref.Query.Data.all (1 .. Buffer.Used);
         Buffer.Used := 0;
      end if;
   end Read;

end Natools.S_Expressions.Atom_Buffers;

Modified src/natools-s_expressions-atom_buffers.ads from [940d53e029] to [6608c95221].

23
24
25
26
27
28
29
30
31
32








33
34
35
36
37
38
39
------------------------------------------------------------------------------

with Natools.S_Expressions.Atom_Refs;

package Natools.S_Expressions.Atom_Buffers is
   pragma Preelaborate (Atom_Buffers);

   type Atom_Buffer is tagged limited private;
   pragma Preelaborable_Initialization (Atom_Buffer);









   procedure Preallocate (Buffer : in out Atom_Buffer; Length : in Count);
      --  Preallocate enough memory to append Length octets without
      --  any further allocation.

   procedure Append (Buffer : in out Atom_Buffer; Data : in Atom);
   procedure Append (Buffer : in out Atom_Buffer; Data : in Octet);
      --  Append Data after the end of Buffer







|


>
>
>
>
>
>
>
>







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
------------------------------------------------------------------------------

with Natools.S_Expressions.Atom_Refs;

package Natools.S_Expressions.Atom_Buffers is
   pragma Preelaborate (Atom_Buffers);

   type Atom_Buffer is new Ada.Streams.Root_Stream_Type with private;
   pragma Preelaborable_Initialization (Atom_Buffer);

   overriding procedure Write
     (Buffer : in out Atom_Buffer;
      Item : in Ada.Streams.Stream_Element_Array);
   overriding procedure Read
     (Buffer : in out Atom_Buffer;
      Item : out Ada.Streams.Stream_Element_Array;
      Last : out Ada.Streams.Stream_Element_Offset);

   procedure Preallocate (Buffer : in out Atom_Buffer; Length : in Count);
      --  Preallocate enough memory to append Length octets without
      --  any further allocation.

   procedure Append (Buffer : in out Atom_Buffer; Data : in Atom);
   procedure Append (Buffer : in out Atom_Buffer; Data : in Octet);
      --  Append Data after the end of Buffer
67
68
69
70
71
72
73
74
75
76
77
78
79
      --  Clear buffer and release internal memory

   procedure Soft_Reset (Buffer : in out Atom_Buffer);
      --  Clear buffer keeping internal memory

private

   type Atom_Buffer is tagged limited record
      Ref : Atom_Refs.Reference;
      Available, Used : Count := 0;
   end record;

end Natools.S_Expressions.Atom_Buffers;







|





75
76
77
78
79
80
81
82
83
84
85
86
87
      --  Clear buffer and release internal memory

   procedure Soft_Reset (Buffer : in out Atom_Buffer);
      --  Clear buffer keeping internal memory

private

   type Atom_Buffer is new Ada.Streams.Root_Stream_Type with record
      Ref : Atom_Refs.Reference;
      Available, Used : Count := 0;
   end record;

end Natools.S_Expressions.Atom_Buffers;