blob: 7121a37fb95e077eb06c29d5f4635157e7f4ce11 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
with
Ada.Containers.Vectors,
Ada.Containers.Ordered_Maps,
Ada.Strings.Unbounded;
private with
Ada.Finalization,
SQLite3;
package Deck_IO is
package SU renames Ada.Strings.Unbounded;
use type SU.Unbounded_String;
type Deck_Handle is limited private;
type Field_Ordinal is new Positive;
type Field_ID is new SU.Unbounded_String;
package Field_ID_Vectors is new Ada.Containers.Vectors
(Index_Type => Field_Ordinal,
Element_Type => Field_ID);
type Template is record
Question : Field_ID_Vectors.Vector;
Answer : Field_ID_Vectors.Vector;
end record;
package Template_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
Element_Type => Template);
type Model_ID is new SU.Unbounded_String;
type Model is record
Fields : Field_ID_Vectors.Vector;
Templates : Template_Vectors.Vector;
end record;
package Model_Maps is new Ada.Containers.Ordered_Maps
(Key_Type => Model_ID,
Element_Type => Model);
type Field is new SU.Unbounded_String;
package Field_Vectors is new Ada.Containers.Vectors
(Index_Type => Field_Ordinal,
Element_Type => Field);
type Note is record
Model : Model_ID;
Fields : Field_Vectors.Vector;
end record;
package Note_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
Element_Type => Note);
function Matches
(Models : in Model_Maps.Map;
Notes : in Note_Vectors.Vector)
return Boolean;
type Media_ID is new SU.Unbounded_String;
subtype Media_Name is SU.Unbounded_String;
package Media_Maps is new Ada.Containers.Ordered_Maps
(Key_Type => Media_ID,
Element_Type => Media_Name);
procedure Read_Media_Map
(Filename : in String;
Media_Map : out Media_Maps.Map);
procedure Open_Database
(Filename : in String;
Deck : in out Deck_Handle)
with Post => Is_Open (Deck);
function Is_Open
(Deck : in Deck_Handle)
return Boolean;
procedure Close_Database
(Deck : in out Deck_Handle)
with Post => not Is_Open (Deck);
procedure Query_Models
(Deck : in out Deck_Handle;
Models : out Model_Maps.Map)
with Pre => Is_Open (Deck);
procedure Query_Notes
(Deck : in out Deck_Handle;
Notes : out Note_Vectors.Vector)
with Pre => Is_Open (Deck);
procedure Write_CSV
(Directory : in String;
Basename : in String;
Models : in Model_Maps.Map;
Notes : in Note_Vectors.Vector;
Overwrite : in Boolean := False)
with Pre => Matches (Models, Notes);
procedure Write_FMD
(Directory : in String;
Basename : in String;
Models : in Model_Maps.Map;
Notes : in Note_Vectors.Vector;
Media : in Media_Maps.Map;
Overwrite : in Boolean := False)
with Pre => Matches (Models, Notes);
private
type Deck_Handle is new Ada.Finalization.Limited_Controlled with record
SQL_Handle : SQLite3.SQLite3_DB;
Status : SQLite3.Status_Code := SQLite3.SQLITE_OK;
Opened : Boolean := False;
Tempfile : SU.Unbounded_String := SU.To_Unbounded_String ("");
end record;
overriding
procedure Finalize
(This : in out Deck_Handle);
end Deck_IO;
|