All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.ifarchive.glk.OpaqueObject

java.lang.Object
   |
   +----org.ifarchive.glk.OpaqueObject

public class OpaqueObject
extends Object
Base class for wrapping opaque Glk objects.

This class contains general methods for handling any type of Glk object. Objects supported by the library have particular subclasses such as Window or Stream. You will only need to deal with OpaqueObject directly if the underlying Glk library contains object types not supported in this wrapper library.


Variable Index

 o clFileRef
Glk class number for file references
 o clSoundChannel
Glk class number for sound channels
 o clStream
Glk class number for streams
 o clWindow
Glk class number for windows
 o m_dispid
Reference to the underlying Glk object.
 o m_glkClass
The number of the Glk class to which this object belongs.
 o m_jrock
Rock given to this object if it was created within Java.

Constructor Index

 o OpaqueObject(int, int)
Constructor.

Method Index

 o castRock(Object)
Convert a Java rock to a Glk rock.
 o destroy()
Destroy this object and the underlying Glk object.
 o finalize()
If the Glk object is still in existence when this object is garbage-collected, destroy it.
 o getClassCount()
Count Glk classes.
 o getDispatchRock()
Get this object's dispatch rock.
 o getRock()
Return this object's rock.
 o iterate(int, OpaqueObject, Object[])
Generalised iterator.
 o setRegistry(ObjectRegistry)
Set an opaque object registry.
 o toString()
Text representation of this object.

Variables

 o m_dispid
 protected int m_dispid
Reference to the underlying Glk object. This is a unique integer; the C layer translates it to a pointer. If m_dispid is 0, the Glk object has been destroyed by the Glk library.

 o m_jrock
 protected Object m_jrock
Rock given to this object if it was created within Java. If this is null, the object was created by Glk, and its rock must be found by a glk_get_*_rock() call.

 o m_glkClass
 protected int m_glkClass
The number of the Glk class to which this object belongs.

See Also:
clWindow, clStream, clFileRef, clSoundChannel
 o clWindow
 public static final int clWindow
Glk class number for windows

 o clStream
 public static final int clStream
Glk class number for streams

 o clFileRef
 public static final int clFileRef
Glk class number for file references

 o clSoundChannel
 public static final int clSoundChannel
Glk class number for sound channels

Constructors

 o OpaqueObject
 protected OpaqueObject(int glkClass,
                        int dispid)
Constructor.

Parameters:
glkClass - The Glk class this object is in.
dispid - The dispatch ID assigned to this object.

Methods

 o toString
 public String toString()
Text representation of this object.

Returns:
A text string containing this object's Glk class, identity, and rock.
Overrides:
toString in class Object
 o iterate
 public static OpaqueObject iterate(int glkClass,
                                    OpaqueObject o,
                                    Object r[])
Generalised iterator. For a given object, find the next object of that class (ordering is arbitrary, but this will find all objects of the chosen class). If the parameter "o" is null, the first object of that class is returned.

Parameters:
glkClass - Glk class number of objects to iterate over
o - null, or an object of the correct class.
r - If not null, r[0] will be set to the returned object's rock.
Returns:
The next object, or null if there is no next object
 o finalize
 protected void finalize()
If the Glk object is still in existence when this object is garbage-collected, destroy it.

Overrides:
finalize in class Object
 o destroy
 protected void destroy()
Destroy this object and the underlying Glk object. This method must be overridden in subclasses since Glk has no way of destroying an object of unknown type.

 o getRock
 public Object getRock()
Return this object's rock. If the object was created by Glk, the rock will be of class Long. Otherwise it can be any class.

Returns:
The object's rock.
 o castRock
 protected static int castRock(Object object)
Convert a Java rock to a Glk rock.

Glk for Java allows a rock to be an object of any type, by storing the rock in the Java layer rather than the underlying Glk layer. However, if the object really is a number, then there's no harm it setting it at the Glk level as well as the Java level.

Parameters:
object - Any object.
Returns:
If object is a number, its integer value. Otherwise 0.
 o getClassCount
 public static int getClassCount()
Count Glk classes.

Returns:
The number of Glk object classes in the underlying Glk library.
 o getDispatchRock
 public Object getDispatchRock()
Get this object's dispatch rock. This will only have been set if an opaque object registry is in use.

Returns:
The dispatch rock.
 o setRegistry
 public static void setRegistry(ObjectRegistry r)
Set an opaque object registry. It will be called when opaque objects are created or destroyed.

Parameters:
r - An instance of your object registry.

All Packages  Class Hierarchy  This Package  Previous  Next  Index