Manual Pages for UNIX Darwin command on man Tcl_NewListObj
MyWebUniversity

Manual Pages for UNIX Darwin command on man Tcl_NewListObj

TclListObj(3) Tcl Library Procedures TclListObj(3)

NAME

TclListObjAppendList, TclListObjAppendElement, TclNewListObj,

TclSetListObj, TclListObjGetElements, TclListObjLength, TclListOb-

jIndex, TclListObjReplace - manipulate Tcl objects as lists

SYNOPSIS

##iinncclluuddee <>

int TTccllLLiissttOObbjjAAppppeennddLLiisstt(interp, listPtr, elemListPtr) int TTccllLLiissttOObbjjAAppppeennddEElleemmeenntt(interp, listPtr, objPtr) TclObj * TTccllNNeewwLLiissttOObbjj(objc, objv) TTccllSSeettLLiissttOObbjj(objPtr, objc, objv) int TTccllLLiissttOObbjjGGeettEElleemmeennttss(interp, listPtr, objcPtr, objvPtr) int TTccllLLiissttOObbjjLLeennggtthh(interp, listPtr, intPtr) int TTccllLLiissttOObbjjIInnddeexx(interp, listPtr, index, objPtrPtr) int TTccllLLiissttOObbjjRReeppllaaccee(interp, listPtr, first, count, objc, objv) AARRGGUUMMEENNTTSS

TclInterp *interp (in) If an error occurs while con-

verting an object to be a list object, an error message is left in the interpreter's result object unless interp is NULL. TclObj *listPtr (in/out) Points to the list object to be manipulated. If listPtr does not already point to a list object, an attempt will be made to convert it to one. TclObj *elemListPtr (in/out) For TTccllLLiissttOObbjjAAppppeennddLLiisstt, this

points to a list object contain-

ing elements to be appended onto

listPtr. Each element of *elem-

ListPtr will become a new ele-

ment of listPtr. If *elem-

ListPtr is not NULL and does not already point to a list object,

an attempt will be made to con-

vert it to one. TclObj *objPtr (in) For TTccllLLiissttOObbjjAAppppeennddEElleemmeenntt, points to the Tcl object that will be appended to listPtr. For TTccllSSeettLLiissttOObbjj, this points to the Tcl object that will be

converted to a list object con-

taining the objc elements of the array referenced by objv. int *objcPtr (in) Points to location where TTccllLLiissttOObbjjGGeettEElleemmeennttss stores the number of element objects in listPtr.

TclObj ***objvPtr (out) A location where TTccllLLiissttOObb-

jjGGeettEElleemmeennttss stores a pointer to

an array of pointers to the ele-

ment objects of listPtr. int objc (in) The number of Tcl objects that TTccllNNeewwLLiissttOObbjj will insert into

a new list object, and TTccllLLiiss-

ttOObbjjRReeppllaaccee will insert into listPtr. For TTccllSSeettLLiissttOObbjj, the number of Tcl objects to insert into objPtr. | TclObj "*CONST objv[]" in || An array of pointers to objects. | TTccllNNeewwLLiissttOObbjj will insert these | objects into a new list object | and TTccllLLiissttOObbjjRReeppllaaccee will | insert them into an existing | listPtr. Each object will | become a separate list element. int *intPtr (out) Points to location where TTccllLLiissttOObbjjLLeennggtthh stores the length of the list. int index (in) Index of the list element that TTccllLLiissttOObbjjIInnddeexx is to return. The first element has index 0.

TclObj **objPtrPtr (out) Points to place where TTccllLLiissttOO-

bbjjIInnddeexx is to store a pointer to the resulting list element object.

int first (in) Index of the starting list ele-

ment that TTccllLLiissttOObbjjRReeppllaaccee is to replace. The list's first element has index 0. int count (in) The number of elements that TTccllLLiissttOObbjjRReeppllaaccee is to replace.

DESCRIPTION

Tcl list objects have an internal representation that supports the efficient indexing and appending. The procedures described in this man page are used to create, modify, index, and append to Tcl list objects from C code. TTccllLLiissttOObbjjAAppppeennddLLiisstt and TTccllLLiissttOObbjjAAppppeennddEElleemmeenntt both add one or more

objects to the end of the list object referenced by listPtr. TTccllLLiiss-

ttOObbjjAAppppeennddLLiisstt appends each element of the list object referenced by elemListPtr while TTccllLLiissttOObbjjAAppppeennddEElleemmeenntt appends the single object

referenced by objPtr. Both procedures will convert the object refer-

enced by listPtr to a list object if necessary. If an error occurs during conversion, both procedures return TTCCLLEERRRROORR and leave an error

message in the interpreter's result object if interp is not NULL. Sim-

ilarly, if elemListPtr does not already refer to a list object, TTccllLLiissttOObbjjAAppppeennddLLiisstt will attempt to convert it to one and if an error

occurs during conversion, will return TTCCLLEERRRROORR and leave an error mes-

sage in the interpreter's result object if interp is not NULL. Both procedures invalidate any old string representation of listPtr and, if

it was converted to a list object, free any old internal representa-

tion. Similarly, TTccllLLiissttOObbjjAAppppeennddLLiisstt frees any old internal repre-

sentation of elemListPtr if it converts it to a list object. After appending each element in elemListPtr, TTccllLLiissttOObbjjAAppppeennddLLiisstt increments the element's reference count since listPtr now also refers to it. For the same reason, TTccllLLiissttOObbjjAAppppeennddEElleemmeenntt increments objPtr's reference count. If no error occurs, the two procedures return TTCCLLOOKK after appending the objects. TTccllNNeewwLLiissttOObbjj and TTccllSSeettLLiissttOObbjj create a new object or modify an existing object to hold the objc elements of the array referenced by objv where each element is a pointer to a Tcl object. If objc is less than or equal to zero, they return an empty object. The new object's string representation is left invalid. The two procedures increment the reference counts of the elements in objc since the list object now refers to them. The new list object returned by TTccllNNeewwLLiissttOObbjj has reference count zero. TTccllLLiissttOObbjjGGeettEElleemmeennttss returns a count and a pointer to an array of the elements in a list object. It returns the count by storing it in the address objcPtr. Similarly, it returns the array pointer by storing it in the address objvPtr. The memory pointed to is managed by Tcl and should not be freed by the caller. If listPtr is not already a list object, TTccllLLiissttOObbjjGGeettEElleemmeennttss will attempt to convert it to one; if the conversion fails, it returns TTCCLLEERRRROORR and leaves an error message in the interpreter's result object if interp is not NULL. Otherwise it returns TTCCLLOOKK after storing the count and array pointer. TTccllLLiissttOObbjjLLeennggtthh returns the number of elements in the list object referenced by listPtr. It returns this count by storing an integer in the address intPtr. If the object is not already a list object, TTccllLLiissttOObbjjLLeennggtthh will attempt to convert it to one; if the conversion

fails, it returns TTCCLLEERRRROORR and leaves an error message in the inter-

preter's result object if interp is not NULL. Otherwise it returns TTCCLLOOKK after storing the list's length.

The procedure TTccllLLiissttOObbjjIInnddeexx returns a pointer to the object at ele-

ment index in the list referenced by listPtr. It returns this object by storing a pointer to it in the address objPtrPtr. If listPtr does not already refer to a list object, TTccllLLiissttOObbjjIInnddeexx will attempt to convert it to one; if the conversion fails, it returns TTCCLLEERRRROORR and leaves an error message in the interpreter's result object if interp is not NULL. If the index is out of range, that is, index is negative or

greater than or equal to the number of elements in the list, TTccllLLiissttOO-

bbjjIInnddeexx stores a NULL in objPtrPtr and returns TTCCLLOOKK. Otherwise it

returns TTCCLLOOKK after storing the element's object pointer. The refer-

ence count for the list element is not incremented; the caller must do that if it needs to retain a pointer to the element.

TTccllLLiissttOObbjjRReeppllaaccee replaces zero or more elements of the list refer-

enced by listPtr with the objc objects in the array referenced by objv. If listPtr does not point to a list object, TTccllLLiissttOObbjjRReeppllaaccee will attempt to convert it to one; if the conversion fails, it returns TTCCLLEERRRROORR and leaves an error message in the interpreter's result object if interp is not NULL. Otherwise, it returns TTCCLLOOKK after replacing the objects. If objv is NULL, no new elements are added. If the argument first is zero or negative, it refers to the first element. If first is greater than or equal to the number of elements in the list, then no elements are deleted; the new elements are appended to the list. count gives the number of elements to replace. If count is zero or negative then no elements are deleted; the new elements are simply inserted before the one designated by first. TTccllLLiissttOObbjjRReeppllaaccee invalidates listPtr's old string representation. The reference counts of any elements inserted from objv are incremented since the resulting list now refers to them. Similarly, the reference counts for any replaced objects are decremented.

Because TTccllLLiissttOObbjjRReeppllaaccee combines both element insertion and dele-

tion, it can be used to implement a number of list operations. For example, the following code inserts the objc objects referenced by the array of object pointers objv just before the element index of the list referenced by listPtr: result = TclListObjReplace(interp, listPtr, index, 0, objc, objv); Similarly, the following code appends the objc objects referenced by the array objv to the end of the list listPtr: result = TclListObjLength(interp, listPtr, &length); if (result == TCLOK) { result = TclListObjReplace(interp, listPtr, length, 0, objc, objv); } The count list elements starting at first can be deleted by simply calling TTccllLLiissttOObbjjRReeppllaaccee with a NULL objvPtr: result = TclListObjReplace(interp, listPtr, first, count, 0, NULL);

SEE ALSO

TclNewObj, TclDecrRefCount, TclIncrRefCount, TclGetObjResult KKEEYYWWOORRDDSS append, index, insert, internal representation, length, list, list object, list type, object, object type, replace, string representation Tcl 8.0 TclListObj(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™