comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Generic package with dynamic subprogram name?
Date: Thu, 10 Jun 2010 08:05:14 +0200
Date: 2010-06-10T08:05:14+02:00	[thread overview]
Message-ID: <87vd9rpgmd.fsf@ludovic-brenta.org> (raw)
In-Reply-To: hup8n8$hdk$1@tornado.tornevall.net

"Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:

> Marek Janukowicz wrote:
>>
>> generic
>>   Attr : String;
>> package Get_Set is
>>   function Get_Attribute return String;
>>   procedure Set_Attribute ( Value : String );
>> end Get_Set;
>>
>> But if I then instantiate:
>> package Get_Set_First_Name is new Get_Set( "FirstName" );
>> package Get_Set_Last_Name is new Get_Set( "LastName" );
>>
>> subprogram names will overlap. I know I can call them using package
>> prefix, but I'd really like to have nice API like here:
>> Get_First_Name( ... );
>> Set_Last_Name( ... );
>
> function Get_First_Name return String renames Get_Set_First_Name.Get_Attribute;
> procedure Set_First_Name (First_Name : in String) renames
> Get_Set_First_Name.Set_Attribute;

generic
  Name : String;
package Attribute is
  function Get return String;
  procedure Set ( Value : String );
end Attribute;

package First_Name is new Attribute (Name => "FirstName");
package Last_Name is new Attribute (Name => "LastName");

First_Name_Attribute := First_Name.Get;
Last_Name.Set (...);

-- 
Ludovic Brenta.



  reply	other threads:[~2010-06-10  6:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-09 23:07 Generic package with dynamic subprogram name? Marek Janukowicz
2010-06-09 23:37 ` Jeffrey R. Carter
2010-06-10  6:05   ` Ludovic Brenta [this message]
2010-06-10  7:33 ` Stephen Leake
2010-06-10 10:14   ` Brian Drummond
2010-06-10 10:48     ` Yannick Duchêne (Hibou57)
2010-06-10 12:13     ` sjw
2010-06-11  9:08     ` Stephen Leake
2010-06-11  9:55       ` J-P. Rosen
2010-06-11 12:19       ` Brian Drummond
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox