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


|