A question about generic collections - maybe...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

A question about generic collections - maybe...

bsquared
Hello,

I am wondering what the best approach to this problem is.

I have what amounts to a Tstringlist that I am attempting to use
generics for typing the objects and I would like to get the names and
values as lists.  I am thinking something along the lines of the
following, but it doesn't feel quite right.

   generic TGenericDatabaseMap<TKey,TData>  = class(TFPGMap)
     function GetDataBases: TFPGList<TData>;
     function GetDatabaseNames: TFPGList<TKey>;
   end;


   TDatabaseMap = specialize TGenericDatabaseMap<String,TDataContainer>;

Any feedback is appreciated

Thank you.

--
Regards,
Brian

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: A question about generic collections - maybe...

bsquared
On 11/14/2012 12:10 PM, bsquared wrote:

> Hello,
>
> I am wondering what the best approach to this problem is.
>
> I have what amounts to a Tstringlist that I am attempting to use
> generics for typing the objects and I would like to get the names and
> values as lists.  I am thinking something along the lines of the
> following, but it doesn't feel quite right.
>
>    generic TGenericDatabaseMap<TKey,TData>  = class(TFPGMap)
>      function GetDataBases: TFPGList<TData>;
>      function GetDatabaseNames: TFPGList<TKey>;
>    end;
>
>
>    TDatabaseMap = specialize TGenericDatabaseMap<String,TDataContainer>;
>
> Any feedback is appreciated
>
> Thank you.
>


I think I got it.

   TDatabaseList = specialize TFPGList<TDataContainer>;
   TBaseDatabaseMap = specialize TFPGMap<String,TDataContainer>;

   { TDatabaseMap }

   TDatabaseMap = class(TBaseDatabaseMap)
     function GetDataBases: TDatabaseList;
     function GetDatabaseNames: TStrings;
   end;

Although I wonder If a collection might serve better.

--
Regards,
Brian

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: A question about generic collections - maybe...

valeray12
This post has NOT been accepted by the mailing list yet.
How can I create a generic method "swap" that swaps two elements?
[url=http://www.barstoolmegastore.com]bar stool[/url]