JADE v6.1

com.dautelle.util
Class Union

java.lang.Object
  extended bycom.dautelle.util.Struct
      extended bycom.dautelle.util.Union

public abstract class Union
extends Struct

This class represents a C/C++ union; it works in the same way as Struct (sub-class) except that all members are mapped to the same location in memory.

Here is an example of C union:

     union Number {
         int   asInt;
         float asFloat;
         char  asString[12];
     };
And its Java equivalent:
     public class Number extends Union {
         Signed32   asInt    = new Signed32();
         Float32    asFloat  = new Float32();
         UTF8String asString = new UTF8String(12);
     }
As for any Struct, fields are directly accessible:
     Number num = new Number();
     num.asInt.set(23);
     num.asString.set("23"); // Null terminated (C compatible)
     float f = num.asFloat.get();

This class is public domain (not copyrighted).

Version:
5.2, September 28, 2003
Author:
Jean-Marie Dautelle

Nested Class Summary
 
Nested classes inherited from class com.dautelle.util.Struct
Struct.ArrayMember, Struct.Bool, Struct.Enum16, Struct.Enum32, Struct.Enum64, Struct.Enum8, Struct.Float32, Struct.Float64, Struct.Member, Struct.Reference32, Struct.Reference64, Struct.Signed16, Struct.Signed32, Struct.Signed64, Struct.Signed8, Struct.StructMember, Struct.Unsigned16, Struct.Unsigned32, Struct.Unsigned8, Struct.UTF8String
 
Constructor Summary
Union()
          Default constructor.
Union(java.nio.ByteBuffer buffer)
          Creates a Union backed by the specified ByteBuffer.
 
Methods inherited from class com.dautelle.util.Struct
address, byteBuffer, byteOrder, copy, equals, hashCode, isPacked, size, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Union

public Union()
Default constructor. Top-level Union created using this constructor are backed by a direct buffer.


Union

public Union(java.nio.ByteBuffer buffer)
Creates a Union backed by the specified ByteBuffer.

Parameters:
buffer - the byte buffer for this Union.

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.