Download GLADE User's Guide

Transcript
16
GLADE User’s Guide
type String_Access is access String;
type Node;
type List is access Node;
type Node is record
Content : String_Access;
Next
: List;
end record;
procedure Read
(S : access Root_Stream_Type’Class;
L : out List);
procedure Write
(S : access Root_Stream_Type’Class;
L : in List);
for List’Read use Read;
for List’Write use Write;
end StringArrayStream;
Non-remote access types cannot be declared in the public part of a remote types unit.
However, it is possible to define private non-remote access types as long as the user provides
its marshaling procedures, that is to say the mechanism needed to place a value of the type
into a communication stream. The code below describes how to transmit a linked structure.
The package declaration provides a type definition of single-linked lists of unbounded
strings. An implementation of the marshaling operations could be the following:
package body StringArrayStream is
procedure Read
(S : access Root_Stream_Type’Class;
L : out List) is
begin
if Boolean’Input (S) then
L := new Node;
L.Content := new String’(String’Input (S));
List’Read (S, L.Next);
else
L := null;
end if;
end Read;
procedure Write
(S : access Root_Stream_Type’Class;
L : in List) is
begin
if L = null then
Boolean’Output (S, False);
else
Boolean’Output (S, True);
String’Output (S, L.Content.all);
List’Write (S, L.Next);
end if;
end Write;
-- [...] Other services
end StringArrayStream;