comp.lang.ada
 help / color / mirror / Atom feed
* access types
@ 2007-07-01  0:39 Brian May
  2007-07-01  1:54 ` Robert A Duff
  0 siblings, 1 reply; 16+ messages in thread
From: Brian May @ 2007-07-01  0:39 UTC (permalink / raw)


Hello,

Ok, so maybe my Ada is rusty.


However, I had a situation where I want to do the following:

=== cut ===
package a is

        type X is tagged private;

        ...

        type X_reference is access X'class;

        ...

        type Y is new X with private;
        procedure do_stuff(my_object : in out Y);

        ...

        type Y_reference is access Y'Class;

        ...
end a

package b is
        procedure save_reference(my_object : in X_reference);
end b;

and I want to be able to do:

declare
        U : Y_reference;
        V : X_reference;
begin
        U := new Y;
        do_stuff(U.all);

        V := U;
        save_reference(V); 
end;
=== cut ===

notes:

- do_stuff is not defined for X only Y, so I can't skip the
Y_reference and go straight to a X_reference.

- not compiled; but hopefully understandable


The problem is the 2nd last instruction (V := U) won't compile, as the
compiler complains it is not possible to convert a Y_Reference to a
X_Reference;

Is it possible to convert a Y_reference to a X_reference?

As the X_reference can access X'Class, which presumable includes
Y'Class, I thought it should be possible somehow, without creating a
separate copy of the object.

(yes, maybe it would be ideal if I didn't need so many access types,
however these objects need to be referenced from multiple objects and
access types would seem the most natural solution).


Thanks.
-- 
Brian May <bam@snoopy.apana.org.au>



^ permalink raw reply	[flat|nested] 16+ messages in thread
* Access Types
@ 1999-07-15  0:00 Ronald Ayoub
  1999-07-21  0:00 ` Robert A Duff
  0 siblings, 1 reply; 16+ messages in thread
From: Ronald Ayoub @ 1999-07-15  0:00 UTC (permalink / raw)



For this line of code:

type File_Access is access constant File_Type;

I understand this to mean that File_Access points to a File_Type variable
which cannot be changed but the value pointed to can be changed. Is this
correct?

How would you specify that the value pointed to is constant? Would it be

type File_Access is constant access File_Type;

Would this specify that both semantic elements are constant

type File_Access is constant access constant File_Type;

Thanks.

Ron 




^ permalink raw reply	[flat|nested] 16+ messages in thread
* Access types
@ 1998-05-27  0:00 jsanchor
  1998-05-28  0:00 ` Jerry van Dijk
  0 siblings, 1 reply; 16+ messages in thread
From: jsanchor @ 1998-05-27  0:00 UTC (permalink / raw)



HI, I am working with access types and have a challenge at hand which I seem
to be losing. Need some help. I have data in Non Volatile Memory and RAM that
I need to access using access types. The problem is I need to have the same
"types" to work on the data, ie compare them, calculate checksum, etc.
ex. I have a package that looks like this:
-------------NVM--------------------------------------
type Non_Volatile_Type is tagged private;

type Ptr_to_Non_Volatile_Type is access all Non_Volatile_Type'class;

????Ptr_to_Data : access Non_Volatile_Type'Class?????;

type Information_Record_Type is
record
    Tag_Part   : Tag;
    NVM_Access : Ptr_to_Data???;
    RAM_Access : Ptr_to_Data???;
end record;

procedure Compute_Checksum (block : ???Ptr_to_Data);
           or
procedure Compute_Checksum (block : ???access Non_Volatile_Type'Class);

private

   type Non_Volatile_Type is tagged
      record
         checksum : Storage_Element;
      end record;

Somebody trying to use my package will declare a package somewhat like this
---------------------USER Spec------------------------------------
  type List_NVM_Type is new ddNVM.Non_Volatile_Type with
  record
     word1 : INTEGER := 8;
  end record;
---------------------USER Body------------------------------------
   procedure test is
      my_nvm : aliased List_NVM_Type;
   begin

      ddNVM.Compute_checksum(my_nvm'access);
   end test;

Does anybody know of a way. Thanks in advance.

sincerely,
Jay Sanchorawala.










-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading




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

end of thread, other threads:[~2007-07-02 15:37 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-01  0:39 access types Brian May
2007-07-01  1:54 ` Robert A Duff
2007-07-01  7:52   ` Dmitry A. Kazakov
2007-07-01 14:57     ` Robert A Duff
2007-07-01 19:41       ` Dmitry A. Kazakov
2007-07-02  0:12         ` Robert A Duff
2007-07-02  8:06           ` Dmitry A. Kazakov
2007-07-02 15:37       ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
1999-07-15  0:00 Access Types Ronald Ayoub
1999-07-21  0:00 ` Robert A Duff
1999-07-22  0:00   ` Steve Folly
1999-07-23  0:00     ` Tucker Taft
1998-05-27  0:00 Access types jsanchor
1998-05-28  0:00 ` Jerry van Dijk
1998-05-29  0:00   ` jsanchor
1998-05-30  0:00     ` Jerry van Dijk

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