comp.lang.ada
 help / color / mirror / Atom feed
From: Dale Stanbrough <MrNoSpam@bigpoop.net.au>
Subject: Using Ada.Containers.Vector and Limited Private types
Date: Sat, 05 Jul 2008 11:53:38 GMT
Date: 2008-07-05T11:53:38+00:00	[thread overview]
Message-ID: <MrNoSpam-843547.21533805072008@news-server.bigpond.net.au> (raw)

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@spam.o.matic.bigpond.net.au



             reply	other threads:[~2008-07-05 11:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-05 11:53 Dale Stanbrough [this message]
2008-07-05 15:42 ` Using Ada.Containers.Vector and Limited Private types george.priv
2008-07-06 18:09 ` Gene
2008-07-06 19:18   ` Dmitry A. Kazakov
2008-07-07 13:29     ` Gene
2008-07-07 14:15       ` Dmitry A. Kazakov
2008-07-07 18:39         ` Gene
2008-07-10  0:16   ` Dale Stanbrough
2008-07-10  7:31     ` Dmitry A. Kazakov
2008-07-10 22:59     ` Gene
2008-07-11 22:06       ` Jeffrey R. Carter
2008-07-12  2:45         ` Gene
2008-07-12  4:41           ` Jeffrey R. Carter
2008-07-13 15:30             ` Gene
2008-07-13 18:10               ` Jeffrey R. Carter
2008-07-16 21:23               ` Simon Wright
2008-07-12  8:02           ` Dmitry A. Kazakov
2008-07-12  7:53       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox