dir_iterators_0.0.4_88741e32/src/dir_iterators-ancestor.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
with Ada.Finalization;
with Ada.Iterator_Interfaces;
with Ada.Strings.Unbounded;

package Dir_Iterators.Ancestor is

    type Cursor is private;
    function Has_Element (Position : Cursor) return Boolean;

    package Ancestor_Dir_Iterator_Interfaces is new Ada.Iterator_Interfaces
        (Cursor => Cursor, Has_Element => Has_Element);

    type Ancestor_Dir_Iterator is
        new Ada.Finalization.Limited_Controlled and
            Ancestor_Dir_Iterator_Interfaces.Forward_Iterator with private;

    overriding function First (Object : Ancestor_Dir_Iterator) return Cursor;
    overriding function Next
        (It : Ancestor_Dir_Iterator; Position : Cursor) return Cursor;

    type Ancestor_Dir_Walk is tagged limited private with
        Default_Iterator  => Iterate,
        Iterator_Element  => String,
        Constant_Indexing => Element_Value;

    function Walk (Dir : String) return Ancestor_Dir_Walk;

    function Iterate
        (Tree : Ancestor_Dir_Walk)
         return Ancestor_Dir_Iterator_Interfaces.Forward_Iterator'Class;

    function Element_Value
        (Tree : Ancestor_Dir_Walk; Position : Cursor) return String;

private

    -- The base type that lets us use an iterator in a nice `for` loop.
    type Ancestor_Dir_Walk is tagged limited record
        Start : Ada.Strings.Unbounded.Unbounded_String;
    end record;

    type Ancestor_Dir_Iterator is new Ada.Finalization.Limited_Controlled and
        Ancestor_Dir_Iterator_Interfaces.Forward_Iterator with record
        Start : Ada.Strings.Unbounded.Unbounded_String;
    end record;

    type Cursor is record
        Current : Ada.Strings.Unbounded.Unbounded_String;
    end record;

end Dir_Iterators.Ancestor;