From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Good/best way to enforce library-level instantiation a generic package
Date: Tue, 17 Mar 2020 12:21:44 +0100
Date: 2020-03-17T12:21:44+01:00 [thread overview]
Message-ID: <r4qbs8$192$1@dont-email.me> (raw)
In-Reply-To: <r4p8md$otc$1@franka.jacob-sparre.dk>
On 3/17/20 2:21 AM, Randy Brukardt wrote:
> "Vincent Marciante" <vincent.marciante@l3harris.com> wrote in message
> news:6bcc6133-8c8b-4252-a8e6-fd64a5eec2ca@googlegroups.com...
>> I made a generic package that I want only to be instantiated at library
>> level.
>> I'm working on compile-time a way to enforce that desire which involves
>> access
>> type accessibility level checking but have not yet set it up correctly.
>> Is there a better/standard way?
>
> For Ada 95, deriving from Controlled does the trick, but that was eliminated
> (at substantial cost) in Ada 2005 and later.
>
> I suppose you could use type String_Access (which is a library-level access
> type) for this:
>
> with Ada.Strings.Unbounded;
> generic
> ...
> package My_Generic is
> -- Real stuff here.
>
> Library-Level : constant aliased String := "Library-Level";
> Check : Ada.Strings.Unbounded.String_Access := Library_Level'Access;
> -- 'Access is illegal if My_Generic is not instantiated at the
> library level.
> end My_Generic;
Check should be constant, too.
For the OP:
You can also use Ada.Tags.Expanded_Name on a tagged type declared in the generic:
type T is abstract tagged null record;
Name : constant String := Ada.Tags.Expanded_Name (T);
pragma Assert
(Ada.Strings.Fixed.Index (Name (Name'First .. Name'Last - 2), ".") = 0,
"Generic_Name must be instantiated at library level");
--
Jeff Carter
"Gentlemen, you can't fight in here. This is the War Room!"
Dr. Strangelove
30
next prev parent reply other threads:[~2020-03-17 11:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 18:51 Good/best way to enforce library-level instantiation a generic package Vincent Marciante
2020-03-17 1:21 ` Randy Brukardt
2020-03-17 10:11 ` Vincent Marciante
2020-03-17 11:21 ` Jeffrey R. Carter [this message]
2020-03-18 1:03 ` Randy Brukardt
2020-03-18 9:23 ` Jeffrey R. Carter
2020-03-20 20:37 ` Randy Brukardt
2020-03-18 10:27 ` Vincent Marciante
2020-03-17 6:29 ` briot.emmanuel
2020-03-17 10:15 ` Vincent Marciante
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox