I'm trying to sort a collection of Ada.Directories.Directory_Entry (a
limited private type) by storing pointers to them in a Vector but am
having problems with accessibility rules.
Is it possible to do this?
Package Ada.Directories only has procedures that have "in out"/out
parameters for the Directory_Entry type, so I can't figure out how to
get a reference to each object as I run through the More_Entries/
Get_Next_Entry procedures.
Thanks,
Dale
---------------------------------------
-- Displays directory entries in increasing date/time order
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Containers.Vectors;
with Ada.Directories; use Ada.Directories;
with Ada.Calendar; use Ada.Calendar; -- for comparing
date/times
procedure List_By_Date is
type Dir_Entry_Ptr is access all Directory_Entry_Type;
package Dir_Vectors is new Ada.Containers.Vectors (Positive,
Dir_Entry_Ptr);
use Dir_Vectors;
DV : Vector;
begin
-- collect the entries
declare
Directory : constant Filter_Type := (true, false, false);
Ordinary_File : constant Filter_Type := (false, true, false);
Results : Search_Type; -- used to hold the result of a search
Directory_Entry : aliased Directory_Entry_Type;
begin
Start_Search ( Results,
Directory => Current_Directory,
Pattern => "", -- select all files
Filter => Directory or Ordinary_File
);
while More_Entries (Results) loop
Get_Next_Entry (Results, Directory_Entry);
DV.Append (Directory_Entry'access);
-- ******************************************************
-- this is of course incorrect, but how to get around it?
-- ******************************************************
end loop;
end;
-- sort the entries
declare
function My_Sorter (Left, Right : Dir_Entry_Ptr) return boolean
is
begin
return Ada.Directories.Modification_Time (Left.all) <
Ada.Directories.Modification_Time (Right.all);
end;
package Dir_Vector_Sorting is new Generic_Sorting (My_Sorter);
begin
Dir_Vector_Sorting.Sort (DV);
end;
-- display the entries
declare
procedure Display_Entry (C : Cursor)
is
Directory_Entry_Ptr : constant Dir_Entry_Ptr := Element (C);
begin
Put (Simple_Name (Directory_Entry_Ptr.all));
end;
begin
DV.iterate (Display_Entry'access);
end;
end List_By_Date;
--
dstanbro@[EMAIL PROTECTED]


|