Natools

Check-in [d6e43fe336]
Login
Overview
Comment:s_expressions-file_readers: add an atom-reference read function
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d6e43fe336468d08771d3128e862cfae084e45fd
User & Date: nat on 2014-07-13 14:27:31
Other Links: manifest | tags
Context
2014-07-14
19:04
s_expressions-file_rw_tests: test the new atom-reference reader check-in: 88f1a31b31 user: nat tags: trunk
2014-07-13
14:27
s_expressions-file_readers: add an atom-reference read function check-in: d6e43fe336 user: nat tags: trunk
2014-07-12
16:08
reference_tests: use the new access-based constructors, to reach full coverage again check-in: 2d7c2f8e09 user: nat tags: trunk
Changes

Modified src/natools-s_expressions-file_readers.adb from [ca56f3defe] to [ed6165cafb].

109
110
111
112
113
114
115













116
117
118
119
120
121
122
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135







+
+
+
+
+
+
+
+
+
+
+
+
+







   begin
      Stream_IO.Set_Index (Object.File, 1);
      Stream_IO.Read (Object.File, Result, Last);
      pragma Assert (Last = Result'Last);
      return Result;
   end Read;


   function Read (Object : Atom_Reader) return Atom_Refs.Reference is
      Length : constant Count := Object.Length;
      Result : constant Atom_Refs.Reference
        := Atom_Refs.Create (new Atom (1 .. Length));
      Last : Count;
   begin
      Stream_IO.Set_Index (Object.File, 1);
      Stream_IO.Read (Object.File, Result.Update.Data.all, Last);
      pragma Assert (Last = Length);
      return Result;
   end Read;


   procedure Read
     (Object : in Atom_Reader;
      Data : out Atom;
      Length : out Count) is
   begin
      Stream_IO.Set_Index (Object.File, 1);

Modified src/natools-s_expressions-file_readers.ads from [412fa61073] to [ee144af528].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







+







------------------------------------------------------------------------------
-- Natools.S_Expressions.File_Readers provides types that read into files   --
-- on disk (using Stream_IO) and expose their data as S-expressions or as   --
-- atoms.                                                                   --
------------------------------------------------------------------------------

with Natools.S_Expressions.Atom_Buffers;
with Natools.S_Expressions.Atom_Refs;
with Natools.S_Expressions.Lockable;

private with Ada.Finalization;
private with Ada.Streams.Stream_IO;
private with Natools.S_Expressions.Parsers;

package Natools.S_Expressions.File_Readers is
53
54
55
56
57
58
59



60
61
62
63
64
65
66
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70







+
+
+








   function Length (Object : Atom_Reader) return Count;
      --  Return the file length

   function Read (Object : Atom_Reader) return Atom;
      --  Read the whole file and return it as a single atom

   function Read (Object : Atom_Reader) return Atom_Refs.Reference;
      --  Read the whole file to memory and return a reference to the data

   procedure Read
     (Object : in Atom_Reader;
      Data : out Atom;
      Length : out Count);
      --  Read the whole file and store it in Data, along with its Length.
      --  If Data is too small, only the file prefix is read.