summaryrefslogtreecommitdiff
path: root/src/fltk-environment.ads
blob: 4bb807b1fbe58f40ec1567bc0dffd54553586b9a (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344


--  Programmed by Jedidiah Barber
--  Released into the public domain


with

    Interfaces;

private with

    Interfaces.C;


package FLTK.Environment is


    type Database is new Wrapper with private;

    type Database_Reference (Data : not null access Database'Class) is
        limited null record with Implicit_Dereference => Data;

    type Pref_Group is new Wrapper with private;

    type Pref_Group_Reference (Data : not null access Pref_Group'Class) is
        limited null record with Implicit_Dereference => Data;

    type Scope is (Global, User);

    type Binary_Data is array (Positive range <>) of Interfaces.Unsigned_8;


    Preference_Error : exception;




    function New_UUID
        return String;




    package Forge is

        function From_Filesystem
               (Directory, Vendor, Application : in String)
            return Database;

        function From_Scope
               (Extent              : in Scope;
                Vendor, Application : in String)
            return Database;

        function Root
               (From : in Database)
            return Pref_Group'Class;

        function In_Memory
               (Name : in String)
            return Pref_Group;

        function By_Name
               (From : in Pref_Group;
                Name : in String)
            return Pref_Group'Class;

        function By_Index
               (From  : in Pref_Group;
                Index : in Positive)
            return Pref_Group'Class;

    end Forge;




    procedure Flush
           (This : in Database);

    function Userdata_Path
           (This : in Database)
        return String;




    procedure Delete_Entry
           (This : in out Pref_Group;
            Key  : in     String)
    with Post => This.Key_Exists (Key) = False;

    procedure Delete_All_Entries
           (This : in out Pref_Group)
    with Post => This.Number_Of_Entries = 0;

    procedure Delete_Group
           (This : in out Pref_Group;
            Name : in     String)
    with Post => This.Group_Exists (Name) = False;

    procedure Delete_All_Groups
           (This : in out Pref_Group)
    with Post => This.Number_Of_Groups = 0;

    procedure Clear
           (This : in out Pref_Group)
    with Post => This.Number_Of_Entries = 0 and
            This.Number_Of_Groups = 0;




    function Number_Of_Entries
           (This : in Pref_Group)
        return Natural;

    function Entry_Key
           (This  : in Pref_Group;
            Index : in Positive)
        return String
    with Pre => Index in 1 .. This.Number_Of_Entries;

    function Key_Exists
           (This : in Pref_Group;
            Key  : in String)
        return Boolean;

    function Value_Size
           (This : in Pref_Group;
            Key  : in String)
        return Natural;




    function Number_Of_Groups
           (This : in Pref_Group)
        return Natural;

    function Group_Name
           (This  : in Pref_Group;
            Index : in Positive)
        return String
    with Pre => Index in 1 .. This.Number_Of_Groups;

    function Group_Exists
           (This : in Pref_Group;
            Name : in String)
        return Boolean;




    function At_Name
           (This : in Pref_Group)
        return String;

    function At_Path
           (This : in Pref_Group)
        return String;




    function Get
           (This : in Pref_Group;
            Key  : in String)
        return Integer;

    function Get
           (This    : in Pref_Group;
            Key     : in String;
            Default : in Integer)
        return Integer;

    function Get
           (This : in Pref_Group;
            Key  : in String)
        return Float;

    function Get
           (This    : in Pref_Group;
            Key     : in String;
            Default : in Float)
        return Float;

    function Get
           (This : in Pref_Group;
            Key  : in String)
        return Long_Float;

    function Get
           (This    : in Pref_Group;
            Key     : in String;
            Default : in Long_Float)
        return Long_Float;

    function Get
           (This : in Pref_Group;
            Key  : in String)
        return String;

    function Get
           (This    : in Pref_Group;
            Key     : in String;
            Default : in String)
        return String;

    function Get
           (This       : in Pref_Group;
            Key        : in String;
            Default    : in String;
            Max_Length : in Natural)
        return String
    with Post => Get'Result'Length <= Max_Length;

    function Get
           (This : in Pref_Group;
            Key  : in String)
        return Binary_Data;

    function Get
           (This    : in Pref_Group;
            Key     : in String;
            Default : in Binary_Data)
        return Binary_Data;

    function Get
           (This       : in Pref_Group;
            Key        : in String;
            Default    : in Binary_Data;
            Max_Length : in Natural)
        return Binary_Data
    with Post => Get'Result'Length <= Max_Length;




    procedure Set
           (This  : in out Pref_Group;
            Key   : in     String;
            Value : in     Integer)
    with Post => This.Key_Exists (Key);

    procedure Set
           (This  : in out Pref_Group;
            Key   : in     String;
            Value : in     Float)
    with Post => This.Key_Exists (Key);

    procedure Set
           (This      : in out Pref_Group;
            Key       : in     String;
            Value     : in     Float;
            Precision : in     Natural)
    with Post => This.Key_Exists (Key);

    procedure Set
           (This  : in out Pref_Group;
            Key   : in     String;
            Value : in     Long_Float)
    with Post => This.Key_Exists (Key);

    procedure Set
           (This      : in out Pref_Group;
            Key       : in     String;
            Value     : in     Long_Float;
            Precision : in     Natural)
    with Post => This.Key_Exists (Key);

    procedure Set
           (This  : in out Pref_Group;
            Key   : in     String;
            Value : in     String)
    with Post => This.Key_Exists (Key);

    procedure Set
           (This  : in out Pref_Group;
            Key   : in     String;
            Value : in     Binary_Data)
    with Post => This.Key_Exists (Key);


private


    type Database is new Wrapper with null record;

    overriding procedure Finalize
           (This : in out Database);


    type Pref_Group is new Wrapper with record
        Root_Ptr : Storage.Integer_Address := Null_Pointer;
    end record;

    overriding procedure Finalize
           (This : in out Pref_Group);


    pragma Convention (C, Binary_Data);
    pragma Pack (Binary_Data);
    for Binary_Data'Component_Size use Interfaces.C.CHAR_BIT;


    pragma Inline (New_UUID);

    pragma Inline (Flush);

    pragma Inline (Delete_Entry);
    pragma Inline (Delete_All_Entries);
    pragma Inline (Delete_Group);
    pragma Inline (Delete_All_Groups);
    pragma Inline (Clear);

    pragma Inline (Number_Of_Entries);
    pragma Inline (Entry_Key);
    pragma Inline (Key_Exists);
    pragma Inline (Value_Size);

    pragma Inline (Number_Of_Groups);
    pragma Inline (Group_Name);
    pragma Inline (Group_Exists);

    pragma Inline (At_Name);
    pragma Inline (At_Path);

    pragma Inline (Set);


    function To_Cint
           (Extent : in Scope)
        return Interfaces.C.int;

    function To_Scope
           (Num : in Interfaces.C.int)
        return Scope;


end FLTK.Environment;