From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Using Ada.Containers.Vector and Limited Private types
Date: Sat, 12 Jul 2008 09:53:33 +0200
Date: 2008-07-12T09:53:37+02:00 [thread overview]
Message-ID: <86v8h7qx6nwr.1mso33mddoxpd.dlg@40tude.net> (raw)
In-Reply-To: 4c5bfeb0-daa0-45e4-82f0-eebabda565e9@d45g2000hsc.googlegroups.com
On Thu, 10 Jul 2008 15:59:30 -0700 (PDT), Gene wrote:
> procedure List_By_Date is
>
> type String_Ptr_Type is access String;
> type File_Info_Type is
> record
> Modification_Time : Time;
> Simple_Name : String_Ptr_Type; -- Freed with storage pool!
> end record;
>
> package File_Info_Vectors is
> new Ada.Containers.Vectors (Positive, File_Info_Type);
I am using a different design in such cases, which are a kind of cached
data store with sorted items.
I would make a descriptor type containing all data of an item:
type File_Info (Length : Natural) is record
Modification_Time : Time;
Simple_Name : String (1..Length);
...
end record;
File_Info can be allocated in an arena or mark-and-release pool. That is no
matter. Then comparison operations are defined on the pointers rather than
the descriptors:
type File_Info_By_Date is access all File_Info;
function "<" (Left, Right : File_Info_By_Date) return Boolean;
type File_Info_By_Name is access all File_Info;
function "<" (Left, Right : File_Info_By_Name) return Boolean;
type File_Info_By_Size is access all File_Info;
function "<" (Left, Right : File_Info_By_Size) return Boolean;
etc.
Then I would create ordered sets of File_Info_By_Date, File_Info_By_Name
and so on. All this I put into a controlled object which takes care about
inserting and removing items. Indexes of pointers are kept sorted. This is
exactly the design I used for a persistency layer.
(I don't use Ada.Containers, but I think this approach should work with
them too.)
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
prev parent reply other threads:[~2008-07-12 7:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-05 11:53 Using Ada.Containers.Vector and Limited Private types Dale Stanbrough
2008-07-05 15:42 ` 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 [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox