|
JADE v6.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.dautelle.util.Struct
com.dautelle.util.Union
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).
| 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 |
public Union()
Union created using this
constructor are backed by a direct buffer.
public Union(java.nio.ByteBuffer buffer)
Union backed by the specified ByteBuffer.
buffer - the byte buffer for this Union.
|
JADE v6.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||