tcl.lang
Class TclList

java.lang.Object
  extended by tcl.lang.TclList
All Implemented Interfaces:
InternalRep

public class TclList
extends java.lang.Object
implements InternalRep

This class implements the list object type in Tcl.


Method Summary
static void append(Interp interp, TclObject tobj, TclObject elemObj)
          Tcl_ListObjAppendElement -> TclList.append() Appends a TclObject element to a list object.
 void dispose()
          Called to free any storage for the type's internal rep.
 InternalRep duplicate()
          DupListInternalRep -> duplicate Returns a dupilcate of the current object.
static TclObject[] getElements(Interp interp, TclObject tobj)
          Returns a TclObject array of the elements in a list object.
static int getLength(Interp interp, TclObject tobj)
          Queries the length of the list.
static TclObject index(Interp interp, TclObject tobj, int index)
          This procedure returns a pointer to the index'th object from the list referenced by tobj.
static TclObject newInstance()
          Creates a new instance of a TclObject with a TclList internal rep.
static void replace(Interp interp, TclObject tobj, int index, int count, TclObject[] elements, int from, int to)
          This procedure replaces zero or more elements of the list referenced by tobj with the objects from an TclObject array.
 java.lang.String toString()
          Called to query the string representation of the Tcl object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

dispose

public void dispose()
Called to free any storage for the type's internal rep.

Specified by:
dispose in interface InternalRep

duplicate

public InternalRep duplicate()
DupListInternalRep -> duplicate Returns a dupilcate of the current object.

Specified by:
duplicate in interface InternalRep

toString

public java.lang.String toString()
Called to query the string representation of the Tcl object. This method is called only by TclObject.toString() when TclObject.stringRep is null.

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

newInstance

public static TclObject newInstance()
Creates a new instance of a TclObject with a TclList internal rep.

Returns:
the TclObject with the given list value.

append

public static final void append(Interp interp,
                                TclObject tobj,
                                TclObject elemObj)
                         throws TclException
Tcl_ListObjAppendElement -> TclList.append() Appends a TclObject element to a list object.

Parameters:
interp - current interpreter.
tobj - the TclObject to append an element to.
elemObj - the element to append to the object.
Throws:
TclException - if tobj cannot be converted into a list.

getLength

public static final int getLength(Interp interp,
                                  TclObject tobj)
                           throws TclException
Queries the length of the list. If tobj is not a list object, an attempt will be made to convert it to a list.

Parameters:
interp - current interpreter.
tobj - the TclObject to use as a list.
Returns:
the length of the list.
Throws:
TclException - if tobj is not a valid list.

getElements

public static TclObject[] getElements(Interp interp,
                                      TclObject tobj)
                               throws TclException
Returns a TclObject array of the elements in a list object. If tobj is not a list object, an attempt will be made to convert it to a list.

The objects referenced by the returned array should be treated as readonly and their ref counts are _not_ incremented; the caller must do that if it holds on to a reference.

Parameters:
interp - the current interpreter.
tobj - the list to sort.
Returns:
a TclObject array of the elements in a list object.
Throws:
TclException - if tobj is not a valid list.

index

public static final TclObject index(Interp interp,
                                    TclObject tobj,
                                    int index)
                             throws TclException
This procedure returns a pointer to the index'th object from the list referenced by tobj. The first element has index 0. If index is negative or greater than or equal to the number of elements in the list, a null is returned. If tobj is not a list object, an attempt will be made to convert it to a list.

Parameters:
interp - current interpreter.
tobj - the TclObject to use as a list.
index - the index of the requested element.
Returns:
the the requested element.
Throws:
TclException - if tobj is not a valid list.

replace

public static final void replace(Interp interp,
                                 TclObject tobj,
                                 int index,
                                 int count,
                                 TclObject[] elements,
                                 int from,
                                 int to)
                          throws TclException
This procedure replaces zero or more elements of the list referenced by tobj with the objects from an TclObject array. If tobj is not a list object, an attempt will be made to convert it to a list.

Parameters:
interp - current interpreter.
tobj - the TclObject to use as a list.
index - the starting index of the replace operation. <=0 means the beginning of the list. >= TclList.getLength(tobj) means the end of the list.
count - the number of elements to delete from the list. <=0 means no elements should be deleted and the operation is equivalent to an insertion operation.
elements - the element(s) to insert.
from - insert elements starting from elements[from] (inclusive)
to - insert elements up to elements[to] (inclusive)
Throws:
TclException - if tobj is not a valid list.