blob: a027727534314a9d1d72e89aeb5dd9f6ea684893 (
plain)
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
|
with
Ada.Strings.Unbounded,
Ada.Text_IO,
CSV;
package body Bundles.Containers is
package SU renames Ada.Strings.Unbounded;
procedure Read_Bundles
(Filename : in String;
Result : out Bundle_Collection)
is
package My_CSV is new CSV;
use Ada.Text_IO;
use type Candidates.CandidateID;
use type Bundle_Vectors.Vector;
Input_File : File_Type;
Current_Record : My_CSV.CSV_Record;
Current_Prefs : Given_Prefs.Preference_Array;
begin
Result := (others => Bundle_Vectors.Empty_Vector & Empty_Bundle);
Open (Input_File, In_File, Filename);
while not End_Of_File (Input_File) loop
Current_Record := My_CSV.Parse_Line (Get_Line (Input_File));
if Integer (Current_Record.Length) > 0 then
Current_Prefs := Given_Prefs.Parse_Preferences
(SU.To_String (Current_Record.Last_Element));
if Current_Prefs (Given_Prefs.Preference_Range'First) /=
Candidates.No_Candidate
then
Result (Candidate_Range (Current_Prefs (Given_Prefs.Preference_Range'First))).Reference
(1).Papers.Append (Current_Prefs);
end if;
end if;
end loop;
Close (Input_File);
for B of Result loop
if B.Reference (1) = Empty_Bundle then
B.Delete (1);
end if;
end loop;
end Read_Bundles;
end Bundles.Containers;
|