Debian Codegraph @

man/Blt_Vector.man3

raw
1 '\"
2 '\" Copyright 1991-1997 by Lucent Technologies, Inc.
3 '\"
4 '\" Permission to use, copy, modify, and distribute this software and its
5 '\" documentation for any purpose and without fee is hereby granted, provided
6 '\" that the above copyright notice appear in all copies and that both that the
7 '\" copyright notice and warranty disclaimer appear in supporting documentation,
8 '\" and that the names of Lucent Technologies any of their entities not be used
9 '\" in advertising or publicity pertaining to distribution of the software
10 '\" without specific, written prior permission.
11 '\"
12 '\" Lucent Technologies disclaims all warranties with regard to this software,
13 '\" including all implied warranties of merchantability and fitness. In no event
14 '\" shall Lucent Technologies be liable for any special, indirect or
15 '\" consequential damages or any damages whatsoever resulting from loss of use,
16 '\" data or profits, whether in an action of contract, negligence or other
17 '\" tortuous action, arising out of or in connection with the use or performance
18 '\" of this software.
19 '\"
20 '\" Vector command created by George Howlett.
21 '\"
22 .so man.macros
23 .TH Blt_Vector 3 BLT_VERSION BLT "Blt Library Procedures"
24 .BS
25 '\" Note: do not modify the .SH NAME line immediately below!
26 .SH NAME
27 Blt_Vector \- Vector data object.
28
29 .SH C LANGUAGE API
30 You can create, modify, and destroy vectors from C code, using
31 library routines.
32 You need to include the header file \fBblt.h\fR. It contains the
33 definition of the structure \fBBlt_Vector\fR, which represents the
34 vector. It appears below.
35 .sp
36 .CS
37 \fRtypedef struct {
38 double *\fIvalueArr\fR;
39 int \fInumValues\fR;
40 int \fIarraySize\fR;
41 double \fImin\fR, \fImax\fR;
42 } \fBBlt_Vector\fR;
43 .CE
44 .sp
45 The field \fIvalueArr\fR points to memory holding the vector
46 components. The components are stored in a double precision array,
47 whose size size is represented by \fIarraySize\fR. \fINumValues\fR is
48 the length of vector. The size of the array is always equal to or
49 larger than the length of the vector. \fIMin\fR and \fImax\fR are
50 minimum and maximum component values.
51 .SH LIBRARY ROUTINES
52 The following routines are available from C to manage vectors.
53 Vectors are identified by the vector name.
54 .PP
55 \fBBlt_CreateVector\fR
56 .RS .25i
57 .TP 1i
58 Synopsis:
59 .CS
60 int \fBBlt_CreateVector\fR (\fIinterp\fR, \fIvecName\fR, \fIlength\fR, \fIvecPtrPtr\fR)
61 .RS 1.25i
62 Tcl_Interp *\fIinterp\fR;
63 char *\fIvecName\fR;
64 int \fIlength\fR;
65 Blt_Vector **\fIvecPtrPtr\fR;
66 .RE
67 .CE
68 .TP
69 Description:
70 Creates a new vector \fIvecName\fR\fR with a length of \fIlength\fR.
71 \fBBlt_CreateVector\fR creates both a new Tcl command and array
72 variable \fIvecName\fR. Neither a command nor variable named
73 \fIvecName\fR can already exist. A pointer to the vector is
74 placed into \fIvecPtrPtr\fR.
75 .TP
76 Results:
77 Returns \fBTCL_OK\fR if the vector is successfully created. If
78 \fIlength\fR is negative, a Tcl variable or command \fIvecName\fR
79 already exists, or memory cannot be allocated for the vector, then
80 \fBTCL_ERROR\fR is returned and \fIinterp->result\fR will contain an
81 error message.
82 .RE
83 .sp
84 .PP
85 \fBBlt_DeleteVectorByName\fR
86 .RS .25i
87 .TP 1i
88 Synopsis:
89 .CS
90 int \fBBlt_DeleteVectorByName\fR (\fIinterp\fR, \fIvecName\fR)
91 .RS 1.25i
92 Tcl_Interp *\fIinterp\fR;
93 char *\fIvecName\fR;
94 .RE
95 .CE
96 .TP 1i
97 Description:
98 Removes the vector \fIvecName\fR. \fIVecName\fR is the name of a vector
99 which must already exist. Both the Tcl command and array variable
100 \fIvecName\fR are destroyed. All clients of the vector will be notified
101 immediately that the vector has been destroyed.
102 .TP
103 Results:
104 Returns \fBTCL_OK\fR if the vector is successfully deleted. If
105 \fIvecName\fR is not the name a vector, then \fBTCL_ERROR\fR is returned
106 and \fIinterp->result\fR will contain an error message.
107 .RE
108 .sp
109 .PP
110 \fBBlt_DeleteVector\fR
111 .RS .25i
112 .TP 1i
113 Synopsis:
114 .CS
115 int \fBBlt_DeleteVector\fR (\fIvecPtr\fR)
116 .RS 1.25i
117 Blt_Vector *\fIvecPtr\fR;
118 .RE
119 .CE
120 .TP 1i
121 Description:
122 Removes the vector pointed to by \fIvecPtr\fR. \fIVecPtr\fR is a
123 pointer to a vector, typically set by \fBBlt_GetVector\fR or
124 \fBBlt_CreateVector\fR. Both the Tcl command and array variable of
125 the vector are destroyed. All clients of the vector will be notified
126 immediately that the vector has been destroyed.
127 .TP
128 Results:
129 Returns \fBTCL_OK\fR if the vector is successfully deleted. If
130 \fIvecName\fR is not the name a vector, then \fBTCL_ERROR\fR is returned
131 and \fIinterp->result\fR will contain an error message.
132 .RE
133 .sp
134 .PP
135 \fBBlt_GetVector\fR
136 .RS .25i
137 .TP 1i
138 Synopsis:
139 .CS
140 int \fBBlt_GetVector\fR (\fIinterp\fR, \fIvecName\fR, \fIvecPtrPtr\fR)
141 .RS 1.25i
142 Tcl_Interp *\fIinterp\fR;
143 char *\fIvecName\fR;
144 Blt_Vector **\fIvecPtrPtr\fR;
145 .RE
146 .CE
147 .TP 1i
148 Description:
149 Retrieves the vector \fIvecName\fR. \fIVecName\fR is the name of a
150 vector which must already exist. \fIVecPtrPtr\fR will point be set to
151 the address of the vector.
152 .TP
153 Results:
154 Returns \fBTCL_OK\fR if the vector is successfully retrieved. If
155 \fIvecName\fR is not the name of a vector, then \fBTCL_ERROR\fR is
156 returned and \fIinterp->result\fR will contain an error message.
157 .RE
158 .sp
159 .PP
160 \fBBlt_ResetVector\fR
161 .PP
162 .RS .25i
163 .TP 1i
164 Synopsis:
165 .CS
166 int \fBBlt_ResetVector\fR (\fIvecPtr\fR, \fIdataArr\fR,
167 \fInumValues\fR, \fIarraySize\fR, \fIfreeProc\fR)
168 .RS 1.25i
169 Blt_Vector *\fIvecPtr\fR;
170 double *\fIdataArr\fR;
171 int *\fInumValues\fR;
172 int *\fIarraySize\fR;
173 Tcl_FreeProc *\fIfreeProc\fR;
174 .RE
175 .CE
176 .TP
177 Description:
178 Resets the components of the vector pointed to by \fIvecPtr\fR.
179 Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
180 notifications to its clients. \fIDataArr\fR is the array of doubles
181 which represents the vector data. \fINumValues\fR is the number of
182 elements in the array. \fIArraySize\fR is the actual size of the array
183 (the array may be bigger than the number of values stored in
184 it). \fIFreeProc\fP indicates how the storage for the vector component
185 array (\fIdataArr\fR) was allocated. It is used to determine how to
186 reallocate memory when the vector is resized or destroyed. It must be
187 \fBTCL_DYNAMIC\fR, \fBTCL_STATIC\fR, \fBTCL_VOLATILE\fR, or a pointer
188 to a function to free the memory allocated for the vector array. If
189 \fIfreeProc\fR is \fBTCL_VOLATILE\fR, it indicates that \fIdataArr\fR
190 must be copied and saved. If \fIfreeProc\fR is \fBTCL_DYNAMIC\fR, it
191 indicates that \fIdataArr\fR was dynamically allocated and that Tcl
192 should free \fIdataArr\fR if necessary. \fBStatic\fR indicates that
193 nothing should be done to release storage for \fIdataArr\fR.
194 .TP
195 Results:
196 Returns \fBTCL_OK\fR if the vector is successfully resized. If
197 \fInewSize\fR is negative, a vector \fIvecName\fR does not exist, or
198 memory cannot be allocated for the vector, then \fBTCL_ERROR\fR is
199 returned and \fIinterp->result\fR will contain an error message.
200 .RE
201 .sp
202 .PP
203 \fBBlt_ResizeVector\fR
204 .RS .25i
205 .TP 1i
206 Synopsis:
207 .CS
208 int \fBBlt_ResizeVector\fR (\fIvecPtr\fR, \fInewSize\fR)
209 .RS 1.25i
210 Blt_Vector *\fIvecPtr\fR;
211 int \fInewSize\fR;
212 .RE
213 .CE
214 .TP
215 Description:
216 Resets the length of the vector pointed to by \fIvecPtr\fR to
217 \fInewSize\fR. If \fInewSize\fR is smaller than the current size of
218 the vector, it is truncated. If \fInewSize\fR is greater, the vector
219 is extended and the new components are initialized to \fB0.0\fR.
220 Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
221 notifications.
222 .TP
223 Results:
224 Returns \fBTCL_OK\fR if the vector is successfully resized. If
225 \fInewSize\fR is negative or memory can not be allocated for the vector,
226 then \fBTCL_ERROR\fR is returned and \fIinterp->result\fR will contain
227 an error message.
228 .sp
229 .PP
230 \fBBlt_VectorExists\fR
231 .RS .25i
232 .TP 1i
233 Synopsis:
234 .CS
235 int \fBBlt_VectorExists\fR (\fIinterp\fR, \fIvecName\fR)
236 .RS 1.25i
237 Tcl_Interp *\fIinterp\fR;
238 char *\fIvecName\fR;
239 .RE
240 .CE
241 .TP
242 Description:
243 Indicates if a vector named \fIvecName\fR exists in \fIinterp\fR.
244 .TP
245 Results:
246 Returns \fB1\fR if a vector \fIvecName\fR exists and \fB0\fR otherwise.
247 .RE
248 .sp
249 .PP
250 If your application needs to be notified when a vector changes, it can
251 allocate a unique \fIclient identifier\fR for itself. Using this
252 identifier, you can then register a call-back to be made whenever the
253 vector is updated or destroyed. By default, the call-backs are made at
254 the next idle point. This can be changed to occur at the time the
255 vector is modified. An application can allocate more than one
256 identifier for any vector. When the client application is done with
257 the vector, it should free the identifier.
258 .PP
259 The call-back routine must of the following type.
260 .CS
261 .RS
262 .sp
263 typedef void (\fBBlt_VectorChangedProc\fR) (Tcl_Interp *\fIinterp\fR,
264 .RS .25i
265 ClientData \fIclientData\fR, Blt_VectorNotify \fInotify\fR);
266 .RE
267 .sp
268 .RE
269 .CE
270 .fi
271 \fIClientData\fR is passed to this routine whenever it is called. You
272 can use this to pass information to the call-back. The \fInotify\fR
273 argument indicates whether the vector has been updated of destroyed. It
274 is an enumerated type.
275 .CS
276 .RS
277 .sp
278 typedef enum {
279 \fBBLT_VECTOR_NOTIFY_UPDATE\fR=1,
280 \fBBLT_VECTOR_NOTIFY_DESTROY\fR=2
281 } \fBBlt_VectorNotify\fR;
282 .sp
283 .RE
284 .CE
285 .PP
286 \fBBlt_AllocVectorId\fR
287 .RS .25i
288 .TP 1i
289 Synopsis:
290 .CS
291 Blt_VectorId \fBBlt_AllocVectorId\fR (\fIinterp\fR, \fIvecName\fR)
292 .RS 1.25i
293 Tcl_Interp *\fIinterp\fR;
294 char *\fIvecName\fR;
295 .RE
296 .CE
297 .TP
298 Description:
299 Allocates an client identifier for with the vector \fIvecName\fR.
300 This identifier can be used to specify a call-back which is triggered
301 when the vector is updated or destroyed.
302 .TP
303 Results:
304 Returns a client identifier if successful. If \fIvecName\fR is not
305 the name of a vector, then \fBNULL\fR is returned and
306 \fIinterp->result\fR will contain an error message.
307 .RE
308 .sp
309 .PP
310 \fBBlt_GetVectorById\fR
311 .RS .25i
312 .TP 1i
313 Synopsis:
314 .CS
315 int \fBBlt_GetVector\fR (\fIinterp\fR, \fIclientId\fR, \fIvecPtrPtr\fR)
316 .RS 1.25i
317 Tcl_Interp *\fIinterp\fR;
318 Blt_VectorId \fIclientId\fR;
319 Blt_Vector **\fIvecPtrPtr\fR;
320 .RE
321 .CE
322 .TP 1i
323 Description:
324 Retrieves the vector used by \fIclientId\fR. \fIClientId\fR is a valid
325 vector client identifier allocated by \fBBlt_AllocVectorId\fR.
326 \fIVecPtrPtr\fR will point be set to the address of the vector.
327 .TP
328 Results:
329 Returns \fBTCL_OK\fR if the vector is successfully retrieved.
330 .RE
331 .sp
332 .PP
333 \fBBlt_SetVectorChangedProc\fR
334 .RS .25i
335 .TP 1i
336 Synopsis:
337 .CS
338 void \fBBlt_SetVectorChangedProc\fR (\fIclientId\fR, \fIproc\fR, \fIclientData\fR);
339 .RS 1.25i
340 Blt_VectorId \fIclientId\fR;
341 Blt_VectorChangedProc *\fIproc\fR;
342 ClientData *\fIclientData\fR;
343 .RE
344 .CE
345 .TP
346 Description:
347 Specifies a call-back routine to be called whenever the vector
348 associated with \fIclientId\fR is updated or deleted. \fIProc\fR is a
349 pointer to call-back routine and must be of the type
350 \fBBlt_VectorChangedProc\fR. \fIClientData\fR is a one-word value to
351 be passed to the routine when it is invoked. If \fIproc\fR is
352 \fBNULL\fR, then the client is not notified.
353 .TP
354 Results:
355 The designated call-back procedure will be invoked when the vector is
356 updated or destroyed.
357 .RE
358 .sp
359 .PP
360 \fBBlt_FreeVectorId\fR
361 .RS .25i
362 .TP 1i
363 Synopsis:
364 .CS
365 void \fBBlt_FreeVectorId\fR (\fIclientId\fR);
366 .RS 1.25i
367 Blt_VectorId \fIclientId\fR;
368 .RE
369 .CE
370 .TP
371 Description:
372 Frees the client identifier. Memory allocated for the identifier
373 is released. The client will no longer be notified when the
374 vector is modified.
375 .TP
376 Results:
377 The designated call-back procedure will be no longer be invoked when
378 the vector is updated or destroyed.
379 .RE
380 .sp
381 .PP
382 \fBBlt_NameOfVectorId\fR
383 .RS .25i
384 .TP 1i
385 Synopsis:
386 .CS
387 char *\fBBlt_NameOfVectorId\fR (\fIclientId\fR);
388 .RS 1.25i
389 Blt_VectorId \fIclientId\fR;
390 .RE
391 .CE
392 .TP
393 Description:
394 Retrieves the name of the vector associated with the client identifier
395 \fIclientId\fR.
396 .TP
397 Results:
398 Returns the name of the vector associated with \fIclientId\fR. If
399 \fIclientId\fR is not an identifier or the vector has been destroyed,
400 \fBNULL\fR is returned.
401 .RE
402 .sp
403 .PP
404 \fBBlt_InstallIndexProc\fR
405 .RS .25i
406 .TP 1i
407 Synopsis:
408 .CS
409 void \fBBlt_InstallIndexProc\fR (\fIindexName\fR, \fIprocPtr\fR)
410 .RS 1.25i
411 char *\fIindexName\fR;
412 Blt_VectorIndexProc *\fIprocPtr\fR;
413 .RE
414 .CE
415 .TP
416 Description:
417 Registers a function to be called to retrieved the index \fIindexName\fR
418 from the vector's array variable.
419 .sp
420 typedef double Blt_VectorIndexProc(Vector *vecPtr);
421 .sp
422 The function will be passed a pointer to the vector. The function must
423 return a double representing the value at the index.
424 .TP
425 Results:
426 The new index is installed into the vector.
427 .RE
428 .RE
429 .SH C API EXAMPLE
430 The following example opens a file of binary data and stores it in an
431 array of doubles. The array size is computed from the size of the
432 file. If the vector "data" exists, calling \fBBlt_VectorExists\fR,
433 \fBBlt_GetVector\fR is called to get the pointer to the vector.
434 Otherwise the routine \fBBlt_CreateVector\fR is called to create a new
435 vector and returns a pointer to it. Just like the Tcl interface, both
436 a new Tcl command and array variable are created when a new vector is
437 created. It doesn't make any difference what the initial size of the
438 vector is since it will be reset shortly. The vector is updated when
439 \fBlt_ResetVector\fR is called. Blt_ResetVector makes the changes
440 visible to the Tcl interface and other vector clients (such as a graph
441 widget).
442 .sp
443 .CS
444 #include <tcl.h>
445 #include <blt.h>
446 ...
447 Blt_Vector *vecPtr;
448 double *newArr;
449 FILE *f;
450 struct stat statBuf;
451 int numBytes, numValues;
452
453 f = fopen("binary.dat", "r");
454 fstat(fileno(f), &statBuf);
455 numBytes = (int)statBuf.st_size;
456
457 /* Allocate an array big enough to hold all the data */
458 newArr = (double *)malloc(numBytes);
459 numValues = numBytes / sizeof(double);
460 fread((void *)newArr, numValues, sizeof(double), f);
461 fclose(f);
462
463 if (Blt_VectorExists(interp, "data")) {
464 if (Blt_GetVector(interp, "data", &vecPtr) != TCL_OK) {
465 return TCL_ERROR;
466 }
467 } else {
468 if (Blt_CreateVector(interp, "data", 0, &vecPtr) != TCL_OK) {
469 return TCL_ERROR;
470 }
471 }
472 /*
473 * Reset the vector. Clients will be notified when Tk is idle.
474 * TCL_DYNAMIC tells the vector to free the memory allocated
475 * if it needs to reallocate or destroy the vector.
476 */
477 if (Blt_ResetVector(vecPtr, newArr, numValues, numValues,
478 TCL_DYNAMIC) != TCL_OK) {
479 return TCL_ERROR;
480 }
481 .CE
482 .SH "INCOMPATIBILITIES"
483 In previous versions, if the array variable isn't global
484 (i.e. local to a Tcl procedure), the vector is automatically
485 destroyed when the procedure returns.
486 .CS
487 proc doit {} {
488 # Temporary vector x
489 vector x(10)
490 set x(9) 2.0
491 ...
492 }
493 .CE
494 .PP
495 This has changed. Variables are not automatically destroyed when
496 their variable is unset. You can restore the old behavior by
497 setting the "-watchunset" switch.
498 .CE
499 .SH KEYWORDS
500 vector, graph, Blt_Vector