tcl.lang
Class TclObject

java.lang.Object
  extended by tcl.lang.TclObject

public final class TclObject
extends java.lang.Object

This class extends TclObjectBase to implement the basic notion of an object in Tcl.


Field Summary
protected static java.lang.RuntimeException DEALLOCATED
          Raise a TclRuntimeError in the case where a TclObject was already disposed of because the last ref was released.
protected  InternalRep internalRep
           
protected  int refCount
           
protected  java.lang.String stringRep
           
 
Constructor Summary
protected TclObject(int ivalue)
          Creates a TclObject with the given integer value.
  TclObject(InternalRep rep)
          Creates a TclObject with the given InternalRep.
protected TclObject(TclString rep, java.lang.String s)
          Creates a TclObject with the given InternalRep and stringRep.
 
Method Summary
protected  void disposedError()
           
protected  void disposeObject()
          Dispose of the TclObject when the refCount reaches 0.
 TclObject duplicate()
          Tcl_DuplicateObj -> duplicate Duplicate a TclObject, this method provides the preferred means to deal with modification of a shared TclObject.
 InternalRep getInternalRep()
          Returns the handle to the current internal rep.
static java.lang.String getObjRecords()
          Return a String that describes TclObject and internal rep type allocations and conversions.
 void invalidateStringRep()
          Sets the string representation of the object to null.
 boolean isDoubleType()
           
 boolean isIntType()
           
 boolean isShared()
          Returns true if the TclObject is shared, false otherwise.
 void preserve()
          Tcl_IncrRefCount -> preserve Increments the refCount to indicate the caller's intent to preserve the value of this object.
 void release()
          Tcl_DecrRefCount -> release Decrements the refCount to indicate that the caller is no longer interested in the value of this object.
 void setInternalRep(InternalRep rep)
          Change the internal rep of the object.
 TclObject takeExclusive()
          Deprecated. The takeExclusive method has been deprecated in favor of the new duplicate() method. The takeExclusive method would modify the ref count of the original object and return an object with a ref count of 1 instead of 0. These two behaviors lead to lots of useless duplication of objects that could be modified directly. This method exists only for backwards compatibility and will be removed at some point.
 java.lang.String toString()
          Returns the string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

internalRep

protected InternalRep internalRep

refCount

protected int refCount

stringRep

protected java.lang.String stringRep

DEALLOCATED

protected static final java.lang.RuntimeException DEALLOCATED
Raise a TclRuntimeError in the case where a TclObject was already disposed of because the last ref was released.

Constructor Detail

TclObject

public TclObject(InternalRep rep)
Creates a TclObject with the given InternalRep. This method should be called only by an InternalRep implementation.

Parameters:
rep - the initial InternalRep for this object.

TclObject

protected TclObject(TclString rep,
                    java.lang.String s)
Creates a TclObject with the given InternalRep and stringRep. This constructor is used by the TclString class only. No other place should call this constructor.

Parameters:
rep - the initial InternalRep for this object.
s - the initial string rep for this object.

TclObject

protected TclObject(int ivalue)
Creates a TclObject with the given integer value. This constructor is used by the TclInteger class only. No other place should call this constructor.

Parameters:
ivalue - the integer value
Method Detail

preserve

public final void preserve()
Tcl_IncrRefCount -> preserve Increments the refCount to indicate the caller's intent to preserve the value of this object. Each preserve() call must be matched by a corresponding release() call. This method is Jacl specific and is intended to be easily inlined in calling code.

Throws:
TclRuntimeError - if the object has already been deallocated.

release

public final void release()
Tcl_DecrRefCount -> release Decrements the refCount to indicate that the caller is no longer interested in the value of this object. If the refCount reaches 0, the object will be deallocated. This method is Jacl specific an is intended to be easily inlined in calling code.

Throws:
TclRuntimeError - if the object has already been deallocated.

getObjRecords

public static java.lang.String getObjRecords()
Return a String that describes TclObject and internal rep type allocations and conversions. The string is in lines separated by newlines. The saveObjRecords needs to be set to true and Jacl recompiled for this method to return a useful value.


isIntType

public final boolean isIntType()

isDoubleType

public final boolean isDoubleType()

getInternalRep

public final InternalRep getInternalRep()
Returns the handle to the current internal rep. This method should be called only by an InternalRep implementation.

Returns:
the handle to the current internal rep.

setInternalRep

public void setInternalRep(InternalRep rep)
Change the internal rep of the object. The old internal rep will be deallocated as a result. This method should be called only by an InternalRep implementation.

Parameters:
rep - the new internal rep.

toString

public final java.lang.String toString()
Returns the string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of the object.

invalidateStringRep

public final void invalidateStringRep()
                               throws TclRuntimeError
Sets the string representation of the object to null. Next time when toString() is called, getInternalRep().toString() will be called. This method should be called ONLY when an InternalRep is about to modify the value of a TclObject.

Throws:
TclRuntimeError - if object is not exclusively owned.

isShared

public final boolean isShared()
Returns true if the TclObject is shared, false otherwise.


duplicate

public final TclObject duplicate()
Tcl_DuplicateObj -> duplicate Duplicate a TclObject, this method provides the preferred means to deal with modification of a shared TclObject. It should be invoked in conjunction with isShared instead of using the deprecated takeExclusive method. Example: if (tobj.isShared()) { tobj = tobj.duplicate(); } TclString.append(tobj, "hello");

Returns:
an TclObject with a refCount of 0.

takeExclusive

public final TclObject takeExclusive()
                              throws TclRuntimeError
Deprecated. The takeExclusive method has been deprecated in favor of the new duplicate() method. The takeExclusive method would modify the ref count of the original object and return an object with a ref count of 1 instead of 0. These two behaviors lead to lots of useless duplication of objects that could be modified directly. This method exists only for backwards compatibility and will be removed at some point.

Throws:
TclRuntimeError

disposeObject

protected final void disposeObject()
Dispose of the TclObject when the refCount reaches 0.

Throws:
TclRuntimeError - if the object has already been deallocated.

disposedError

protected final void disposedError()