Debian Codegraph @

generic/bltVecInt.h

raw symbols SCIP
1 /*
2 * bltVecInt.h --
3 *
4 * This module implements vector data objects.
5 *
6 * Copyright 1995-1998 Lucent Technologies, Inc.
7 *
8 * Permission to use, copy, modify, and distribute this software and
9 * its documentation for any purpose and without fee is hereby
10 * granted, provided that the above copyright notice appear in all
11 * copies and that both that the copyright notice and warranty
12 * disclaimer appear in supporting documentation, and that the names
13 * of Lucent Technologies any of their entities not be used in
14 * advertising or publicity pertaining to distribution of the software
15 * without specific, written prior permission.
16 *
17 * Lucent Technologies disclaims all warranties with regard to this
18 * software, including all implied warranties of merchantability and
19 * fitness. In no event shall Lucent Technologies be liable for any
20 * special, indirect or consequential damages or any damages
21 * whatsoever resulting from loss of use, data or profits, whether in
22 * an action of contract, negligence or other tortuous action, arising
23 * out of or in connection with the use or performance of this
24 * software.
25 */
26
27
28 #include "bltInt.h"
29 #include <bltHash.h>
30 #include <bltChain.h>
31
32 #define VECTOR_THREAD_KEY "BLT Vector Data"
33 #define VECTOR_MAGIC ((unsigned int) 0x46170277)
34
35 /* These defines allow parsing of different types of indices */
36
37 #define INDEX_SPECIAL (1<<0) /* Recognize "min", "max", and "++end" as
38 * valid indices */
39 #define INDEX_COLON (1<<1) /* Also recognize a range of indices
40 * separated by a colon */
41 #define INDEX_CHECK (1<<2) /* Verify that the specified index or
42 * range of indices are within limits */
43 #define INDEX_VAR_TRACE (1<<3) /* Index lookup on array trace allow -1,-1. */
44
45 #define INDEX_ALL_FLAGS (INDEX_SPECIAL | INDEX_COLON | INDEX_CHECK)
46
47
48 #define SPECIAL_INDEX -2
49
50
51 typedef struct {
52 Blt_HashTable vectorTable; /* Table of vectors */
53 Blt_HashTable mathProcTable; /* Table of vector math functions */
54 Blt_HashTable indexProcTable;
55 Tcl_Interp *interp;
56 unsigned int nextId;
57 int bltNoCommand;
58 int bltNoVariable;
59 int bltMaxSize;
60 int bltFreeOnUnset;
61 int bltFlushArray;
62 int bltOldCreate;
63 } VectorInterpData;
64
65 /*
66 * VectorObject --
67 *
68 * A vector is an array of double precision values. It can be
69 * accessed through a Tcl command, a Tcl array variable, or C
70 * API. The storage for the array points initially to a
71 * statically allocated buffer, but to malloc-ed memory if more
72 * is necessary.
73 *
74 * Vectors can be shared by several clients (for example, two
75 * different graph widgets). The data is shared. When a client
76 * wants to use a vector, it allocates a vector identifier, which
77 * identifies the client. Clients use this ID to specify a
78 * callback routine to be invoked whenever the vector is modified
79 * or destroyed. Whenever the vector is updated or destroyed,
80 * each client is notified of the change by their callback
81 * routine.
82 */
83
84 typedef struct {
85
86 /*
87 * If you change these fields, make sure you change the definition
88 * of Blt_Vector in bltInt.h and blt.h too.
89 */
90
91 double *valueArr; /* Array of values (malloc-ed) */
92
93 int length; /* Current number of values in the array. */
94
95 int size; /* Maximum number of values that can be stored
96 * in the value array. */
97
98 double min, max; /* Minimum and maximum values in the vector */
99
100 int dirty; /* Indicates if the vector has been updated */
101
102 int reserved;
103
104 /* The following fields are local to this module */
105
106 char *name; /* The namespace-qualified name of the vector.
107 * It points to the hash key allocated for the
108 * entry in the vector hash table. */
109
110 VectorInterpData *dataPtr;
111 Tcl_Interp *interp; /* Interpreter associated with the
112 * vector */
113
114 Blt_HashEntry *hashPtr; /* If non-NULL, pointer in a hash table to
115 * track the vectors in use. */
116
117 Tcl_FreeProc *freeProc; /* Address of procedure to call to
118 * release storage for the value
119 * array, Optionally can be one of the
120 * following: TCL_STATIC, TCL_DYNAMIC,
121 * or TCL_VOLATILE. */
122
123 char *arrayName; /* The name of the Tcl array variable
124 * mapped to the vector
125 * (malloc'ed). If NULL, indicates
126 * that the vector isn't mapped to any
127 * variable */
128
129 Tcl_Namespace *varNsPtr; /* Namespace context of the Tcl variable
130 * associated with the vector. This is
131 * needed to reset the indices of the array
132 * variable. */
133
134 Tcl_Namespace *nsPtr; /* Namespace context of the vector itself. */
135
136 int offset; /* Offset from zero of the vector's
137 * starting index */
138
139 Tcl_Command cmdToken; /* Token for vector's Tcl command. */
140
141 Blt_Chain *chainPtr; /* List of clients using this vector */
142
143 int notifyFlags; /* Notification flags. See definitions
144 * below */
145
146 int varFlags; /* Indicate if the variable is global,
147 * namespace, or local */
148
149 int freeOnUnset; /* For backward compatibility only: If
150 * non-zero, free the vector when its
151 * variable is unset. */
152 int flush;
153
154 int first, last; /* Selected region of vector. This is used
155 * mostly for the math routines */
156 int numcols; /* Matrix row size. */
157 Tcl_Obj *callback; /* Command to call on notify. */
158
159 } VectorObject;
160
161 #define NOTIFY_UPDATED ((int)BLT_VECTOR_NOTIFY_UPDATE)
162 #define NOTIFY_DESTROYED ((int)BLT_VECTOR_NOTIFY_DESTROY)
163
164 #define NOTIFY_NEVER (1<<3) /* Never notify clients of updates to
165 * the vector */
166 #define NOTIFY_ALWAYS (1<<4) /* Notify clients after each update
167 * of the vector is made */
168 #define NOTIFY_WHENIDLE (1<<5) /* Notify clients at the next idle point
169 * that the vector has been updated. */
170
171 #define NOTIFY_PENDING (1<<6) /* A do-when-idle notification of the
172 * vector's clients is pending. */
173 #define NOTIFY_NOW (1<<7) /* Notify clients of changes once
174 * immediately */
175
176 #define NOTIFY_WHEN_MASK (NOTIFY_NEVER|NOTIFY_ALWAYS|NOTIFY_WHENIDLE)
177
178 #define UPDATE_RANGE (1<<9) /* The data of the vector has changed.
179 * Update the min and max limits when
180 * they are needed */
181
182 #define FindRange(array, first, last, min, max) \
183 { \
184 min = max = 0.0; \
185 if (first <= last) { \
186 register int i; \
187 min = max = array[first]; \
188 for (i = first + 1; i <= last; i++) { \
189 if (min > array[i]) { \
190 min = array[i]; \
191 } else if (max < array[i]) { \
192 max = array[i]; \
193 } \
194 } \
195 } \
196 }
197
198 extern void Blt_VectorInstallSpecialIndices
199 _ANSI_ARGS_((Blt_HashTable *tablePtr));
200
201 extern void Blt_VectorInstallMathFunctions
202 _ANSI_ARGS_((Blt_HashTable *tablePtr));
203
204 extern void Blt_VectorUninstallMathFunctions
205 _ANSI_ARGS_((Blt_HashTable *tablePtr));
206
207 extern VectorInterpData *Blt_VectorGetInterpData
208 _ANSI_ARGS_((Tcl_Interp *interp));
209
210 extern VectorObject *Blt_VectorNew _ANSI_ARGS_((VectorInterpData *dataPtr));
211
212 extern int Blt_VectorDuplicate _ANSI_ARGS_((VectorObject *destPtr,
213 VectorObject *srcPtr));
214
215 extern int Blt_VectorChangeLength _ANSI_ARGS_((VectorObject *vPtr,
216 int length));
217
218 extern VectorObject *Blt_VectorParseElement _ANSI_ARGS_((Tcl_Interp *interp,
219 VectorInterpData *dataPtr, CONST char *start, char **endPtr,
220 int flags));
221
222 extern void Blt_VectorFree _ANSI_ARGS_((VectorObject *vPtr));
223
224 extern int *Blt_VectorSortIndex _ANSI_ARGS_((VectorObject **vPtrPtr,
225 int nVectors));
226
227 extern int Blt_VectorLookupName _ANSI_ARGS_((VectorInterpData *dataPtr,
228 char *vecName, VectorObject **vPtrPtr));
229
230 extern VectorObject *Blt_VectorCreate _ANSI_ARGS_((VectorInterpData *dataPtr,
231 CONST char *name, CONST char *cmdName, CONST char *varName,
232 int *newPtr));
233
234 extern void Blt_VectorUpdateRange _ANSI_ARGS_((VectorObject *vPtr));
235
236 extern void Blt_VectorUpdateClients _ANSI_ARGS_((VectorObject *vPtr));
237
238 extern void Blt_VectorFlushCache _ANSI_ARGS_((VectorObject *vPtr));
239
240 extern int Blt_VectorReset _ANSI_ARGS_((VectorObject *vPtr, double *dataArr,
241 int nValues, int arraySize, Tcl_FreeProc *freeProc));
242
243 extern int Blt_VectorGetIndex _ANSI_ARGS_((Tcl_Interp *interp,
244 VectorObject *vPtr, CONST char *string, int *indexPtr, int flags,
245 Blt_VectorIndexProc **procPtrPtr));
246
247 extern int Blt_VectorGetIndexRange _ANSI_ARGS_((Tcl_Interp *interp,
248 VectorObject *vPtr, CONST char *string, int flags,
249 Blt_VectorIndexProc **procPtrPtr));
250
251 extern int Blt_VectorMapVariable _ANSI_ARGS_((Tcl_Interp *interp,
252 VectorObject *vPtr, CONST char *name));
253
254 #if (TCL_MAJOR_VERSION == 7)
255 extern Tcl_CmdProc Blt_VectorInstCmd;
256 #else
257 extern Tcl_ObjCmdProc Blt_VectorInstCmd;
258 #endif
259
260 extern Tcl_VarTraceProc Blt_VectorVarTrace;
261
262 extern Tcl_IdleProc Blt_VectorNotifyClients;