1--  This file is covered by the Internet Software Consortium (ISC) License
2--  Reference: ../../License.txt
3
4with Ada.Characters.Handling;
5
6package body AdaBase.Results.Sets is
7
8   package ACH renames Ada.Characters.Handling;
9
10   --------------
11   --  column  --
12   --------------
13   function column (row : Datarow; index : Positive) return ARF.Std_Field is
14   begin
15      if index > Natural (row.crate.Length) then
16         raise COLUMN_DOES_NOT_EXIST with "Column" & index'Img &
17           " requested, but only" & row.crate.Length'Img & " columns present.";
18      end if;
19      return row.crate.Element (Index => index);
20   end column;
21
22
23   --------------
24   --  column  --
25   --------------
26   function column (row : Datarow; heading : String) return ARF.Std_Field
27   is
28      use type heading_map.Cursor;
29      cursor : heading_map.Cursor;
30      index  : Positive;
31      headup : String := ACH.To_Upper (heading);
32   begin
33      cursor := row.map.Find (Key => headup);
34      if cursor = heading_map.No_Element then
35         raise COLUMN_DOES_NOT_EXIST with
36           "There is no column named '" & headup & "'.";
37      end if;
38      index := heading_map.Element (Position => cursor);
39      return row.crate.Element (Index => index);
40   end column;
41
42
43   -------------
44   --  count  --
45   -------------
46   function count  (row : Datarow) return Natural is
47   begin
48      return Natural (row.crate.Length);
49   end count;
50
51
52   ----------------------
53   --  data_exhausted  --
54   ----------------------
55   function data_exhausted (row : Datarow) return Boolean is
56   begin
57      return row.done;
58   end data_exhausted;
59
60
61   --------------------
62   --  Same_Strings  --
63   --------------------
64   function Same_Strings (S, T : String) return Boolean is
65   begin
66      return S = T;
67   end Same_Strings;
68
69
70   ------------
71   --  push  --
72   ------------
73   procedure push (row        : out Datarow;
74                   heading    : String;
75                   field      : ARF.Std_Field;
76                   last_field : Boolean := False)
77   is
78   begin
79      if row.locked then
80         raise CONSTRUCTOR_DO_NOT_USE with "The push method is not for you.";
81      end if;
82
83      if last_field then
84         row.locked := True;
85      end if;
86
87      row.crate.Append (New_Item => field);
88      row.map.Insert (Key      => ACH.To_Upper (heading),
89                      New_Item => row.crate.Last_Index);
90   end push;
91
92
93end AdaBase.Results.Sets;
94