Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Using Ada.Conta...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 18 Topic 5799 of 5881
Post > Topic >>

Using Ada.Containers.Vector and Limited Private types

by Dale Stanbrough <MrNoSpam@[EMAIL PROTECTED] > Jul 5, 2008 at 11:53 AM

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]

 




 18 Posts in Topic:
Using Ada.Containers.Vector and Limited Private types
Dale Stanbrough <MrNoS  2008-07-05 11:53:38 
Re: Using Ada.Containers.Vector and Limited Private types
george.priv@[EMAIL PROTEC  2008-07-05 08:42:41 
Re: Using Ada.Containers.Vector and Limited Private types
Gene <gene.ressler@[EM  2008-07-06 11:09:58 
Re: Using Ada.Containers.Vector and Limited Private types
"Dmitry A. Kazakov&q  2008-07-06 21:18:17 
Re: Using Ada.Containers.Vector and Limited Private types
Dale Stanbrough <MrNoS  2008-07-10 00:16:06 
Re: Using Ada.Containers.Vector and Limited Private types
"Dmitry A. Kazakov&q  2008-07-10 09:31:52 
Re: Using Ada.Containers.Vector and Limited Private types
Gene <gene.ressler@[EM  2008-07-07 06:29:16 
Re: Using Ada.Containers.Vector and Limited Private types
"Dmitry A. Kazakov&q  2008-07-07 16:15:11 
Re: Using Ada.Containers.Vector and Limited Private types
Gene <gene.ressler@[EM  2008-07-07 11:39:52 
Re: Using Ada.Containers.Vector and Limited Private types
Gene <gene.ressler@[EM  2008-07-10 15:59:30 
Re: Using Ada.Containers.Vector and Limited Private types
"Jeffrey R. Carter&q  2008-07-11 22:06:58 
Re: Using Ada.Containers.Vector and Limited Private types
"Dmitry A. Kazakov&q  2008-07-12 09:53:33 
Re: Using Ada.Containers.Vector and Limited Private types
Gene <gene.ressler@[EM  2008-07-11 19:45:47 
Re: Using Ada.Containers.Vector and Limited Private types
"Jeffrey R. Carter&q  2008-07-12 04:41:31 
Re: Using Ada.Containers.Vector and Limited Private types
"Dmitry A. Kazakov&q  2008-07-12 10:02:07 
Re: Using Ada.Containers.Vector and Limited Private types
Gene <gene.ressler@[EM  2008-07-13 08:30:23 
Re: Using Ada.Containers.Vector and Limited Private types
"Jeffrey R. Carter&q  2008-07-13 18:10:08 
Re: Using Ada.Containers.Vector and Limited Private types
Simon Wright <simon.j.  2008-07-16 22:23:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 15:31:51 CDT 2008.