OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [ListObj.3] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1996-1997 Sun Microsystems, Inc.
3
'\"
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6
'\"
7
'\" RCS: @(#) $Id: ListObj.3,v 1.1.1.1 2002-01-16 10:25:24 markom Exp $
8
'\"
9
.so man.macros
10
.TH Tcl_ListObj 3 8.0 Tcl "Tcl Library Procedures"
11
.BS
12
.SH NAME
13
Tcl_ListObjAppendList, Tcl_ListObjAppendElement, Tcl_NewListObj, Tcl_SetListObj, Tcl_ListObjGetElements, Tcl_ListObjLength, Tcl_ListObjIndex, Tcl_ListObjReplace \- manipulate Tcl objects as lists
14
.SH SYNOPSIS
15
.nf
16
\fB#include \fR
17
.sp
18
int
19
\fBTcl_ListObjAppendList\fR(\fIinterp, listPtr, elemListPtr\fR)
20
.sp
21
int
22
\fBTcl_ListObjAppendElement\fR(\fIinterp, listPtr, objPtr\fR)
23
.sp
24
Tcl_Obj *
25
\fBTcl_NewListObj\fR(\fIobjc, objv\fR)
26
.sp
27
\fBTcl_SetListObj\fR(\fIobjPtr, objc, objv\fR)
28
.sp
29
int
30
\fBTcl_ListObjGetElements\fR(\fIinterp, listPtr, objcPtr, objvPtr\fR)
31
.sp
32
int
33
\fBTcl_ListObjLength\fR(\fIinterp, listPtr, intPtr\fR)
34
.sp
35
int
36
\fBTcl_ListObjIndex\fR(\fIinterp, listPtr, index, objPtrPtr\fR)
37
.sp
38
int
39
\fBTcl_ListObjReplace\fR(\fIinterp, listPtr, first, count, objc, objv\fR)
40
.SH ARGUMENTS
41
.AS Tcl_Interp "*CONST objv[]" out
42
.AP Tcl_Interp *interp in
43
If an error occurs while converting an object to be a list object,
44
an error message is left in the interpreter's result object
45
unless \fIinterp\fR is NULL.
46
.AP Tcl_Obj *listPtr in/out
47
Points to the list object to be manipulated.
48
If \fIlistPtr\fR does not already point to a list object,
49
an attempt will be made to convert it to one.
50
.AP Tcl_Obj *elemListPtr in/out
51
For \fBTcl_ListObjAppendList\fR, this points to a list object
52
containing elements to be appended onto \fIlistPtr\fR.
53
Each element of *\fIelemListPtr\fR will
54
become a new element of \fIlistPtr\fR.
55
If *\fIelemListPtr\fR is not NULL and
56
does not already point to a list object,
57
an attempt will be made to convert it to one.
58
.AP Tcl_Obj *objPtr in
59
For \fBTcl_ListObjAppendElement\fR,
60
points to the Tcl object that will be appended to \fIlistPtr\fR.
61
For \fBTcl_SetListObj\fR,
62
this points to the Tcl object that will be converted to a list object
63
containing the \fIobjc\fR elements of the array referenced by \fIobjv\fR.
64
.AP int *objcPtr in
65
Points to location where \fBTcl_ListObjGetElements\fR
66
stores the number of element objects in \fIlistPtr\fR.
67
.AP Tcl_Obj ***objvPtr out
68
A location where \fBTcl_ListObjGetElements\fR stores a pointer to an array
69
of pointers to the element objects of \fIlistPtr\fR.
70
.AP int objc in
71
The number of Tcl objects that \fBTcl_NewListObj\fR
72
will insert into a new list object,
73
and \fBTcl_ListObjReplace\fR will insert into \fIlistPtr\fR.
74
For \fBTcl_SetListObj\fR,
75
the number of Tcl objects to insert into \fIobjPtr\fR.
76
.VS
77
.TP
78
Tcl_Obj *CONST \fIobjv\fR[]     (in)
79
.
80
An array of pointers to objects.
81
\fBTcl_NewListObj\fR will insert these objects into a new list object
82
and \fBTcl_ListObjReplace\fR will insert them into an existing \fIlistPtr\fR.
83
Each object will become a separate list element.
84
.VE
85
.AP int *intPtr out
86
Points to location where \fBTcl_ListObjLength\fR
87
stores the length of the list.
88
.AP int index in
89
Index of the list element that \fBTcl_ListObjIndex\fR
90
is to return.
91
The first element has index 0.
92
.AP Tcl_Obj **objPtrPtr out
93
Points to place where \fBTcl_ListObjIndex\fR is to store
94
a pointer to the resulting list element object.
95
.AP int first in
96
Index of the starting list element that \fBTcl_ListObjReplace\fR
97
is to replace.
98
The list's first element has index 0.
99
.AP int count in
100
The number of elements that \fBTcl_ListObjReplace\fR
101
is to replace.
102
.BE
103
 
104
.SH DESCRIPTION
105
.PP
106
Tcl list objects have an internal representation that supports
107
the efficient indexing and appending.
108
The procedures described in this man page are used to
109
create, modify, index, and append to Tcl list objects from C code.
110
.PP
111
\fBTcl_ListObjAppendList\fR and \fBTcl_ListObjAppendElement\fR
112
both add one or more objects
113
to the end of the list object referenced by \fIlistPtr\fR.
114
\fBTcl_ListObjAppendList\fR appends each element of the list object
115
referenced by \fIelemListPtr\fR while
116
\fBTcl_ListObjAppendElement\fR appends the single object
117
referenced by \fIobjPtr\fR.
118
Both procedures will convert the object referenced by \fIlistPtr\fR
119
to a list object if necessary.
120
If an error occurs during conversion,
121
both procedures return \fBTCL_ERROR\fR and leave an error message
122
in the interpreter's result object if \fIinterp\fR is not NULL.
123
Similarly, if \fIelemListPtr\fR does not already refer to a list object,
124
\fBTcl_ListObjAppendList\fR will attempt to convert it to one
125
and if an error occurs during conversion,
126
will return \fBTCL_ERROR\fR
127
and leave an error message in the interpreter's result object
128
if interp is not NULL.
129
Both procedures invalidate any old string representation of \fIlistPtr\fR
130
and, if it was converted to a list object,
131
free any old internal representation.
132
Similarly, \fBTcl_ListObjAppendList\fR frees any old internal representation
133
of \fIelemListPtr\fR if it converts it to a list object.
134
After appending each element in \fIelemListPtr\fR,
135
\fBTcl_ListObjAppendList\fR increments the element's reference count
136
since \fIlistPtr\fR now also refers to it.
137
For the same reason, \fBTcl_ListObjAppendElement\fR
138
increments \fIobjPtr\fR's reference count.
139
If no error occurs,
140
the two procedures return \fBTCL_OK\fR after appending the objects.
141
.PP
142
\fBTcl_NewListObj\fR and \fBTcl_SetListObj\fR
143
create a new object or modify an existing object to hold
144
the \fIobjc\fR elements of the array referenced by \fIobjv\fR
145
where each element is a pointer to a Tcl object.
146
If \fIobjc\fR is less than or equal to zero,
147
they return an empty object.
148
The new object's string representation is left invalid.
149
The two procedures increment the reference counts
150
of the elements in \fIobjc\fR since the list object now refers to them.
151
The new list object returned by \fBTcl_NewListObj\fR
152
has reference count zero.
153
.PP
154
\fBTcl_ListObjGetElements\fR returns a count and
155
a pointer to an array of the elements in a list object.
156
It returns the count by storing it in the address \fIobjcPtr\fR.
157
Similarly, it returns the array pointer by storing it
158
in the address \fIobjvPtr\fR.
159
If \fIlistPtr\fR is not already a list object,
160
\fBTcl_ListObjGetElements\fR will attempt to convert it to one;
161
if the conversion fails, it returns \fBTCL_ERROR\fR
162
and leaves an error message in the interpreter's result object
163
if \fIinterp\fR is not NULL.
164
Otherwise it returns \fBTCL_OK\fR after storing the count and array pointer.
165
.PP
166
\fBTcl_ListObjLength\fR returns the number of elements in the list object
167
referenced by \fIlistPtr\fR.
168
It returns this count by storing an integer in the address \fIintPtr\fR.
169
If the object is not already a list object,
170
\fBTcl_ListObjLength\fR will attempt to convert it to one;
171
if the conversion fails, it returns \fBTCL_ERROR\fR
172
and leaves an error message in the interpreter's result object
173
if \fIinterp\fR is not NULL.
174
Otherwise it returns \fBTCL_OK\fR after storing the list's length.
175
.PP
176
The procedure \fBTcl_ListObjIndex\fR returns a pointer to the object
177
at element \fIindex\fR in the list referenced by \fIlistPtr\fR.
178
It returns this object by storing a pointer to it
179
in the address \fIobjPtrPtr\fR.
180
If \fIlistPtr\fR does not already refer to a list object,
181
\fBTcl_ListObjIndex\fR will attempt to convert it to one;
182
if the conversion fails, it returns \fBTCL_ERROR\fR
183
and leaves an error message in the interpreter's result object
184
if \fIinterp\fR is not NULL.
185
If the index is out of range,
186
that is, \fIindex\fR is negative or
187
greater than or equal to the number of elements in the list,
188
\fBTcl_ListObjIndex\fR stores a NULL in \fIobjPtrPtr\fR
189
and returns \fBTCL_OK\fR.
190
Otherwise it returns \fBTCL_OK\fR after storing the element's
191
object pointer.
192
The reference count for the list element is not incremented;
193
the caller must do that if it needs to retain a pointer to the element.
194
.PP
195
\fBTcl_ListObjReplace\fR replaces zero or more elements
196
of the list referenced by \fIlistPtr\fR
197
with the \fIobjc\fR objects in the array referenced by \fIobjv\fR.
198
If \fIlistPtr\fR does not point to a list object,
199
\fBTcl_ListObjReplace\fR will attempt to convert it to one;
200
if the conversion fails, it returns \fBTCL_ERROR\fR
201
and leaves an error message in the interpreter's result object
202
if \fIinterp\fR is not NULL.
203
Otherwise, it returns \fBTCL_OK\fR after replacing the objects.
204
If \fIobjv\fR is NULL, no new elements are added.
205
If the argument \fIfirst\fR is zero or negative,
206
it refers to the first element.
207
If \fIfirst\fR is greater than or equal to the
208
number of elements in the list, then no elements are deleted;
209
the new elements are appended to the list.
210
\fIcount\fR gives the number of elements to replace.
211
If \fIcount\fR is zero or negative then no elements are deleted;
212
the new elements are simply inserted before the one
213
designated by \fIfirst\fR.
214
\fBTcl_ListObjReplace\fR invalidates \fIlistPtr\fR's
215
old string representation.
216
The reference counts of any elements inserted from \fIobjv\fR
217
are incremented since the resulting list now refers to them.
218
Similarly, the reference counts for any replaced objects are decremented.
219
.PP
220
Because \fBTcl_ListObjReplace\fR combines
221
both element insertion and deletion,
222
it can be used to implement a number of list operations.
223
For example, the following code inserts the \fIobjc\fR objects
224
referenced by the array of object pointers \fIobjv\fR
225
just before the element \fIindex\fR of the list referenced by \fIlistPtr\fR:
226
.CS
227
result = Tcl_ListObjReplace(interp, listPtr, index, 0, objc, objv);
228
.CE
229
Similarly, the following code appends the \fIobjc\fR objects
230
referenced by the array \fIobjv\fR
231
to the end of the list \fIlistPtr\fR:
232
.CS
233
result = Tcl_ListObjLength(interp, listPtr, &length);
234
if (result == TCL_OK) {
235
        result = Tcl_ListObjReplace(interp, listPtr, length, 0, objc, objv);
236
}
237
.CE
238
The \fIcount\fR list elements starting at \fIfirst\fR can be deleted
239
by simply calling \fBTcl_ListObjReplace\fR
240
with a NULL \fIobjvPtr\fR:
241
.CS
242
result = Tcl_ListObjReplace(interp, listPtr, first, count, 0, NULL);
243
.CE
244
 
245
.SH "SEE ALSO"
246
Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult
247
 
248
.SH KEYWORDS
249
append, index, insert, internal representation, length, list, list object, list type, object, object type, replace, string representation

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.