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_ALL_FLAGS (INDEX_SPECIAL | INDEX_COLON | INDEX_CHECK)
|
---|
44 |
|
---|
45 | #define SPECIAL_INDEX -2
|
---|
46 |
|
---|
47 |
|
---|
48 | typedef struct {
|
---|
49 | Blt_HashTable vectorTable; /* Table of vectors */
|
---|
50 | Blt_HashTable mathProcTable; /* Table of vector math functions */
|
---|
51 | Blt_HashTable indexProcTable;
|
---|
52 | Tcl_Interp *interp;
|
---|
53 | unsigned int nextId;
|
---|
54 | } VectorInterpData;
|
---|
55 |
|
---|
56 | /*
|
---|
57 | * VectorObject --
|
---|
58 | *
|
---|
59 | * A vector is an array of double precision values. It can be
|
---|
60 | * accessed through a Tcl command, a Tcl array variable, or C
|
---|
61 | * API. The storage for the array points initially to a
|
---|
62 | * statically allocated buffer, but to malloc-ed memory if more
|
---|
63 | * is necessary.
|
---|
64 | *
|
---|
65 | * Vectors can be shared by several clients (for example, two
|
---|
66 | * different graph widgets). The data is shared. When a client
|
---|
67 | * wants to use a vector, it allocates a vector identifier, which
|
---|
68 | * identifies the client. Clients use this ID to specify a
|
---|
69 | * callback routine to be invoked whenever the vector is modified
|
---|
70 | * or destroyed. Whenever the vector is updated or destroyed,
|
---|
71 | * each client is notified of the change by their callback
|
---|
72 | * routine.
|
---|
73 | */
|
---|
74 |
|
---|
75 | typedef struct {
|
---|
76 |
|
---|
77 | /*
|
---|
78 | * If you change these fields, make sure you change the definition
|
---|
79 | * of Blt_Vector in bltInt.h and blt.h too.
|
---|
80 | */
|
---|
81 |
|
---|
82 | double *valueArr; /* Array of values (malloc-ed) */
|
---|
83 |
|
---|
84 | int length; /* Current number of values in the array. */
|
---|
85 |
|
---|
86 | int size; /* Maximum number of values that can be stored
|
---|
87 | * in the value array. */
|
---|
88 |
|
---|
89 | double min, max; /* Minimum and maximum values in the vector */
|
---|
90 |
|
---|
91 | int dirty; /* Indicates if the vector has been updated */
|
---|
92 |
|
---|
93 | int reserved;
|
---|
94 |
|
---|
95 | /* The following fields are local to this module */
|
---|
96 |
|
---|
97 | char *name; /* The namespace-qualified name of the vector.
|
---|
98 | * It points to the hash key allocated for the
|
---|
99 | * entry in the vector hash table. */
|
---|
100 |
|
---|
101 | VectorInterpData *dataPtr;
|
---|
102 | Tcl_Interp *interp; /* Interpreter associated with the
|
---|
103 | * vector */
|
---|
104 |
|
---|
105 | Blt_HashEntry *hashPtr; /* If non-NULL, pointer in a hash table to
|
---|
106 | * track the vectors in use. */
|
---|
107 |
|
---|
108 | Tcl_FreeProc *freeProc; /* Address of procedure to call to
|
---|
109 | * release storage for the value
|
---|
110 | * array, Optionally can be one of the
|
---|
111 | * following: TCL_STATIC, TCL_DYNAMIC,
|
---|
112 | * or TCL_VOLATILE. */
|
---|
113 |
|
---|
114 | char *arrayName; /* The name of the Tcl array variable
|
---|
115 | * mapped to the vector
|
---|
116 | * (malloc'ed). If NULL, indicates
|
---|
117 | * that the vector isn't mapped to any
|
---|
118 | * variable */
|
---|
119 |
|
---|
120 | Tcl_Namespace *varNsPtr; /* Namespace context of the Tcl variable
|
---|
121 | * associated with the vector. This is
|
---|
122 | * needed to reset the indices of the array
|
---|
123 | * variable. */
|
---|
124 |
|
---|
125 | Tcl_Namespace *nsPtr; /* Namespace context of the vector itself. */
|
---|
126 |
|
---|
127 | int offset; /* Offset from zero of the vector's
|
---|
128 | * starting index */
|
---|
129 |
|
---|
130 | Tcl_Command cmdToken; /* Token for vector's Tcl command. */
|
---|
131 |
|
---|
132 | Blt_Chain *chainPtr; /* List of clients using this vector */
|
---|
133 |
|
---|
134 | int notifyFlags; /* Notification flags. See definitions
|
---|
135 | * below */
|
---|
136 |
|
---|
137 | int varFlags; /* Indicate if the variable is global,
|
---|
138 | * namespace, or local */
|
---|
139 |
|
---|
140 | int freeOnUnset; /* For backward compatibility only: If
|
---|
141 | * non-zero, free the vector when its
|
---|
142 | * variable is unset. */
|
---|
143 | int flush;
|
---|
144 |
|
---|
145 | int first, last; /* Selected region of vector. This is used
|
---|
146 | * mostly for the math routines */
|
---|
147 | } VectorObject;
|
---|
148 |
|
---|
149 | #define NOTIFY_UPDATED ((int)BLT_VECTOR_NOTIFY_UPDATE)
|
---|
150 | #define NOTIFY_DESTROYED ((int)BLT_VECTOR_NOTIFY_DESTROY)
|
---|
151 |
|
---|
152 | #define NOTIFY_NEVER (1<<3) /* Never notify clients of updates to
|
---|
153 | * the vector */
|
---|
154 | #define NOTIFY_ALWAYS (1<<4) /* Notify clients after each update
|
---|
155 | * of the vector is made */
|
---|
156 | #define NOTIFY_WHENIDLE (1<<5) /* Notify clients at the next idle point
|
---|
157 | * that the vector has been updated. */
|
---|
158 |
|
---|
159 | #define NOTIFY_PENDING (1<<6) /* A do-when-idle notification of the
|
---|
160 | * vector's clients is pending. */
|
---|
161 | #define NOTIFY_NOW (1<<7) /* Notify clients of changes once
|
---|
162 | * immediately */
|
---|
163 |
|
---|
164 | #define NOTIFY_WHEN_MASK (NOTIFY_NEVER|NOTIFY_ALWAYS|NOTIFY_WHENIDLE)
|
---|
165 |
|
---|
166 | #define UPDATE_RANGE (1<<9) /* The data of the vector has changed.
|
---|
167 | * Update the min and max limits when
|
---|
168 | * they are needed */
|
---|
169 |
|
---|
170 | extern void Blt_VectorInstallSpecialIndices
|
---|
171 | _ANSI_ARGS_((Blt_HashTable *tablePtr));
|
---|
172 |
|
---|
173 | extern void Blt_VectorInstallMathFunctions
|
---|
174 | _ANSI_ARGS_((Blt_HashTable *tablePtr));
|
---|
175 |
|
---|
176 | extern void Blt_VectorUninstallMathFunctions
|
---|
177 | _ANSI_ARGS_((Blt_HashTable *tablePtr));
|
---|
178 |
|
---|
179 | extern VectorInterpData *Blt_VectorGetInterpData
|
---|
180 | _ANSI_ARGS_((Tcl_Interp *interp));
|
---|
181 |
|
---|
182 | extern VectorObject *Blt_VectorNew _ANSI_ARGS_((VectorInterpData *dataPtr));
|
---|
183 |
|
---|
184 | extern int Blt_VectorDuplicate _ANSI_ARGS_((VectorObject *destPtr,
|
---|
185 | VectorObject *srcPtr));
|
---|
186 |
|
---|
187 | extern int Blt_VectorChangeLength _ANSI_ARGS_((VectorObject *vPtr,
|
---|
188 | int length));
|
---|
189 |
|
---|
190 | extern VectorObject *Blt_VectorParseElement _ANSI_ARGS_((Tcl_Interp *interp,
|
---|
191 | VectorInterpData *dataPtr, CONST char *start, char **endPtr,
|
---|
192 | int flags));
|
---|
193 |
|
---|
194 | extern void Blt_VectorFree _ANSI_ARGS_((VectorObject *vPtr));
|
---|
195 |
|
---|
196 | extern int *Blt_VectorSortIndex _ANSI_ARGS_((VectorObject **vPtrPtr,
|
---|
197 | int nVectors));
|
---|
198 |
|
---|
199 | extern int Blt_VectorLookupName _ANSI_ARGS_((VectorInterpData *dataPtr,
|
---|
200 | char *vecName, VectorObject **vPtrPtr));
|
---|
201 |
|
---|
202 | extern VectorObject *Blt_VectorCreate _ANSI_ARGS_((VectorInterpData *dataPtr,
|
---|
203 | CONST char *name, CONST char *cmdName, CONST char *varName,
|
---|
204 | int *newPtr));
|
---|
205 |
|
---|
206 | extern void Blt_VectorUpdateRange _ANSI_ARGS_((VectorObject *vPtr));
|
---|
207 |
|
---|
208 | extern void Blt_VectorUpdateClients _ANSI_ARGS_((VectorObject *vPtr));
|
---|
209 |
|
---|
210 | extern void Blt_VectorFlushCache _ANSI_ARGS_((VectorObject *vPtr));
|
---|
211 |
|
---|
212 | extern int Blt_VectorReset _ANSI_ARGS_((VectorObject *vPtr, double *dataArr,
|
---|
213 | int nValues, int arraySize, Tcl_FreeProc *freeProc));
|
---|
214 |
|
---|
215 | extern int Blt_VectorGetIndex _ANSI_ARGS_((Tcl_Interp *interp,
|
---|
216 | VectorObject *vPtr, CONST char *string, int *indexPtr, int flags,
|
---|
217 | Blt_VectorIndexProc **procPtrPtr));
|
---|
218 |
|
---|
219 | extern int Blt_VectorGetIndexRange _ANSI_ARGS_((Tcl_Interp *interp,
|
---|
220 | VectorObject *vPtr, CONST char *string, int flags,
|
---|
221 | Blt_VectorIndexProc **procPtrPtr));
|
---|
222 |
|
---|
223 | extern int Blt_VectorMapVariable _ANSI_ARGS_((Tcl_Interp *interp,
|
---|
224 | VectorObject *vPtr, CONST char *name));
|
---|
225 |
|
---|
226 | #if (TCL_MAJOR_VERSION == 7)
|
---|
227 | extern Tcl_CmdProc Blt_VectorInstCmd;
|
---|
228 | #else
|
---|
229 | extern Tcl_ObjCmdProc Blt_VectorInstCmd;
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | extern Tcl_VarTraceProc Blt_VectorVarTrace;
|
---|
233 |
|
---|
234 | extern Tcl_IdleProc Blt_VectorNotifyClients;
|
---|