comp.lang.ada
 help / color / mirror / Atom feed
* Dispatching problem.
@ 2003-02-06 14:04 Petter Fryklund
  2003-02-06 15:33 ` James S. Rogers
  2003-02-07  9:01 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 10+ messages in thread
From: Petter Fryklund @ 2003-02-06 14:04 UTC (permalink / raw)


We have the following:

package A is
  type Msg;
  type Msg_Ptr is access all Msg'Class;
  type Msg is abstract tagged null record;
  ... other declarations

  type M1 is new Msg with ....
  type M1_Ptr is access all M1;
  type M2 is new Msg with ....
  type M2_Ptr is access all M2;
  ... other declarations

  function X (Param : Integer) return Msg_Ptr;
end A;

with A;
package B is 
  type Msg is abstract new A.Msg with null record;
  type Msg_Ptr is access all Msg;
  type B1 is new A.M1 with null record;
  type B1_Ptr is access all B1;
  type B2 is new A.M1 with null record;
  type B2_Ptr is access all B2;

  procedure Y (MP : access B1);
  procedure Y (MP : access B2); 
end B;

with A;
with B;
procedure Main is

   X : A.Msg_Ptr;
   Y : A.Msg_Ptr;
begin
   X := A.X (1);        -- Building a A.M1
   Y := A.X (2);        -- Building a A.M2
   B.Y (B.Msg_Ptr (X)); -- causes Constraint_Error Tag Check Failed to be raised. 
end Main;

How can we dispatch in package B?



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

* Re: Dispatching problem.
  2003-02-06 14:04 Petter Fryklund
@ 2003-02-06 15:33 ` James S. Rogers
  2003-02-07  7:35   ` Petter Fryklund
  2003-02-07  9:01 ` Dmitry A. Kazakov
  1 sibling, 1 reply; 10+ messages in thread
From: James S. Rogers @ 2003-02-06 15:33 UTC (permalink / raw)


"Petter Fryklund" <petter.fryklund.konsult@dynamics.saab.se> wrote in
message news:f74cb448.0302060604.e808c22@posting.google.com...
> We have the following:
>
> package A is
>   type Msg;
>   type Msg_Ptr is access all Msg'Class;
>   type Msg is abstract tagged null record;
>   ... other declarations
>
>   type M1 is new Msg with ....
>   type M1_Ptr is access all M1;
>   type M2 is new Msg with ....
>   type M2_Ptr is access all M2;
>   ... other declarations
>
>   function X (Param : Integer) return Msg_Ptr;
> end A;
>
> with A;
> package B is
>   type Msg is abstract new A.Msg with null record;
>   type Msg_Ptr is access all Msg;
>   type B1 is new A.M1 with null record;
>   type B1_Ptr is access all B1;
>   type B2 is new A.M1 with null record;
>   type B2_Ptr is access all B2;
>
>   procedure Y (MP : access B1);
>   procedure Y (MP : access B2);
> end B;
>
> with A;
> with B;
> procedure Main is
>
>    X : A.Msg_Ptr;
>    Y : A.Msg_Ptr;
> begin
>    X := A.X (1);        -- Building a A.M1
>    Y := A.X (2);        -- Building a A.M2
>    B.Y (B.Msg_Ptr (X)); -- causes Constraint_Error Tag Check Failed to be
raised.
> end Main;
>
> How can we dispatch in package B?

You seem to have your inheritence concepts inverted here.
Every B.B1 is a member of the class rooted at A.Msg. Not every
A.Msg is a member of B.B1. For instance, A.M1 is not a B.B1.

Jim Rogers





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

* Re: Dispatching problem.
  2003-02-06 15:33 ` James S. Rogers
@ 2003-02-07  7:35   ` Petter Fryklund
  0 siblings, 0 replies; 10+ messages in thread
From: Petter Fryklund @ 2003-02-07  7:35 UTC (permalink / raw)


ur right. A is used for encode/decode in communication department. How
can we dispatch both in encode of A and in the application B. I'm sure
there is a way, but I can't find it.

> You seem to have your inheritence concepts inverted here.
> Every B.B1 is a member of the class rooted at A.Msg. Not every
> A.Msg is a member of B.B1. For instance, A.M1 is not a B.B1.
> 
> Jim Rogers



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

* Re: Dispatching problem.
  2003-02-06 14:04 Petter Fryklund
  2003-02-06 15:33 ` James S. Rogers
@ 2003-02-07  9:01 ` Dmitry A. Kazakov
  2003-02-07 14:55   ` Petter Fryklund
  1 sibling, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2003-02-07  9:01 UTC (permalink / raw)


On 6 Feb 2003 06:04:51 -0800, petter.fryklund.konsult@dynamics.saab.se
(Petter Fryklund) wrote:

>We have the following:
>
>package A is
>  type Msg;
>  type Msg_Ptr is access all Msg'Class;
>  type Msg is abstract tagged null record;
>  ... other declarations
>
>  type M1 is new Msg with ....
>  type M1_Ptr is access all M1;
>  type M2 is new Msg with ....
>  type M2_Ptr is access all M2;
>  ... other declarations
>
>  function X (Param : Integer) return Msg_Ptr;
>end A;
>
>with A;
>package B is 
>  type Msg is abstract new A.Msg with null record;
>  type Msg_Ptr is access all Msg;
>  type B1 is new A.M1 with null record;
>  type B1_Ptr is access all B1;
>  type B2 is new A.M1 with null record;
>  type B2_Ptr is access all B2;
>
>  procedure Y (MP : access B1);
>  procedure Y (MP : access B2); 
>end B;
>
>with A;
>with B;
>procedure Main is
>
>   X : A.Msg_Ptr;
>   Y : A.Msg_Ptr;
>begin
>   X := A.X (1);        -- Building a A.M1
>   Y := A.X (2);        -- Building a A.M2
>   B.Y (B.Msg_Ptr (X)); -- causes Constraint_Error Tag Check Failed to be raised. 
>end Main;
>
>How can we dispatch in package B?

You cannot dispatch "in a package". So what was the question?

If B.Y has to be dispatching, declare it appropriately. The first
question here is: what is the type class it dispatches over? From your
code follows that A.M1, A.M2 belong to the set. The single type class
which includes them and B.Msg is A.Msg. Thus Y has to be defined on
A.Msg:

package A.Msg is
   procedure Y (MP : access Msg) is abstract;

Note that it is abstract so you have to override it for A.M1, A.M2,
B.Msg etc.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



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

* Re: Dispatching problem.
  2003-02-07  9:01 ` Dmitry A. Kazakov
@ 2003-02-07 14:55   ` Petter Fryklund
  2003-02-10  9:12     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 10+ messages in thread
From: Petter Fryklund @ 2003-02-07 14:55 UTC (permalink / raw)


Another way to explain our problem: a message (of which there are
several variants) is received from another system in unit P. It is
forwarded to unit B which decodes to message using procedures in
package A. Package A can also be used for coding of outbound messages
and for producing trace of messages contents, both inbound and
outbound. We would like to dispatch both coding and tracing in A and
subsequent usage of the decoded message in B. Perhaps inbound messages
and outbound should be treated differently? In the original post there
is a 1-to-1 relationship between ie B.B1 and A.M1. They have the same
contents, apart from the tag. So, how do make an A.M1 a B.B1 (or
really an A.Msg a B.Msg?)so that we can dispatch in code written in
package B? (Dispatching in B ;-)



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

* Re: Dispatching problem.
  2003-02-07 14:55   ` Petter Fryklund
@ 2003-02-10  9:12     ` Dmitry A. Kazakov
  2003-02-11  8:31       ` Petter Fryklund
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2003-02-10  9:12 UTC (permalink / raw)


On 7 Feb 2003 06:55:49 -0800, petter.fryklund.konsult@dynamics.saab.se
(Petter Fryklund) wrote:

>Another way to explain our problem: a message (of which there are
>several variants) is received from another system in unit P. It is
>forwarded to unit B which decodes to message using procedures in
>package A. Package A can also be used for coding of outbound messages
>and for producing trace of messages contents, both inbound and
>outbound. We would like to dispatch both coding and tracing in A and
>subsequent usage of the decoded message in B. Perhaps inbound messages
>and outbound should be treated differently? In the original post there
>is a 1-to-1 relationship between ie B.B1 and A.M1. They have the same
>contents, apart from the tag. So, how do make an A.M1 a B.B1 (or
>really an A.Msg a B.Msg?)so that we can dispatch in code written in
>package B? (Dispatching in B ;-)

First of all, Ada does not have multiple inheritance, so B.Msg have to
be in A.Msg. What is wrong with the following design?

package A is
   type Msg is abstract tagged null record;
   procedure Y (X : in out Msg) is abstract;

   type M1 is new Msg with ...;
   procedure Y (X : in out Msg);

   type M2 is new Msg with ...;
   procedure Y (X : in out Msg);
end A;

with A;
package B is
   type M1 is new A.M1 with ...;
   procedure Y (X : in out M1);

   type M2 is new A.M2 with ...;
   procedure Y (X : in out M2);
end B;

BTW, the package B looks superfluos, as it possibly is, if you are
saying that A.Mi = B.Mi.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



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

* Re: Dispatching problem.
  2003-02-10  9:12     ` Dmitry A. Kazakov
@ 2003-02-11  8:31       ` Petter Fryklund
  0 siblings, 0 replies; 10+ messages in thread
From: Petter Fryklund @ 2003-02-11  8:31 UTC (permalink / raw)


> package A is
>    type Msg is abstract tagged null record;
>    procedure Y (X : in out Msg) is abstract;
> 
>    type M1 is new Msg with ...;
>    procedure Y (X : in out Msg);
> 
>    type M2 is new Msg with ...;
>    procedure Y (X : in out Msg);
> end A;
> 
> with A;
> package B is
>    type M1 is new A.M1 with ...;
>    procedure Y (X : in out M1);
> 
>    type M2 is new A.M2 with ...;
>    procedure Y (X : in out M2);
> end B;
> 
> BTW, the package B looks superfluos, as it possibly is, if you are
> saying that A.Mi = B.Mi.
> 
> ---
> Regards,
> Dmitry Kazakov
> www.dmitry-kazakov.de

ur. We forgot to redesign, we just thought of what we already had.
We're changing A to just containing type definitions, since it's
needed in several other places and B to holds the oo stuff.

Thx,
Petter



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

* Dispatching problem.
@ 2008-01-15 18:55 petter_fryklund
  2008-01-15 19:49 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 10+ messages in thread
From: petter_fryklund @ 2008-01-15 18:55 UTC (permalink / raw)


Hi all!

I get compilation error when I  try to dispatch a call using class
wide access variables stating that I cannot call abstract program.

Perhaps oversimplified example is:

package PBN is
   type Item_T is abstract tagged null record;
   type Item_Ptr is access all Item_T'Class;
   function  Create (From : in String) return access Item_T'Class is
abstract;
   function  Img (From : access Item_T'Class) return String is
abstract;
end PBN;

package PBN.Site is
   type Site_T is new Item_T with
      record
         Name :  ASU.Unbounded_String;
      end record;
   type Site_Ptr is access all Site_T;

   function  Create (From : in String) return Site_Ptr;
   function  Img (From : access Site_T) return String;
end PBN.Site;

with Ada.Text_IO;
with PBN;
with PBN.Site;
procedure Print is
    Site :  PBN.Item_Ptr;
begin
    Site := PBN.Site.Create ("[Site qwerty]");
    Ada.Text_IO.Put_Line (Site.Img);             <-----------------
cannot call abstract program
end Print;

Any suggestions (apart from taking extensive course in OOD ;-) ?

Regards,
Petter



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

* Re: Dispatching problem.
  2008-01-15 18:55 Dispatching problem petter_fryklund
@ 2008-01-15 19:49 ` Dmitry A. Kazakov
  2008-01-15 20:01   ` petter_fryklund
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2008-01-15 19:49 UTC (permalink / raw)


On Tue, 15 Jan 2008 10:55:46 -0800 (PST), petter_fryklund@hotmail.com
wrote:

> I get compilation error when I  try to dispatch a call using class
> wide access variables stating that I cannot call abstract program.
> 
> Perhaps oversimplified example is:
> 
> package PBN is
>    type Item_T is abstract tagged null record;
>    type Item_Ptr is access all Item_T'Class;
>    function  Create (From : in String) return access Item_T'Class is
> abstract;
>    function  Img (From : access Item_T'Class) return String is
> abstract;

This is a class-wide operation. As such it is not primitive (and does not
dispatch). For non-primitive operations declaring abstract means
disallowing in Ada.

[ My guess, you wanted:

    function  Img (From : access Item_T) return String is abstract;
(better:  function  Img (From : Item_T) return String is abstract;)

BTW, same applies to Create. It is a factory, so it should be

   function  Create (From : in String)
      return access Item_T is abstract;
(better:  function  Create (From : in String) return Item_T;) ]

> end PBN;
> 
> package PBN.Site is
>    type Site_T is new Item_T with
>       record
>          Name :  ASU.Unbounded_String;
>       end record;
>    type Site_Ptr is access all Site_T;
> 
>    function  Create (From : in String) return Site_Ptr;
>    function  Img (From : access Site_T) return String;

This is an "overloading" for the disallowed operation above.

> end PBN.Site;
> 
> with Ada.Text_IO;
> with PBN;
> with PBN.Site;
> procedure Print is
>     Site :  PBN.Item_Ptr;
> begin
>     Site := PBN.Site.Create ("[Site qwerty]");
>     Ada.Text_IO.Put_Line (Site.Img);             <-----------------
> cannot call abstract program

This calls to the disallowed Img from PBN, the compiler tells you so.

> end Print;
> 
> Any suggestions (apart from taking extensive course in OOD ;-) ?

Use new keywords of Ada 2005 indicating a desire to override, since you are
using that (damned (:-)) prefix notation anyway...

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



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

* Re: Dispatching problem.
  2008-01-15 19:49 ` Dmitry A. Kazakov
@ 2008-01-15 20:01   ` petter_fryklund
  0 siblings, 0 replies; 10+ messages in thread
From: petter_fryklund @ 2008-01-15 20:01 UTC (permalink / raw)


On 15 Jan, 20:49, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Tue, 15 Jan 2008 10:55:46 -0800 (PST), petter_frykl...@hotmail.com
> wrote:
>
> > I get compilation error when I  try to dispatch a call using class
> > wide access variables stating that I cannot call abstract program.
>
> > Perhaps oversimplified example is:
>
> > package PBN is
> >    type Item_T is abstract tagged null record;
> >    type Item_Ptr is access all Item_T'Class;
> >    function  Create (From : in String) return access Item_T'Class is
> > abstract;
> >    function  Img (From : access Item_T'Class) return String is
> > abstract;
>
> This is a class-wide operation. As such it is not primitive (and does not
> dispatch). For non-primitive operations declaring abstract means
> disallowing in Ada.
>
> [ My guess, you wanted:
>
>     function  Img (From : access Item_T) return String is abstract;
> (better:  function  Img (From : Item_T) return String is abstract;)
>
> BTW, same applies to Create. It is a factory, so it should be
>
>    function  Create (From : in String)
>       return access Item_T is abstract;
> (better:  function  Create (From : in String) return Item_T;) ]
>
> > end PBN;
>
> > package PBN.Site is
> >    type Site_T is new Item_T with
> >       record
> >          Name :  ASU.Unbounded_String;
> >       end record;
> >    type Site_Ptr is access all Site_T;
>
> >    function  Create (From : in String) return Site_Ptr;
> >    function  Img (From : access Site_T) return String;
>
> This is an "overloading" for the disallowed operation above.
>
> > end PBN.Site;
>
> > with Ada.Text_IO;
> > with PBN;
> > with PBN.Site;
> > procedure Print is
> >     Site :  PBN.Item_Ptr;
> > begin
> >     Site := PBN.Site.Create ("[Site qwerty]");
> >     Ada.Text_IO.Put_Line (Site.Img);             <-----------------
> > cannot call abstract program
>
> This calls to the disallowed Img from PBN, the compiler tells you so.
>
> > end Print;
>
> > Any suggestions (apart from taking extensive course in OOD ;-) ?
>
> Use new keywords of Ada 2005 indicating a desire to override, since you are
> using that (damned (:-)) prefix notation anyway...
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

Thanks!



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

end of thread, other threads:[~2008-01-15 20:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-15 18:55 Dispatching problem petter_fryklund
2008-01-15 19:49 ` Dmitry A. Kazakov
2008-01-15 20:01   ` petter_fryklund
  -- strict thread matches above, loose matches on Subject: below --
2003-02-06 14:04 Petter Fryklund
2003-02-06 15:33 ` James S. Rogers
2003-02-07  7:35   ` Petter Fryklund
2003-02-07  9:01 ` Dmitry A. Kazakov
2003-02-07 14:55   ` Petter Fryklund
2003-02-10  9:12     ` Dmitry A. Kazakov
2003-02-11  8:31       ` Petter Fryklund

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