From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6c43f45c2ab47c51,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!news-out.readnews.com!transit3.readnews.com!panix!newsfeed-00.mathworks.com!lon-transit.news.telstra.net!lon-in.news.telstra.net!news.telstra.net!news-server.bigpond.net.au!53ab2750!not-for-mail From: Dale Stanbrough Newsgroups: comp.lang.ada Subject: Using Ada.Containers.Vector and Limited Private types User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X) Message-ID: Date: Sat, 05 Jul 2008 11:53:38 GMT NNTP-Posting-Host: 58.161.16.225 X-Complaints-To: abuse@bigpond.net.au X-Trace: news-server.bigpond.net.au 1215258818 58.161.16.225 (Sat, 05 Jul 2008 21:53:38 EST) NNTP-Posting-Date: Sat, 05 Jul 2008 21:53:38 EST Organization: BigPond Internet Services Xref: g2news1.google.com comp.lang.ada:1015 Date: 2008-07-05T11:53:38+00:00 List-Id: 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