rxada_0.1.1_dd9da799/dirx/src/dirx.ads

 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
with Ada.Directories;

with Rx.Std;

private with Rx.Tools.Shared_Data;

package DirX is

   -----------
   -- Types --
   -----------

   subtype Path is String;
   --  A Path can be either a folder, file, subpath, combination of those, etc.

   subtype Path_Observable is Rx.Std.Strings.Observable;

   type Name_Kinds is (Full_Name, Simple_Name);

   -----------------------
   -- Directory entries --
   -----------------------

   --  We need a nonlimited type to be able to use it with Rx, so this one
   --  encapsulates entries in Ada.Directories

   type Directory_Entry (<>) is tagged private;

   type Entry_Reference
     (The_Entry : access constant Ada.Directories.Directory_Entry_Type)
     is limited null record
     with Implicit_Dereference => The_Entry;

   function Get_Entry (This : Directory_Entry) return Entry_Reference;

   function Is_Directory (This : Directory_Entry) return Boolean;

private

   package AD renames Ada.Directories;

   use all type AD.File_Kind;

   type Entry_Access is access AD.Directory_Entry_Type;

   package Shared_Entries is new Rx.Tools.Shared_Data (AD.Directory_Entry_Type,
                                                       Entry_Access);

   type Directory_Entry is new Shared_Entries.Proxy with null record;

   ---------------
   -- Get_Entry --
   ---------------

   function Get_Entry (This : Directory_Entry) return Entry_Reference is
     (Entry_Reference'(The_Entry => Shared_Entries.Proxy (This).Get.Actual));

   ------------------
   -- Is_Directory --
   ------------------

   function Is_Directory (This : Directory_Entry) return Boolean is
     (AD.Kind (This.Get_Entry) = AD.Directory);

end DirX;