dir_iterators_0.0.4_88741e32/src/dir_iterators-ancestor.adb

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

package body Dir_Iterators.Ancestor is
    package ASU renames Ada.Strings.Unbounded;

    function Iterate
       (Tree : Ancestor_Dir_Walk)
        return Ancestor_Dir_Iterator_Interfaces.Forward_Iterator'Class is
    begin
        return It : Ancestor_Dir_Iterator do
            It.Start := Tree.Start;
        end return;
    end Iterate;

    function Walk (Dir : String) return Ancestor_Dir_Walk is
    begin
        return ADW : Ancestor_Dir_Walk do
            ADW.Start := ASU.To_Unbounded_String (Dir);
        end return;
    end Walk;

    function Has_Element (Position : Cursor) return Boolean is
        Parent : ASU.Unbounded_String;
    begin
        pragma Unreferenced (Parent);
        Parent :=
           ASU.To_Unbounded_String
              (Ada.Directories.Containing_Directory
                  (ASU.To_String (Position.Current)));
        return True;
    exception
        when others =>
            return False;
    end Has_Element;

    overriding function First (Object : Ancestor_Dir_Iterator) return Cursor is
    begin
        return Cursor'(Current => Object.Start);
    end First;

    overriding function Next
       (It : Ancestor_Dir_Iterator; Position : Cursor) return Cursor is
    begin
        pragma Unreferenced (It);
        return
           Cursor'
              (Current =>
                  ASU.To_Unbounded_String
                     (Ada.Directories.Containing_Directory
                         (ASU.To_String(Position.Current))));
    end Next;

    function Element_Value
       (Tree : Ancestor_Dir_Walk; Position : Cursor) return String is
    begin
        pragma Unreferenced (Tree);
        return ASU.To_String(Position.Current);
    end Element_Value;

end Dir_Iterators.Ancestor;