comp.lang.ada
 help / color / mirror / Atom feed
From: Edward Fish <edward.r.fish@gmail.com>
Subject: Re: limited /non-limited tagged type
Date: Fri, 4 Mar 2011 16:17:55 -0800 (PST)
Date: 2011-03-04T16:17:55-08:00	[thread overview]
Message-ID: <aad295ce-4747-448b-a038-11baee58e43f@k15g2000prk.googlegroups.com> (raw)
In-Reply-To: 7fa882b5-72ab-4a76-9f4c-1c303cb04858@v31g2000vbs.googlegroups.com

On Mar 4, 2:18 pm, Hacid <chadi.alku...@gmail.com> wrote:
> On 4 mar, 20:54, Edward Fish <edward.r.f...@gmail.com> wrote:
>
>
>
> > On Mar 4, 11:56 am, Hacid <chadi.alku...@gmail.com> wrote:
>
> > > Hi,
>
> > > I haven't found an existing topic about this, so I ask my question :
>
> > > I develop a package for colleagues. In this package I define a tagged
> > > type. I want to prevent them from doing assignments on this type. But
> > > I want to be able to do these assignments in my body.
>
> > > I understand why I can't define my type limited in the public part and
> > > not limited in the private part. But is there a way to do what I
> > > want ?
>
> > > Something like :
>
> > > package Foo is
>
> > >    type Object is tagged private;
>
> > >    function ":=" (Left : out Object,; Right : in Object) is abstract;
> > > -- I know this looks strange
>
> > > end Foo;
>
> > > Thanks.
>
> > Yes, I think.
> > You could add in an 'indirection step'.
>
> --
> package Whatever is
>
>    type Public_Type is tagged limited private;
>
>    --primitive functions.
>
> private
>
>   -- Base is the type that you will manipulate in the Body.
>   type Base is tagged record
>     -- fields
>      null;
>   end record;
>
>   type Public_Type is new Base with null record;
>
> end Whatever;
> --
> whatever.ads:15:08: completion of limited tagged type must be limited
>
> This way seems to not work ... :o(

After reading your requirements, perhaps this would be the best
way to design what you need/want:

package Whatever is

   Type Public_Type is tagged limited private;

   -- Create constructs an object of Public_Type and may ONLY be used
for
   -- initialization of objects of that type as the type is limited.
   Function Create( Field_1 : In Positive; Field_2 : In Integer )
			Return Public_Type;

   -- Other primitive functions.

private

   Type Public_Type is tagged limited record
   --tagged limited record
      -- Add fields here
      Null;
   end record;

   --Private/hidden functions.

   -- Assign may be used to copy Input to output; this includes
replaceing the
   -- contents of a Public_Type object, which may be done like so:
   --	Assign( Output => Variable, Input => Create(1,128) );
   Procedure Assign( Input : In Public_Type; Output : Out
Public_Type );

end Whatever;



  reply	other threads:[~2011-03-05  0:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-04 18:56 limited /non-limited tagged type Hacid
2011-03-04 19:54 ` Edward Fish
2011-03-04 21:18   ` Hacid
2011-03-05  0:17     ` Edward Fish [this message]
2011-03-04 20:10 ` Georg Bauhaus
2011-03-04 21:55   ` Hacid
2011-03-04 22:21     ` Hacid
2011-03-05  1:20       ` Randy Brukardt
2011-03-04 22:22     ` Georg Bauhaus
2011-03-04 22:40       ` Hacid
2011-03-05  1:29         ` Georg Bauhaus
2011-03-04 23:34 ` Adam Beneschan
2011-03-05  3:26 ` Adam Beneschan
2011-03-05 16:48   ` Hacid
replies disabled

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