Natools

Check-in [a2fd0fbfb6]
Login
Overview
Comment:s_expressions-atom_buffers: rename Read procedure to Peek, to make room for stream primitives
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a2fd0fbfb64d870172de7e99df477b4920e3c239
User & Date: nat on 2014-08-29 20:37:38
Other Links: manifest | tags
Context
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
2014-08-27
19:43
reference_tests-pools: new test suite for reference pools check-in: 2fa0bb02a5 user: nat tags: trunk
Changes

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

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
         Process.all (Null_Atom);
      else
         Process.all (Buffer.Ref.Query.Data.all (1 .. Buffer.Used));
      end if;
   end Query;


   procedure Read
     (Buffer : in Atom_Buffer;
      Data : out Atom;
      Length : out Count)
   is
      Transmit : constant Count := Count'Min (Data'Length, Buffer.Used);
   begin
      Length := Buffer.Used;

      if Buffer.Ref.Is_Empty then
         pragma Assert (Length = 0);
         null;
      else
         Data (Data'First .. Data'First + Transmit - 1)
           := Buffer.Ref.Query.Data.all (1 .. Transmit);
      end if;
   end Read;


   function Element (Buffer : Atom_Buffer; Position : Count) return Octet is
   begin
      return Buffer.Ref.Query.Data.all (Position);
   end Element;








|















|







169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
         Process.all (Null_Atom);
      else
         Process.all (Buffer.Ref.Query.Data.all (1 .. Buffer.Used));
      end if;
   end Query;


   procedure Peek
     (Buffer : in Atom_Buffer;
      Data : out Atom;
      Length : out Count)
   is
      Transmit : constant Count := Count'Min (Data'Length, Buffer.Used);
   begin
      Length := Buffer.Used;

      if Buffer.Ref.Is_Empty then
         pragma Assert (Length = 0);
         null;
      else
         Data (Data'First .. Data'First + Transmit - 1)
           := Buffer.Ref.Query.Data.all (1 .. Transmit);
      end if;
   end Peek;


   function Element (Buffer : Atom_Buffer; Position : Count) return Octet is
   begin
      return Buffer.Ref.Query.Data.all (Position);
   end Element;

Modified src/natools-s_expressions-atom_buffers.ads from [5653ca8412] to [940d53e029].

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

   function Length (Buffer : Atom_Buffer) return Count;
   function Capacity (Buffer : Atom_Buffer) return Count;
   function Data (Buffer : Atom_Buffer) return Atom;
   procedure Query
     (Buffer : in Atom_Buffer;
      Process : not null access procedure (Data : in Atom));
   procedure Read
     (Buffer : in Atom_Buffer;
      Data : out Atom;
      Length : out Count);
   function Element (Buffer : Atom_Buffer; Position : Count) return Octet;
      --  Accessors to the whole buffer as an Atom

   procedure Pop (Buffer : in out Atom_Buffer; Data : out Octet);







|







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

   function Length (Buffer : Atom_Buffer) return Count;
   function Capacity (Buffer : Atom_Buffer) return Count;
   function Data (Buffer : Atom_Buffer) return Atom;
   procedure Query
     (Buffer : in Atom_Buffer;
      Process : not null access procedure (Data : in Atom));
   procedure Peek
     (Buffer : in Atom_Buffer;
      Data : out Atom;
      Length : out Count);
   function Element (Buffer : Atom_Buffer; Position : Count) return Octet;
      --  Accessors to the whole buffer as an Atom

   procedure Pop (Buffer : in out Atom_Buffer; Data : out Octet);

Modified src/natools-s_expressions-parsers.adb from [81bb40d722] to [5ca94300aa].

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
      Data : out Atom;
      Length : out Count) is
   begin
      if Self.Locked or Self.Latest /= Events.Add_Atom then
         raise Program_Error;
      end if;

      Self.Buffer.Read (Data, Length);
   end Read_Atom;


   overriding procedure Next
     (Self : in out Parser;
      Event : out Events.Event)
   is







|







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
      Data : out Atom;
      Length : out Count) is
   begin
      if Self.Locked or Self.Latest /= Events.Add_Atom then
         raise Program_Error;
      end if;

      Self.Buffer.Peek (Data, Length);
   end Read_Atom;


   overriding procedure Next
     (Self : in out Parser;
      Event : out Events.Event)
   is

Modified tests/natools-s_expressions-atom_buffers-tests.adb from [af14b7fc76] to [31a69a9e16].

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
246
247
248
249
250
251
252
            end if;
         end;

         declare
            Retrieved : Atom (10 .. 310);
            Length : Count;
         begin
            Buffer.Read (Retrieved, Length);
            if Length /= Data'Length
              or else Retrieved (10 .. Length + 9) /= Data
            then
               Report.Item (Name, NT.Fail);
               Report.Info ("Read into an existing buffer");
               Report.Info ("Length returned" & Count'Image (Length)
                 & ", expected" & Count'Image (Data'Length));
               Test_Tools.Dump_Atom
                 (Report, Retrieved (10 .. Length + 9), "Found");
               Test_Tools.Dump_Atom (Report, Data, "Expected");
               return;
            end if;
         end;

         declare
            Retrieved : Atom (20 .. 50);
            Length : Count;
         begin
            Buffer.Read (Retrieved, Length);
            if Length /= Data'Length or else Retrieved /= Data (0 .. 30) then
               Report.Item (Name, NT.Fail);
               Report.Info ("Read into a buffer too small");
               Report.Info ("Length returned" & Count'Image (Length)
                 & ", expected" & Count'Image (Data'Length));
               Test_Tools.Dump_Atom (Report, Retrieved, "Found");
               Test_Tools.Dump_Atom (Report, Data (0 .. 30), "Expected");
               return;
            end if;
         end;







|




|













|


|







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
246
247
248
249
250
251
252
            end if;
         end;

         declare
            Retrieved : Atom (10 .. 310);
            Length : Count;
         begin
            Buffer.Peek (Retrieved, Length);
            if Length /= Data'Length
              or else Retrieved (10 .. Length + 9) /= Data
            then
               Report.Item (Name, NT.Fail);
               Report.Info ("Peek into an existing buffer");
               Report.Info ("Length returned" & Count'Image (Length)
                 & ", expected" & Count'Image (Data'Length));
               Test_Tools.Dump_Atom
                 (Report, Retrieved (10 .. Length + 9), "Found");
               Test_Tools.Dump_Atom (Report, Data, "Expected");
               return;
            end if;
         end;

         declare
            Retrieved : Atom (20 .. 50);
            Length : Count;
         begin
            Buffer.Peek (Retrieved, Length);
            if Length /= Data'Length or else Retrieved /= Data (0 .. 30) then
               Report.Item (Name, NT.Fail);
               Report.Info ("Peek into a buffer too small");
               Report.Info ("Length returned" & Count'Image (Length)
                 & ", expected" & Count'Image (Data'Length));
               Test_Tools.Dump_Atom (Report, Retrieved, "Found");
               Test_Tools.Dump_Atom (Report, Data (0 .. 30), "Expected");
               return;
            end if;
         end;
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
            return;
         end if;

         declare
            Retrieved : Atom (1 .. 10);
            Length : Count;
         begin
            Buffer.Read (Retrieved, Length);
            if Length /= 0 then
               Report.Item (Name, NT.Fail);
               Report.Info ("Read into an existing buffer");
               Report.Info ("Length returned" & Count'Image (Length)
                 & ", expected 0");
               return;
            end if;
         end;

         declare







|


|







296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
            return;
         end if;

         declare
            Retrieved : Atom (1 .. 10);
            Length : Count;
         begin
            Buffer.Peek (Retrieved, Length);
            if Length /= 0 then
               Report.Item (Name, NT.Fail);
               Report.Info ("Peek into an existing buffer");
               Report.Info ("Length returned" & Count'Image (Length)
                 & ", expected 0");
               return;
            end if;
         end;

         declare