summaryrefslogtreecommitdiff
path: root/src/deckdata-io.ads
blob: acdcda33c4ff673db2b4715af97b98368bcd90e0 (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


--  This source is licensed under the Sunset License v1.0


private with

    Ada.Finalization,
    SQLite3;


package Deckdata.IO is


    use type SU.Unbounded_String;


    type Deck_Handle is limited private;


    function Matches
           (Models : in Model_Map;
            Notes  : in Note_Vector)
        return Boolean;


    procedure Read_Media_Collection
           (Filename  : in     String;
            Media     :    out Media_Collection);


    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_Map)
    with Pre => Is_Open (Deck);

    procedure Query_Notes
           (Deck  : in out Deck_Handle;
            Notes :    out Note_Vector)
    with Pre => Is_Open (Deck);


    procedure Write_CSV
           (Directory : in String;
            Basename  : in String;
            Models    : in Model_Map;
            Notes     : in Note_Vector;
            Overwrite : in Boolean := False)
    with Pre => Matches (Models, Notes);

    procedure Write_FMD
           (Directory : in String;
            Basename  : in String;
            Models    : in Model_Map;
            Notes     : in Note_Vector;
            Media     : in Media_Collection;
            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 Deckdata.IO;