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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6c43f45c2ab47c51 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f63g2000hsf.googlegroups.com!not-for-mail From: george.priv@gmail.com Newsgroups: comp.lang.ada Subject: Re: Using Ada.Containers.Vector and Limited Private types Date: Sat, 5 Jul 2008 08:42:41 -0700 (PDT) Organization: http://groups.google.com Message-ID: <14fdd948-bfcd-46aa-ae8c-d91c2c03ed31@f63g2000hsf.googlegroups.com> References: NNTP-Posting-Host: 166.217.38.41 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1215272562 20133 127.0.0.1 (5 Jul 2008 15:42:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 5 Jul 2008 15:42:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f63g2000hsf.googlegroups.com; posting-host=166.217.38.41; posting-account=VnNb3AoAAACTpRtCcTrcjmPX7cs92k1Q User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1021 Date: 2008-07-05T08:42:41-07:00 List-Id: On Jul 5, 7:53 am, Dale Stanbrough wrote: > 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; > > -- > dstan...@spam.o.matic.bigpond.net.au You are attempting to create vector with pointers each pointing to the same instance of Directory_Entry. You need to allocate new directory_entry_type objects as you traverse the directory (before calling Get_Next_Entry). Off course you have to free these objects after use. George.