01: /*
02: * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
03: * Copyright (C) 2005 - Javolution (http://javolution.org/)
04: * All rights reserved.
05: *
06: * Permission to use, copy, modify, and distribute this software is
07: * freely granted, provided that this notice is preserved.
08: */
09: package javolution.io;
10:
11: /**
12: * <p> This class represents a <code>C/C++ union</code>; it works in the same
13: * way as {@link Struct} (sub-class) except that all members are mapped
14: * to the same location in memory.</p>
15: * <p> Here is an example of C union: [code]
16: * union Number {
17: * int asInt;
18: * float asFloat;
19: * char asString[12];
20: * };[/code]
21: * And its Java equivalent:[code]
22: * public class Number extends Union {
23: * Signed32 asInt = new Signed32();
24: * Float32 asFloat = new Float32();
25: * Utf8String asString = new Utf8String(12);
26: * }[/code]
27: * As for any {@link Struct}, fields are directly accessible:[code]
28: * Number num = new Number();
29: * num.asInt.set(23);
30: * num.asString.set("23"); // Null terminated (C compatible)
31: * float f = num.asFloat.get();[/code]
32: *
33: * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
34: * @version 1.0, October 4, 2004
35: */
36: public abstract class Union extends Struct {
37:
38: /**
39: * Default constructor.
40: */
41: public Union() {
42: }
43:
44: /**
45: * Returns <code>true</code>.
46: *
47: * @return <code>true</code>
48: */
49: public final boolean isUnion() {
50: return true;
51: }
52: }
|