tcl.lang
Class TclObject

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

public final class TclObject
extends Object

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


Field Summary
protected static String DEALLOCATED_MSG
           
protected  InternalRep internalRep
           
 long ivalue
          The ivalue field is used for a TclObject that contains an integer value.
protected  int refCount
           
protected  String stringRep
           
 
Constructor Summary
  TclObject(InternalRep rep)
          Creates a TclObject with the given InternalRep.
protected TclObject(long ivalue)
          Creates a TclObject with the given integer value.
protected TclObject(TclString rep, String s)
          Creates a TclObject with the given InternalRep and stringRep.
 
Method Summary
protected  void disposedError()
          Raise a TclRuntimeError in the case where a TclObject was already disposed of because the last ref was released.
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.
 boolean equals(Object o)
           
 InternalRep getInternalRep()
          Returns the handle to the current internal rep.
static String getObjRecords()
          Return a String that describes TclObject and internal rep type allocations and conversions.
 int getRefCount()
          Returns the refCount of this object.
 int hashCode()
           
 boolean hasNoStringRep()
           
 void invalidateStringRep()
          Sets the string representation of the object to null.
 boolean isByteArrayType()
           
 boolean isDoubleType()
           
 boolean isIntType()
           
 boolean isListType()
           
 boolean isShared()
          Returns true if the TclObject is shared, false otherwise.
 boolean isStringType()
           
 boolean isWideIntType()
           
 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.
 String toString()
          Returns the string representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

internalRep

protected InternalRep internalRep

refCount

protected int refCount

stringRep

protected String stringRep

DEALLOCATED_MSG

protected static final String DEALLOCATED_MSG
See Also:
Constant Field Values

ivalue

public long ivalue
The ivalue field is used for a TclObject that contains an integer value. This implementation uses less memory than the previous approach that stored an int value in a internal rep of type TclInteger. This implementation executes integer operations more quickly since instanceof and upcast operations are no longer needed in the critical execution path. The ivalue field is always set after a call to setInternalRep() in the TclInteger class.

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,
                    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(long 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 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.


equals

public boolean equals(Object o)

hashCode

public int hashCode()

isIntType

public final boolean isIntType()
Returns:
true if the TclObject contains an int.

isStringType

public final boolean isStringType()
Returns:
true if the TclObject contains a TclString.

isDoubleType

public final boolean isDoubleType()
Returns:
true if the TclObject contains a TclDouble

isWideIntType

public final boolean isWideIntType()
Returns:
true if the TclObject contains a TclWideInteger.

isListType

public final boolean isListType()
Returns:
true if the TclObject contains a TclList.

isByteArrayType

public final boolean isByteArrayType()
Returns:
true if the TclObject contains a TclByteArray

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 String toString()
Returns the string representation of the object.

Overrides:
toString in class 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

getRefCount

public final int getRefCount()
Returns the refCount of this object.

Returns:
refCount.

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()
Raise a TclRuntimeError in the case where a TclObject was already disposed of because the last ref was released.


hasNoStringRep

public final boolean hasNoStringRep()


Copyright © 2015. All rights reserved.