All Packages Class Hierarchy This Package Previous Next Index
Class org.ifarchive.glk.UniversalUnion
java.lang.Object
|
+----org.ifarchive.glk.UniversalUnion
- public class UniversalUnion
- extends Object
The UniversalUnion is a Glk dispatch argument.
Use these if you want to marshal your own arguments to Glk.dispatchCall().
For example, to call glk_select():
Event ev;
UniversalUnion args[] = new UniversalUnion[5];
args[0] = new UniversalUnion(true); // pointer flag
args[1] = new UniversalUnion(UniversalUnion.UINT, 0); // uint
args[2] = new UniversalUnion(null, OpaqueObject.clWindow);
// null pointer to Window
args[3] = new UniversalUnion(UniversalUnion.UINT, 0); // uint
args[4] = new UniversalUnion(UniversalUnion.UINT, 0); // uint
Glk.dispatchCall(0x00C0, args); // call glk_event()
ev.type = args[1].intVal();
ev.win = (Window)(args[2].opaqueVal);
ev.val1 = args[3].longVal();
ev.val2 = args[4].longVal();
note that unlike in C-Glk, you have to populate args[] even for parameters
that are only used for output.
Here's an example using arrays to do glk_put_buffer_stream():
byte buf[64];
...populate buf...
UniversalUnion args[] = new UniversalUnion[4];
args[0] = new UniversalUnion(myStream, OpaqueObject.clStream); // stream
args[1] = new UniversalUnion(true); // pointer flag
args[2] = new UniversalUnion(buf); // byte array
args[3] = new UniversalUnion(UniversalUnion.UINT, buf.length); // buffer length
Glk.dispatchCall(0x0085, args); // glk_put_buffer()
args[2].release(); // All arrays and strings must be released
- See Also:
- dispatchCall
-
ARRAY
- This object represents an array.
-
CHAR
- This object represents a native character.
-
OPAQUE
- This object represents an opaque object.
-
PTRFLAG
- This object represents a pointer flag.
-
SCHAR
- This object represents a signed character.
-
SINT
- This object represents a signed integer.
-
STRING
- This object represents a string.
-
UCHAR
- This object represents an unsigned character.
-
UINT
- This object represents an unsigned integer.
-
UniversalUnion(boolean)
- Construct a UniversalUnion that holds a pointer flag.
-
UniversalUnion(byte[])
- Construct a UniversalUnion that holds an array of bytes.
-
UniversalUnion(char[])
- Construct a UniversalUnion that holds an array of characters.
-
UniversalUnion(int, char)
- Construct a UniversalUnion that holds a character.
-
UniversalUnion(int, int)
- Construct a UniversalUnion that holds an integer.
-
UniversalUnion(int[])
- Construct a UniversalUnion that holds an array of ints.
-
UniversalUnion(long)
- Construct a UniversalUnion that holds an unsigned int.
-
UniversalUnion(long[])
- Construct a UniversalUnion that holds an array of longs.
-
UniversalUnion(OpaqueObject, int)
- Construct a UniversalUnion that holds an opaque object.
-
UniversalUnion(short[])
- Construct a UniversalUnion that holds an array of shorts.
-
UniversalUnion(String)
- Construct a UniversalUnion that holds a C string.
-
charVal()
- If this object holds something that can be expressed as a character,
return it.
-
finalize()
- Release any arrays or character strings.
-
getType()
- Get the type of this object
-
intVal()
- If this object holds something that can be expressed as an integer,
return it.
-
longVal()
- If this object holds something that can be expressed as a long,
return it.
-
opaqueVal()
- If this object holds something that can be expressed as an opaque
object, return it.
-
release()
- Release any arrays or character strings associated with this object.
-
toString()
- Produce a printable representation of this object.
UINT
public static final int UINT
- This object represents an unsigned integer.
- See Also:
- getType
SINT
public static final int SINT
- This object represents a signed integer.
- See Also:
- getType
OPAQUE
public static final int OPAQUE
- This object represents an opaque object.
- See Also:
- getType
UCHAR
public static final int UCHAR
- This object represents an unsigned character.
- See Also:
- getType
SCHAR
public static final int SCHAR
- This object represents a signed character.
- See Also:
- getType
CHAR
public static final int CHAR
- This object represents a native character.
It can be signed or unsigned depending on the underlying C compiler.
- See Also:
- getType
STRING
public static final int STRING
- This object represents a string.
- See Also:
- getType
ARRAY
public static final int ARRAY
- This object represents an array.
- See Also:
- getType
PTRFLAG
public static final int PTRFLAG
- This object represents a pointer flag.
- See Also:
- getType
UniversalUnion
public UniversalUnion(int type,
char v)
- Construct a UniversalUnion that holds a character.
- Parameters:
- type - UCHAR, SCHAR or CHAR
- v - The character to pass in.
UniversalUnion
public UniversalUnion(long v)
- Construct a UniversalUnion that holds an unsigned int.
- Parameters:
- v - The value to pass in.
UniversalUnion
public UniversalUnion(OpaqueObject o,
int glkc)
- Construct a UniversalUnion that holds an opaque object.
- Parameters:
- o - The object to store.
- glkc - The object's Glk class (used only if the object itself is null).
UniversalUnion
public UniversalUnion(boolean b)
- Construct a UniversalUnion that holds a pointer flag.
- Parameters:
- b - true if the pointer is valid, false if it's null.
UniversalUnion
public UniversalUnion(int type,
int v)
- Construct a UniversalUnion that holds an integer.
- Parameters:
- type - UINT or SINT
- v - Value of integer.
UniversalUnion
public UniversalUnion(String s)
- Construct a UniversalUnion that holds a C string.
You must call release() on this object after you have
made the Glk call that uses it.
- Parameters:
- s - The string to store.
- See Also:
- release
UniversalUnion
public UniversalUnion(byte bytes[])
- Construct a UniversalUnion that holds an array of bytes.
You must call release() on this object after you have made
the Glk call that uses it.
- Parameters:
- bytes - The array to store.
- See Also:
- release
UniversalUnion
public UniversalUnion(int ints[])
- Construct a UniversalUnion that holds an array of ints.
You must call release() on this object after you have made
the Glk call that uses it.
- Parameters:
- ints - The array to store.
- See Also:
- release
UniversalUnion
public UniversalUnion(short shorts[])
- Construct a UniversalUnion that holds an array of shorts.
You must call release() on this object after you have made
the Glk call that uses it.
- Parameters:
- shorts - The array to store.
- See Also:
- release
UniversalUnion
public UniversalUnion(long longs[])
- Construct a UniversalUnion that holds an array of longs.
You must call release() on this object after you have made
the Glk call that uses it.
- Parameters:
- longs - The array to store.
- See Also:
- release
UniversalUnion
public UniversalUnion(char chars[])
- Construct a UniversalUnion that holds an array of characters.
You must call release() on this object after you have made
the Glk call that uses it.
- Parameters:
- chars - The array to store.
- See Also:
- release
getType
public int getType()
- Get the type of this object
toString
public String toString()
- Produce a printable representation of this object.
- Returns:
- The printed representation.
- Overrides:
- toString in class Object
release
public boolean release()
- Release any arrays or character strings associated with this object.
- Returns:
- false if Glk has retained the array this object represents, else true.
finalize
protected void finalize()
- Release any arrays or character strings. Unfortunately you can't
guarantee finalize() will be called, which is why release() is
there.
- Overrides:
- finalize in class Object
- See Also:
- release
longVal
public long longVal()
- If this object holds something that can be expressed as a long,
return it.
- Returns:
- The value, if possible; else -1.
intVal
public int intVal()
- If this object holds something that can be expressed as an integer,
return it.
- Returns:
- The value, if possible; else -1.
charVal
public char charVal()
- If this object holds something that can be expressed as a character,
return it.
- Returns:
- The value, if possible; else 0xFFFF.
opaqueVal
public OpaqueObject opaqueVal()
- If this object holds something that can be expressed as an opaque
object, return it.
- Returns:
- an opaque object, or null.
All Packages Class Hierarchy This Package Previous Next Index