comp.lang.ada
 help / color / mirror / Atom feed
* Extend Record in Spec and Body
@ 2006-10-16 15:30 richard.charts
  2006-10-16 16:53 ` Jean-Pierre Rosen
  2006-10-17  7:30 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 8+ messages in thread
From: richard.charts @ 2006-10-16 15:30 UTC (permalink / raw)


Is it possible to extend a record twice in a package?
I'm building a component now that will be mostly reusable.  There are a
couple packages that are the same, but for one piece the differences
require different code.  However, with the way it is designed, it seems
I could make the package specs the same and only alter the bodies.
I would like to try to hide part of the extended record from the
specification without having to change  the operation declarations.

I included a small slice of what I'm trying to do.  Is this even
possible?
Thanks.

SPEC:

private
    type Object is new HigherPackage.object
    with record
        Repo_View   : Repo_View_Array;
    end record;

end spec;

body
    type Object is new HigherPackage.object  -- This is where I'm not
sure how to proceed
    with record
        Data: Data_Array;
        Ack: boolean;
    end record;




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Extend Record in Spec and Body
  2006-10-16 15:30 Extend Record in Spec and Body richard.charts
@ 2006-10-16 16:53 ` Jean-Pierre Rosen
  2006-10-16 17:20   ` Richard Charts
  2006-10-17  7:30 ` Dmitry A. Kazakov
  1 sibling, 1 reply; 8+ messages in thread
From: Jean-Pierre Rosen @ 2006-10-16 16:53 UTC (permalink / raw)


richard.charts@gmail.com a �crit :
> Is it possible to extend a record twice in a package?
> I'm building a component now that will be mostly reusable.  There are a
> couple packages that are the same, but for one piece the differences
> require different code.  However, with the way it is designed, it seems
> I could make the package specs the same and only alter the bodies.
> I would like to try to hide part of the extended record from the
> specification without having to change  the operation declarations.
> 
> I included a small slice of what I'm trying to do.  Is this even
> possible?
> Thanks.
> 
> SPEC:
> 
> private
>     type Object is new HigherPackage.object
>     with record
>         Repo_View   : Repo_View_Array;
>     end record;
> 
> end spec;
> 
> body
>     type Object is new HigherPackage.object  -- This is where I'm not
> sure how to proceed
>     with record
>         Data: Data_Array;
>         Ack: boolean;
>     end record;
> 
This is not allowed as stated, but you could derive an Internal_Object 
from Object in the body, and add conversions where needed.

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Extend Record in Spec and Body
  2006-10-16 16:53 ` Jean-Pierre Rosen
@ 2006-10-16 17:20   ` Richard Charts
  2006-10-17  0:33     ` Georg Bauhaus
  2006-10-17  1:11     ` Randy Brukardt
  0 siblings, 2 replies; 8+ messages in thread
From: Richard Charts @ 2006-10-16 17:20 UTC (permalink / raw)



Jean-Pierre Rosen wrote:
> richard.charts@gmail.com a écrit :
> > Is it possible to extend a record twice in a package?
> > I'm building a component now that will be mostly reusable.  There are a
> > couple packages that are the same, but for one piece the differences
> > require different code.  However, with the way it is designed, it seems
> > I could make the package specs the same and only alter the bodies.
> > I would like to try to hide part of the extended record from the
> > specification without having to change  the operation declarations.
> >
> > I included a small slice of what I'm trying to do.  Is this even
> > possible?
> > Thanks.
> >
> > SPEC:
> >
> > private
> >     type Object is new HigherPackage.object
> >     with record
> >         Repo_View   : Repo_View_Array;
> >     end record;
> >
> > end spec;
> >
> > body
> >     type Object is new HigherPackage.object  -- This is where I'm not
> > sure how to proceed
> >     with record
> >         Data: Data_Array;
> >         Ack: boolean;
> >     end record;
> >
> This is not allowed as stated, but you could derive an Internal_Object
> from Object in the body, and add conversions where needed.
>
> --
> ---------------------------------------------------------
>             J-P. Rosen (rosen@adalog.fr)
> Visit Adalog's web site at http://www.adalog.fr


As a kind of similar question, is it legal to extend an object and have
the new object be variant?

type Object (Type: New_Type is new HigherPackage.object
    with record
        Repo_View   : Repo_View_Array;
        case Type is
            Something =>
                 Test : Natural;
end record;




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Extend Record in Spec and Body
  2006-10-16 17:20   ` Richard Charts
@ 2006-10-17  0:33     ` Georg Bauhaus
  2006-10-17  1:11     ` Randy Brukardt
  1 sibling, 0 replies; 8+ messages in thread
From: Georg Bauhaus @ 2006-10-17  0:33 UTC (permalink / raw)


On Mon, 2006-10-16 at 10:20 -0700, Richard Charts wrote:


> As a kind of similar question, is it legal to extend an object and have
> the new object be variant?
> 
> type Object (Type: New_Type is new HigherPackage.object
>     with record
>         Repo_View   : Repo_View_Array;
>         case Type is
>             Something =>
>                  Test : Natural;
> end record;

Yes, extensions can have discriminants.
I have found this useful when the number
of variants was small, e.g. in an enumeration
type. Not using "when others =>" makes
sure that no case is lost, at compile time.


-- Georg 





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Extend Record in Spec and Body
  2006-10-16 17:20   ` Richard Charts
  2006-10-17  0:33     ` Georg Bauhaus
@ 2006-10-17  1:11     ` Randy Brukardt
  1 sibling, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2006-10-17  1:11 UTC (permalink / raw)


"Richard Charts" <richard.charts@gmail.com> wrote in message
news:1161019211.319933.248220@i42g2000cwa.googlegroups.com...

...
> As a kind of similar question, is it legal to extend an object and have
> the new object be variant?

Yes, that is legal.

                   Randy.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Extend Record in Spec and Body
  2006-10-16 15:30 Extend Record in Spec and Body richard.charts
  2006-10-16 16:53 ` Jean-Pierre Rosen
@ 2006-10-17  7:30 ` Dmitry A. Kazakov
  2006-10-17 18:49   ` Simon Wright
  1 sibling, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2006-10-17  7:30 UTC (permalink / raw)


On 16 Oct 2006 08:30:46 -0700, richard.charts@gmail.com wrote:

> Is it possible to extend a record twice in a package?

Yes, but not in the body and each extension would produce a new type.

> I'm building a component now that will be mostly reusable.  There are a
> couple packages that are the same, but for one piece the differences
> require different code.  However, with the way it is designed, it seems
> I could make the package specs the same and only alter the bodies.
> I would like to try to hide part of the extended record from the
> specification without having to change  the operation declarations.

You cannot do it in the body and you cannot do it so that both extensions
were looked as one type. But you can make one extension public and another
private:

   type Transient_Object is abstract new HigherPackage.object with record
      <public things>
   end record;

   type Object is new Transient_Object with private;
private
   type Object is new Transient_Object with record
      <private things>
   end record;

Well, if the public things are read-only you could expose them through
getters using the prefix interface (new in Ada 2005), and then move
everything into private.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Extend Record in Spec and Body
  2006-10-17  7:30 ` Dmitry A. Kazakov
@ 2006-10-17 18:49   ` Simon Wright
  2006-10-17 20:19     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Wright @ 2006-10-17 18:49 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> Yes, but not in the body and each extension would produce a new
> type.

I have written code that extends an abstract tagged type (declared in
the package spec) in the package body, why would that be a problem?
(in fact I do it 3 times ...)

--S



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Extend Record in Spec and Body
  2006-10-17 18:49   ` Simon Wright
@ 2006-10-17 20:19     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2006-10-17 20:19 UTC (permalink / raw)


On Tue, 17 Oct 2006 19:49:23 +0100, Simon Wright wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> Yes, but not in the body and each extension would produce a new
>> type.
> 
> I have written code that extends an abstract tagged type (declared in
> the package spec) in the package body, why would that be a problem?
> (in fact I do it 3 times ...)

Because *a* record cannot be extended twice. See the first posting in the
thread. As I understood it, OP wished to provide (A) two accumulating
record extensions resulting in the same type. (B) The first "incomplete"
extension should happen in the specification. The second "completion"
extension should in the body. Neither is legal in Ada.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-10-17 20:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-16 15:30 Extend Record in Spec and Body richard.charts
2006-10-16 16:53 ` Jean-Pierre Rosen
2006-10-16 17:20   ` Richard Charts
2006-10-17  0:33     ` Georg Bauhaus
2006-10-17  1:11     ` Randy Brukardt
2006-10-17  7:30 ` Dmitry A. Kazakov
2006-10-17 18:49   ` Simon Wright
2006-10-17 20:19     ` Dmitry A. Kazakov

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