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

Variable Index

 o ARRAY
This object represents an array.
 o CHAR
This object represents a native character.
 o OPAQUE
This object represents an opaque object.
 o PTRFLAG
This object represents a pointer flag.
 o SCHAR
This object represents a signed character.
 o SINT
This object represents a signed integer.
 o STRING
This object represents a string.
 o UCHAR
This object represents an unsigned character.
 o UINT
This object represents an unsigned integer.

Constructor Index

 o UniversalUnion(boolean)
Construct a UniversalUnion that holds a pointer flag.
 o UniversalUnion(byte[])
Construct a UniversalUnion that holds an array of bytes.
 o UniversalUnion(char[])
Construct a UniversalUnion that holds an array of characters.
 o UniversalUnion(int, char)
Construct a UniversalUnion that holds a character.
 o UniversalUnion(int, int)
Construct a UniversalUnion that holds an integer.
 o UniversalUnion(int[])
Construct a UniversalUnion that holds an array of ints.
 o UniversalUnion(long)
Construct a UniversalUnion that holds an unsigned int.
 o UniversalUnion(long[])
Construct a UniversalUnion that holds an array of longs.
 o UniversalUnion(OpaqueObject, int)
Construct a UniversalUnion that holds an opaque object.
 o UniversalUnion(short[])
Construct a UniversalUnion that holds an array of shorts.
 o UniversalUnion(String)
Construct a UniversalUnion that holds a C string.

Method Index

 o charVal()
If this object holds something that can be expressed as a character, return it.
 o finalize()
Release any arrays or character strings.
 o getType()
Get the type of this object
 o intVal()
If this object holds something that can be expressed as an integer, return it.
 o longVal()
If this object holds something that can be expressed as a long, return it.
 o opaqueVal()
If this object holds something that can be expressed as an opaque object, return it.
 o release()
Release any arrays or character strings associated with this object.
 o toString()
Produce a printable representation of this object.

Variables

 o UINT
 public static final int UINT
This object represents an unsigned integer.

See Also:
getType
 o SINT
 public static final int SINT
This object represents a signed integer.

See Also:
getType
 o OPAQUE
 public static final int OPAQUE
This object represents an opaque object.

See Also:
getType
 o UCHAR
 public static final int UCHAR
This object represents an unsigned character.

See Also:
getType
 o SCHAR
 public static final int SCHAR
This object represents a signed character.

See Also:
getType
 o 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
 o STRING
 public static final int STRING
This object represents a string.

See Also:
getType
 o ARRAY
 public static final int ARRAY
This object represents an array.

See Also:
getType
 o PTRFLAG
 public static final int PTRFLAG
This object represents a pointer flag.

See Also:
getType

Constructors

 o 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.
 o UniversalUnion
 public UniversalUnion(long v)
Construct a UniversalUnion that holds an unsigned int.

Parameters:
v - The value to pass in.
 o 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).
 o 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.
 o UniversalUnion
 public UniversalUnion(int type,
                       int v)
Construct a UniversalUnion that holds an integer.

Parameters:
type - UINT or SINT
v - Value of integer.
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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

Methods

 o getType
 public int getType()
Get the type of this object

 o toString
 public String toString()
Produce a printable representation of this object.

Returns:
The printed representation.
Overrides:
toString in class Object
 o 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.
 o 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
 o 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.
 o 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.
 o 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.
 o 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