Debian Codegraph @

html/Blt_Vector.html

raw symbols SCIP
1
2 <!-- manual page source format generated by PolyglotMan v3.0.9, -->
3 <!-- available via anonymous ftp from ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z -->
4
5 <HTML>
6 <HEAD>
7 <TITLE>Blt_Vector(3) manual page</TITLE>
8 </HEAD>
9 <BODY bgcolor=white>
10 <A HREF="#toc">Table of Contents</A><P>
11
12 <H2><A NAME="sect0" HREF="#toc0">Name</A></H2>
13 Blt_Vector - Vector data object.
14 <P>
15
16 <H2><A NAME="sect1" HREF="#toc1">C Language API</A></H2>
17 You can create, modify, and destroy vectors from C code,
18 using library routines. You need to include the header file blt.h. It
19 contains the definition of the structure <B>Blt_Vector</B>, which represents the
20 vector. It appears below. <P>
21 <BR>
22 <CODE>typedef struct {<BR>
23 double *<I>valueArr</I>; <BR>
24 int <I>numValues</I>; <BR>
25 int <I>arraySize</I>; <BR>
26 double <I>min</I>, <I>max</I>; <BR>
27 } <B>Blt_Vector</B>;<BR>
28 <P>
29 </CODE>The field <I>valueArr</I> points to memory holding the vector components. The
30 components are stored in a double precision array, whose size size is represented
31 by <I>arraySize</I>. <I>NumValues</I> is the length of vector. The size of the array
32 is always equal to or larger than the length of the vector. <I>Min</I> and <I>max</I>
33 are minimum and maximum component values.
34 <H2><A NAME="sect2" HREF="#toc2">Library Routines</A></H2>
35 The following
36 routines are available from C to manage vectors. Vectors are identified
37 by the vector name. <P>
38 <B>Blt_CreateVector</B> <blockquote>
39 <DL>
40
41 <DT>Synopsis: </DT>
42 <DD><BR>
43 <CODE>int <B>Blt_CreateVector</B> (<I>interp</I>, <I>vecName</I>, <I>length</I>, <I>vecPtrPtr</I>)<BR>
44 <blockquote>Tcl_Interp *<I>interp</I>;<BR>
45 char *<I>vecName</I>;<BR>
46 int <I>length</I>;<BR>
47 Blt_Vector **<I>vecPtrPtr</I>;<BR>
48 </DD>
49 </DL>
50 </blockquote>
51
52 <DL>
53
54 <DT></CODE>Description: </DT>
55 <DD>Creates a new vector <I>vecName</I> with a length of <I>length</I>. <B>Blt_CreateVector</B>
56 creates both a new Tcl command and array variable <I>vecName</I>. Neither a command
57 nor variable named <I>vecName</I> can already exist. A pointer to the vector
58 is placed into <I>vecPtrPtr</I>. </DD>
59
60 <DT>Results: </DT>
61 <DD>Returns TCL_OK if the vector is successfully
62 created. If <I>length</I> is negative, a Tcl variable or command <I>vecName</I> already
63 exists, or memory cannot be allocated for the vector, then TCL_ERROR
64 is returned and <I>interp-&gt;result</I> will contain an error message. </DD>
65 </DL>
66 </blockquote>
67 <P>
68 <P>
69 <B>Blt_DeleteVectorByName</B>
70 <blockquote>
71 <DL>
72
73 <DT>Synopsis: </DT>
74 <DD><BR>
75 <CODE>int <B>Blt_DeleteVectorByName</B> (<I>interp</I>, <I>vecName</I>)<BR>
76 <blockquote>Tcl_Interp *<I>interp</I>;<BR>
77 char *<I>vecName</I>;<BR>
78 </DD>
79 </DL>
80 </blockquote>
81
82 <DL>
83
84 <DT></CODE>Description: </DT>
85 <DD>Removes the vector <I>vecName</I>. <I>VecName</I> is the name of a vector
86 which must already exist. Both the Tcl command and array variable <I>vecName</I>
87 are destroyed. All clients of the vector will be notified immediately that
88 the vector has been destroyed. </DD>
89
90 <DT>Results: </DT>
91 <DD>Returns TCL_OK if the vector is
92 successfully deleted. If <I>vecName</I> is not the name a vector, then TCL_ERROR
93 is returned and <I>interp-&gt;result</I> will contain an error message. </DD>
94 </DL>
95 </blockquote>
96 <P>
97 <P>
98 <B>Blt_DeleteVector</B>
99 <blockquote>
100 <DL>
101
102 <DT>Synopsis: </DT>
103 <DD><BR>
104 <CODE>int <B>Blt_DeleteVector</B> (<I>vecPtr</I>)<BR>
105 <blockquote>Blt_Vector *<I>vecPtr</I>;<BR>
106 </DD>
107 </DL>
108 </blockquote>
109
110 <DL>
111
112 <DT></CODE>Description: </DT>
113 <DD>Removes the vector pointed to by <I>vecPtr</I>. <I>VecPtr</I> is a pointer
114 to a vector, typically set by <B>Blt_GetVector</B> or <B>Blt_CreateVector</B>. Both the
115 Tcl command and array variable of the vector are destroyed. All clients
116 of the vector will be notified immediately that the vector has been destroyed.
117 </DD>
118
119 <DT>Results: </DT>
120 <DD>Returns TCL_OK if the vector is successfully deleted. If <I>vecName</I>
121 is not the name a vector, then TCL_ERROR is returned and <I>interp-&gt;result</I>
122 will contain an error message. </DD>
123 </DL>
124 </blockquote>
125 <P>
126 <P>
127 <B>Blt_GetVector</B> <blockquote>
128 <DL>
129
130 <DT>Synopsis: </DT>
131 <DD><BR>
132 <CODE>int <B>Blt_GetVector</B> (<I>interp</I>, <I>vecName</I>, <I>vecPtrPtr</I>)<BR>
133 <blockquote>Tcl_Interp *<I>interp</I>;<BR>
134 char *<I>vecName</I>;<BR>
135 Blt_Vector **<I>vecPtrPtr</I>;<BR>
136 </DD>
137 </DL>
138 </blockquote>
139
140 <DL>
141
142 <DT></CODE>Description: </DT>
143 <DD>Retrieves the vector <I>vecName</I>. <I>VecName</I> is the name of a vector
144 which must already exist. <I>VecPtrPtr</I> will point be set to the address of
145 the vector. </DD>
146
147 <DT>Results: </DT>
148 <DD>Returns TCL_OK if the vector is successfully retrieved.
149 If <I>vecName</I> is not the name of a vector, then TCL_ERROR is returned and
150 <I>interp-&gt;result</I> will contain an error message. </DD>
151 </DL>
152 </blockquote>
153 <P>
154 <P>
155 <B>Blt_ResetVector</B> <P>
156 <blockquote>
157 <DL>
158
159 <DT>Synopsis: </DT>
160 <DD><BR>
161 <CODE>int <B>Blt_ResetVector</B> (<I>vecPtr</I>, <I>dataArr</I>, <BR>
162 <tt> </tt>&nbsp;<tt> </tt>&nbsp;<I>numValues</I>, <I>arraySize</I>, <I>freeProc</I>)<BR>
163 <blockquote>Blt_Vector *<I>vecPtr</I>;<BR>
164 double *<I>dataArr</I>;<BR>
165 int *<I>numValues</I>;<BR>
166 int *<I>arraySize</I>;<BR>
167 Tcl_FreeProc *<I>freeProc</I>;<BR>
168 </DD>
169 </DL>
170 </blockquote>
171
172 <DL>
173
174 <DT></CODE>Description: </DT>
175 <DD>Resets the components of the vector pointed to by <I>vecPtr</I>.
176 Calling <B>Blt_ResetVector</B> will trigger the vector to dispatch notifications
177 to its clients. <I>DataArr</I> is the array of doubles which represents the vector
178 data. <I>NumValues</I> is the number of elements in the array. <I>ArraySize</I> is the
179 actual size of the array (the array may be bigger than the number of values
180 stored in it). <I>FreeProc</I> indicates how the storage for the vector component
181 array (<I>dataArr</I>) was allocated. It is used to determine how to reallocate
182 memory when the vector is resized or destroyed. It must be TCL_DYNAMIC,
183 TCL_STATIC, TCL_VOLATILE, or a pointer to a function to free the memory
184 allocated for the vector array. If <I>freeProc</I> is TCL_VOLATILE, it indicates
185 that <I>dataArr</I> must be copied and saved. If <I>freeProc</I> is TCL_DYNAMIC, it
186 indicates that <I>dataArr</I> was dynamically allocated and that Tcl should free
187 <I>dataArr</I> if necessary. Static indicates that nothing should be done to
188 release storage for <I>dataArr</I>. </DD>
189
190 <DT>Results: </DT>
191 <DD>Returns TCL_OK if the vector is
192 successfully resized. If <I>newSize</I> is negative, a vector <I>vecName</I> does not
193 exist, or memory cannot be allocated for the vector, then TCL_ERROR is
194 returned and <I>interp-&gt;result</I> will contain an error message. </DD>
195 </DL>
196 </blockquote>
197 <P>
198 <P>
199 <B>Blt_ResizeVector</B>
200 <blockquote>
201 <DL>
202
203 <DT>Synopsis: </DT>
204 <DD><BR>
205 <CODE>int <B>Blt_ResizeVector</B> (<I>vecPtr</I>, <I>newSize</I>)<BR>
206 <blockquote>Blt_Vector *<I>vecPtr</I>;<BR>
207 int <I>newSize</I>;<BR>
208 </DD>
209 </DL>
210 </blockquote>
211
212 <DL>
213
214 <DT></CODE>Description: </DT>
215 <DD>Resets the length of the vector pointed to by <I>vecPtr</I> to <I>newSize</I>.
216 If <I>newSize</I> is smaller than the current size of the vector, it is truncated.
217 If <I>newSize</I> is greater, the vector is extended and the new components are
218 initialized to 0.0. Calling <B>Blt_ResetVector</B> will trigger the vector to
219 dispatch notifications. </DD>
220
221 <DT>Results: </DT>
222 <DD>Returns TCL_OK if the vector is successfully
223 resized. If <I>newSize</I> is negative or memory can not be allocated for the
224 vector, then TCL_ERROR is returned and <I>interp-&gt;result</I> will contain an
225 error message. <P>
226 </DD>
227 </DL>
228 <P>
229 <B>Blt_VectorExists</B> <blockquote>
230 <DL>
231
232 <DT>Synopsis: </DT>
233 <DD><BR>
234 <CODE>int <B>Blt_VectorExists</B> (<I>interp</I>, <I>vecName</I>)<BR>
235 <blockquote>Tcl_Interp *<I>interp</I>;<BR>
236 char *<I>vecName</I>;<BR>
237 </DD>
238 </DL>
239 </blockquote>
240
241 <DL>
242
243 <DT></CODE>Description: </DT>
244 <DD>Indicates if a vector named <I>vecName</I> exists in <I>interp</I>. </DD>
245
246 <DT>Results:
247 </DT>
248 <DD>Returns 1 if a vector <I>vecName</I> exists and 0 otherwise. </DD>
249 </DL>
250 </blockquote>
251 <P>
252 <P>
253 If your application
254 needs to be notified when a vector changes, it can allocate a unique <I>client
255 identifier</I> for itself. Using this identifier, you can then register a call-back
256 to be made whenever the vector is updated or destroyed. By default, the
257 call-backs are made at the next idle point. This can be changed to occur
258 at the time the vector is modified. An application can allocate more than
259 one identifier for any vector. When the client application is done with
260 the vector, it should free the identifier. <P>
261 The call-back routine must of
262 the following type. <BR>
263 <blockquote><BR>
264 <CODE>typedef void (<B>Blt_VectorChangedProc</B>) (Tcl_Interp *<I>interp</I>, <BR>
265 <blockquote>ClientData <I>clientData</I>, Blt_VectorNotify <I>notify</I>);<BR>
266 </blockquote>
267 <BR>
268 </blockquote>
269 </PRE></CODE><I>ClientData</I> is passed to this routine whenever it is called. You can use
270 this to pass information to the call-back. The <I>notify</I> argument indicates
271 whether the vector has been updated of destroyed. It is an enumerated type.
272 <BR>
273 <blockquote><BR>
274 <CODE>typedef enum {<BR>
275 BLT_VECTOR_NOTIFY_UPDATE=1,<BR>
276 BLT_VECTOR_NOTIFY_DESTROY=2<BR>
277 } <B>Blt_VectorNotify</B>;<BR>
278 <BR>
279 </blockquote>
280 <P>
281 </CODE><B>Blt_AllocVectorId</B> <blockquote>
282 <DL>
283
284 <DT>Synopsis: </DT>
285 <DD><BR>
286 <CODE>Blt_VectorId <B>Blt_AllocVectorId</B> (<I>interp</I>, <I>vecName</I>)<BR>
287 <blockquote>Tcl_Interp *<I>interp</I>;<BR>
288 char *<I>vecName</I>;<BR>
289 </DD>
290 </DL>
291 </blockquote>
292
293 <DL>
294
295 <DT></CODE>Description: </DT>
296 <DD>Allocates an client identifier for with the vector <I>vecName</I>.
297 This identifier can be used to specify a call-back which is triggered when
298 the vector is updated or destroyed. </DD>
299
300 <DT>Results: </DT>
301 <DD>Returns a client identifier
302 if successful. If <I>vecName</I> is not the name of a vector, then NULL is returned
303 and <I>interp-&gt;result</I> will contain an error message. </DD>
304 </DL>
305 </blockquote>
306 <P>
307 <P>
308 <B>Blt_GetVectorById</B> <blockquote>
309 <DL>
310
311 <DT>Synopsis:
312 </DT>
313 <DD><BR>
314 <CODE>int <B>Blt_GetVector</B> (<I>interp</I>, <I>clientId</I>, <I>vecPtrPtr</I>)<BR>
315 <blockquote>Tcl_Interp *<I>interp</I>;<BR>
316 Blt_VectorId <I>clientId</I>;<BR>
317 Blt_Vector **<I>vecPtrPtr</I>;<BR>
318 </DD>
319 </DL>
320 </blockquote>
321
322 <DL>
323
324 <DT></CODE>Description: </DT>
325 <DD>Retrieves the vector used by <I>clientId</I>. <I>ClientId</I> is a valid
326 vector client identifier allocated by <B>Blt_AllocVectorId</B>. <I>VecPtrPtr</I> will
327 point be set to the address of the vector. </DD>
328
329 <DT>Results: </DT>
330 <DD>Returns TCL_OK if
331 the vector is successfully retrieved. </DD>
332 </DL>
333 </blockquote>
334 <P>
335 <P>
336 <B>Blt_SetVectorChangedProc</B> <blockquote>
337 <DL>
338
339 <DT>Synopsis:
340 </DT>
341 <DD><BR>
342 <CODE>void <B>Blt_SetVectorChangedProc</B> (<I>clientId</I>, <I>proc</I>, <I>clientData</I>);<BR>
343 <blockquote>Blt_VectorId <I>clientId</I>;<BR>
344 Blt_VectorChangedProc *<I>proc</I>;<BR>
345 ClientData *<I>clientData</I>;<BR>
346 </DD>
347 </DL>
348 </blockquote>
349
350 <DL>
351
352 <DT></CODE>Description: </DT>
353 <DD>Specifies a call-back routine to be called whenever the vector
354 associated with <I>clientId</I> is updated or deleted. <I>Proc</I> is a pointer to call-back
355 routine and must be of the type <B>Blt_VectorChangedProc</B>. <I>ClientData</I> is a
356 one-word value to be passed to the routine when it is invoked. If <I>proc</I> is
357 NULL, then the client is not notified. </DD>
358
359 <DT>Results: </DT>
360 <DD>The designated call-back
361 procedure will be invoked when the vector is updated or destroyed. </DD>
362 </DL>
363 </blockquote>
364 <P>
365 <P>
366 <B>Blt_FreeVectorId</B>
367 <blockquote>
368 <DL>
369
370 <DT>Synopsis: </DT>
371 <DD><BR>
372 <CODE>void <B>Blt_FreeVectorId</B> (<I>clientId</I>);<BR>
373 <blockquote>Blt_VectorId <I>clientId</I>;<BR>
374 </DD>
375 </DL>
376 </blockquote>
377
378 <DL>
379
380 <DT></CODE>Description: </DT>
381 <DD>Frees the client identifier. Memory allocated for the identifier
382 is released. The client will no longer be notified when the vector is
383 modified. </DD>
384
385 <DT>Results: </DT>
386 <DD>The designated call-back procedure will be no longer be
387 invoked when the vector is updated or destroyed. </DD>
388 </DL>
389 </blockquote>
390 <P>
391 <P>
392 <B>Blt_NameOfVectorId</B> <blockquote>
393 <DL>
394
395 <DT>Synopsis:
396 </DT>
397 <DD><BR>
398 <CODE>char *<B>Blt_NameOfVectorId</B> (<I>clientId</I>);<BR>
399 <blockquote>Blt_VectorId <I>clientId</I>;<BR>
400 </DD>
401 </DL>
402 </blockquote>
403
404 <DL>
405
406 <DT></CODE>Description: </DT>
407 <DD>Retrieves the name of the vector associated with the client
408 identifier <I>clientId</I>. </DD>
409
410 <DT>Results: </DT>
411 <DD>Returns the name of the vector associated
412 with <I>clientId</I>. If <I>clientId</I> is not an identifier or the vector has been
413 destroyed, NULL is returned. </DD>
414 </DL>
415 </blockquote>
416 <P>
417 <P>
418 <B>Blt_InstallIndexProc</B> <blockquote>
419 <DL>
420
421 <DT>Synopsis: </DT>
422 <DD><BR>
423 <CODE>void <B>Blt_InstallIndexProc</B> (<I>indexName</I>, <I>procPtr</I>)<BR>
424 <blockquote>char *<I>indexName</I>;<BR>
425 Blt_VectorIndexProc *<I>procPtr</I>;<BR>
426 </DD>
427 </DL>
428 </blockquote>
429
430 <DL>
431
432 <DT></CODE>Description: </DT>
433 <DD>Registers a function to be called to retrieved the index
434 <I>indexName</I> from the vector's array variable. <P>
435 typedef double Blt_VectorIndexProc(Vector
436 *vecPtr); <P>
437 The function will be passed a pointer to the vector. The function
438 must return a double representing the value at the index. </DD>
439
440 <DT>Results: </DT>
441 <DD>The new
442 index is installed into the vector. </DD>
443 </DL>
444 </blockquote>
445 </blockquote>
446
447 <H2><A NAME="sect3" HREF="#toc3">C API Example</A></H2>
448 The following example opens
449 a file of binary data and stores it in an array of doubles. The array size
450 is computed from the size of the file. If the vector "data" exists, calling
451 <B>Blt_VectorExists</B>, <B>Blt_GetVector</B> is called to get the pointer to the vector.
452 Otherwise the routine <B>Blt_CreateVector</B> is called to create a new vector
453 and returns a pointer to it. Just like the Tcl interface, both a new Tcl
454 command and array variable are created when a new vector is created. It
455 doesn't make any difference what the initial size of the vector is since
456 it will be reset shortly. The vector is updated when <B>lt_ResetVector</B> is called.
457 Blt_ResetVector makes the changes visible to the Tcl interface and other
458 vector clients (such as a graph widget). <P>
459 <BR>
460 <CODE>#include &lt;tcl.h&gt;<BR>
461 #include &lt;blt.h&gt;<tt> </tt>&nbsp;<tt> </tt>&nbsp;<tt> </tt>&nbsp;<tt> </tt>&nbsp;<tt> </tt>&nbsp;<tt> </tt>&nbsp;<tt> </tt>&nbsp;<tt> </tt>&nbsp;<BR>
462 Blt_Vector *vecPtr;<BR>
463 double *newArr;<BR>
464 FILE *f;<BR>
465 struct stat statBuf;<BR>
466 int numBytes, numValues;<BR>
467 <P>
468 f = fopen("binary.dat", "r");<BR>
469 fstat(fileno(f), &amp;statBuf);<BR>
470 numBytes = (int)statBuf.st_size;<BR>
471 <P>
472 /* Allocate an array big enough to hold all the data */<BR>
473 newArr = (double *)m<A HREF="alloc.numBytes">alloc(numBytes)</A>
474 ;<BR>
475 numValues = numBytes / sizeof(double);<BR>
476 fread((void *)newArr, numValues, sizeof(double), f);<BR>
477 fclose(f);<BR>
478 <P>
479 if (Blt_VectorExists(interp, "data")) {<BR>
480 if (Blt_GetVector(interp, "data", &amp;vecPtr) != TCL_OK) {<BR>
481 <tt> </tt>&nbsp;<tt> </tt>&nbsp;return TCL_ERROR;<BR>
482 }<BR>
483 } else {<BR>
484 if (Blt_CreateVector(interp, "data", 0, &amp;vecPtr) != TCL_OK) {<BR>
485 <tt> </tt>&nbsp;<tt> </tt>&nbsp;return TCL_ERROR;<BR>
486 }<BR>
487 }<BR>
488 /* <BR>
489 * Reset the vector. Clients will be notified when Tk is idle. <BR>
490 * TCL_DYNAMIC tells the vector to free the memory allocated <BR>
491 * if it needs to reallocate or destroy the vector.<BR>
492 */<BR>
493 if (Blt_ResetVector(vecPtr, newArr, numValues, numValues, <BR>
494 <tt> </tt>&nbsp;<tt> </tt>&nbsp;TCL_DYNAMIC) != TCL_OK) {<BR>
495 return TCL_ERROR;<BR>
496 }<BR>
497
498 <H2><A NAME="sect4" HREF="#toc4"></CODE>Incompatibilities</A></H2>
499 In previous versions, if the array variable isn't global
500 (i.e. local to a Tcl procedure), the vector is automatically destroyed
501 when the procedure returns. <BR>
502 <CODE>proc doit {} {<BR>
503 # Temporary vector x<BR>
504 vector x(10)<BR>
505 set <A HREF="x.9">x(9)</A>
506 2.0<BR>
507 ...<BR>
508 }<BR>
509 <P>
510 </CODE>This has changed. Variables are not automatically destroyed when their
511 variable is unset. You can restore the old behavior by setting the "-watchunset"
512 switch.
513 <H2><A NAME="sect5" HREF="#toc5"></CODE>Keywords</A></H2>
514 vector, graph, Blt_Vector <P>
515
516 <HR><P>
517 <A NAME="toc"><B>Table of Contents</B></A><P>
518 <UL>
519 <LI><A NAME="toc0" HREF="#sect0">Name</A></LI>
520 <LI><A NAME="toc1" HREF="#sect1">C Language API</A></LI>
521 <LI><A NAME="toc2" HREF="#sect2">Library Routines</A></LI>
522 <LI><A NAME="toc3" HREF="#sect3">C API Example</A></LI>
523 <LI><A NAME="toc4" HREF="#sect4">Incompatibilities</A></LI>
524 <LI><A NAME="toc5" HREF="#sect5">Keywords</A></LI>
525 </UL>
526 </BODY></HTML>