comp.lang.ada
 help / color / mirror / Atom feed
* Help with a Remote Type / Iterator
@ 2003-12-01  3:48 Michael Lamarre
  2003-12-01  5:31 ` Robert I. Eachus
  2003-12-01 23:00 ` Nick Roberts
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Lamarre @ 2003-12-01  3:48 UTC (permalink / raw)


Hi there. This is my first post here, so please be gentle. I'm 
developing a distributed Ada program at work. I have a very skilled 
mentor helping me, but we're having a hell of a time with one particular 
problem. I've included simple mock-ups of the packages/types involved 
below, but let me give a high-level explanation first.

I have a record type I've defined in package A. In package A.CHILD, I 
want to define a type that is a collection of these records. For 
stylistic reasons, we'd rather declare all of the types in the spec and 
not have any incomplete type declarations in the spec. Both A and 
A.CHILD are REMOTE_TYPES (RT) packages.

What we need is some kind of iterator for the collection type declared 
in A.CHILD. We've tried a passive iterator, but some of the stuff we 
need to do while iterating just won't work given that the passive 
iterator needs to take an access-to-subprogram parameter, which, in a RT 
package must be a remote subprogram. We need the flexibility of an 
active iterator.

Naturally, the standard way to do this is to have an iterator type that 
takes an access discriminant that points at the collection the iterator 
is associated with. However, this won't work, as the compiler informs us 
that a non-remote-access type must have user-defined READ and WRITE 
attributes. As an access discriminant is an anonymous type, this is 
impossible. I tried using a named access type as the discriminant, but 
the code in the body for the iterator subprograms wouldn't compile, 
saying something like "invalid dereference of a remote access to 
classwide type".

Anyway, here's my sample code, simplified to drastic degrees. Can anyone 
help me figure out how to come up with an iterator for my 
COLLECTION_TYPE? Is there a standard way to iterate over a remote type? 
Thanks in advance.

-- Mike L.

---[ File: a.ads ]-------------------

package A is

    pragma REMOTE_TYPES(A);

    type RECORD_TYPE is tagged limited private;

    type RECORD_PTR_TYPE is access all RECORD_TYPE'CLASS;

    -- various operations on RECORD_TYPEs.

private

    type RECORD_TYPE is tagged limited record
       -- Various record fields.
    end record;

end A;

---[ File: a-child.ads ]-------------

package A.CHILD

    pragma REMOTE_TYPES(CHILD);

    type COLLECTION_TYPE(CAPACITY : NATURAL) is tagged limited private;

    type COLLECTION_PTR_TYPE is access all COLLECTION_TYPE'CLASS;

    -- Various operations on COLLECTION_TYPEs.

private

    type REC_ARRAY_TYPE is array (NATURAL range <>) of RECORD_PTR_TYPE;

    type COLLECTION_TYPE(CAPACITY : NATURAL) is tagged limited record
       RECORD_ARRAY : REC_ARRAY_TYPE(1..CAPACITY);
       -- Various other fields.
    end record;

end A.CHILD;




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

end of thread, other threads:[~2003-12-03  4:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-01  3:48 Help with a Remote Type / Iterator Michael Lamarre
2003-12-01  5:31 ` Robert I. Eachus
2003-12-01 13:37   ` Michael Lamarre
2003-12-02 23:17     ` Robert I. Eachus
2003-12-03  4:46       ` Michael Lamarre
2003-12-01 23:00 ` Nick Roberts

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