comp.lang.ada
 help / color / mirror / Atom feed
From: emery@mitre-bedford.arpa  (David Emery)
Subject: Re: Retrieving Rep Spec'ed Enumeration Values
Date: 29 Jun 93 21:05:52 GMT	[thread overview]
Message-ID: <EMERY.93Jun29160552@goldfinger.mitre.org> (raw)

A much better way to handle this particular problem over the net is to
use the 'POS/'VAL attributes, which are portable for all
representations of the same enumeration type:

	shared code:
	
package DEFINES_ENUM_TYPE is

  type COLOR is (RED, GREEN, BLUE):

end DEFINES_ENUM_TYPE;   

package INTEGERS_OVER_NETWORK is

  procedure SEND (I : in INTEGER);
  procedure RECEIVE (I : out INTEGER);

end INTEGERS_OVER_NETWORK;
		
	server/sender code:

with INTEGERS_OVER_NETWORK;
with DEFINES_ENUM_TYPE;
procedure SEND_ENUM_VALUE (E : DEFINES_ENUM_TYPE.COLOR)
is
begin
  INTEGERS_OVER_NETWORK.SEND (DEFINES_ENUM_TYPE.COLOR'POS(E));
	-- send the (integer) position (first, second, third enum value);
end SEND_ENUM_VALUE;

	client/receiver code: 

with INTEGERS_OVER_NETWORK;
with DEFINES_ENUM_TYPE;
procedure RECEIVE_ENUM_VALUE (E : out DEFINES_ENUM_TYPE.COLOR)
is
  I : INTEGER;
begin
  INTEGERS_OVER_NETWORK.RECEIVE (I);
  if I in DEFINES_ENUM_TYPE.COLOR'POS (DEFINES_ENUM_TYPE.COLOR'FIRST))
	  .. 	DEFINES_ENUM_TYPE.COLOR'POS (DEFINES_ENUM_TYPE.COLOR'LAST))
  then
    E := DEFINES_ENUM_TYPE.COLOR'VAL (I);
  else
    -- appropriate action for out of range value, e.g. raise
    -- exception, return default value, etc.
  end if;
end RECEIVE_ENUM_VALUE;

We have used this technique for sending enumeration types across
Remote Procedure Calls.  The SEND and RECEIVE operations were
implemented using the ONC XDR xdr_int() operations (for which we have
a simple Ada binding.)

				dave

             reply	other threads:[~1993-06-29 21:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-06-29 21:05 David Emery [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-06-29 20:25 Retrieving Rep Spec'ed Enumeration Values Gene Ouye
1993-06-29 17:44 Dave Bashford
1993-06-29 16:39 agate!howland.reston.ans.net!noc.near.net!nic.umass.edu!ymir.cs.umass.edu
1993-06-28 20:58 Mark A Biggar
1993-06-28 20:47 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.
replies disabled

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