tcl.lang
Class TclDict

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

public class TclDict
extends Object
implements InternalRep

This class implements the dict object type in Tcl.


Nested Class Summary
static interface TclDict.Visitor
          An interface to traverse (visit) each key-value pair in a Tcl dictionary object.
 
Method Summary
static void appendToKey(Interp interp, TclObject dict, TclObject key, TclObject[] objv, int start, int end)
          Appends the given strings to the given key in the given dictionary object.
 void dispose()
          Called to free any storage for the type's internal rep.
 InternalRep duplicate()
          Returns a duplicate of the current object.
static Object foreach(Interp interp, Object accum, TclObject dict, TclDict.Visitor body)
          An internal iterator methods for traversing the elements of a Tcl dictionary object.
static TclObject get(Interp interp, TclObject dict, TclObject key)
          Tcl_DictObjGet.
static TclObject newInstance()
          Creates a new instance of a TclObject with a TclDict internal rep.
static void put(Interp interp, TclObject dict, TclObject key, TclObject value)
          Tcl_DictObjPut.
static void putKeyList(Interp interp, TclObject dict, TclObject[] keys, int start, int length, TclObject value)
          Tcl_DictObjPutKeyList.
static void remove(Interp interp, TclObject dict, TclObject key)
          Tcl_DictObjRemove.
static void removeKeyList(Interp interp, TclObject dict, TclObject[] keys, int start, int length)
          Tcl_DictObjRemoveKeyList.
static int size(Interp interp, TclObject dict)
          Tcl_DictObjSize.
 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()
Returns a duplicate of the current object.

Specified by:
duplicate in interface InternalRep

toString

public 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 Object
Returns:
the string representation of the Tcl object.

newInstance

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

Returns:
the TclObject with the given list value.

get

public static final TclObject get(Interp interp,
                                  TclObject dict,
                                  TclObject key)
                           throws TclException
Tcl_DictObjGet.

Throws:
TclException

put

public static final void put(Interp interp,
                             TclObject dict,
                             TclObject key,
                             TclObject value)
                      throws TclException
Tcl_DictObjPut.

Throws:
TclException

remove

public static final void remove(Interp interp,
                                TclObject dict,
                                TclObject key)
                         throws TclException
Tcl_DictObjRemove.

Throws:
TclException

size

public static final int size(Interp interp,
                             TclObject dict)
                      throws TclException
Tcl_DictObjSize.

Throws:
TclException

foreach

public static final Object foreach(Interp interp,
                                   Object accum,
                                   TclObject dict,
                                   TclDict.Visitor body)
                            throws TclException
An internal iterator methods for traversing the elements of a Tcl dictionary object. The TclDict.Visitor object is invoked for each key/value pair in the dictionary. The accum argument can be used to thread some arbitrary state through the traversal, and in this way forms a fold operation over the dictionary, familiar from functional programming languages. The Visitor object can throw a TclException to terminate the loop early either with an error (which will propagate) or with a TCL.BREAK exception which will cause termination of the loop with the current accumulator value. This method will take care of cleaning up resources associated with the loop in the event of any exception — which is the reason this is structured as an internal iterator rather than a more usual (in Java) external iterator. Equivalent in functionality to the Tcl_DictObjFirst/Next/Done C functions.

Parameters:
interp - A Tcl interpreter for reporting errors.
accum - Arbitrary state to thread through the traversal.
dict - The Tcl dictionary object.
body - The Visitor object to invoke for each key-value pair.
Returns:
The final accumulator value.
Throws:
TclException - if the visitor object throws one.

putKeyList

public static final void putKeyList(Interp interp,
                                    TclObject dict,
                                    TclObject[] keys,
                                    int start,
                                    int length,
                                    TclObject value)
                             throws TclException
Tcl_DictObjPutKeyList.

Throws:
TclException

removeKeyList

public static final void removeKeyList(Interp interp,
                                       TclObject dict,
                                       TclObject[] keys,
                                       int start,
                                       int length)
                                throws TclException
Tcl_DictObjRemoveKeyList.

Throws:
TclException

appendToKey

public static final void appendToKey(Interp interp,
                                     TclObject dict,
                                     TclObject key,
                                     TclObject[] objv,
                                     int start,
                                     int end)
                              throws TclException
Appends the given strings to the given key in the given dictionary object.

Throws:
TclException


Copyright © 2015. All rights reserved.