|
@@ -0,0 +1,179 @@
|
|
1
|
+#include "cmPrefix.h"
|
|
2
|
+#include "cmGlobal.h"
|
|
3
|
+#include "cmFloatTypes.h"
|
|
4
|
+#include "cmRpt.h"
|
|
5
|
+#include "cmErr.h"
|
|
6
|
+#include "cmCtx.h"
|
|
7
|
+#include "cmMem.h"
|
|
8
|
+#include "cmMallocDebug.h"
|
|
9
|
+#include "cmLinkedHeap.h"
|
|
10
|
+#include "cmSymTbl.h"
|
|
11
|
+#include "cmJson.h"
|
|
12
|
+#include "cmDspValue.h"
|
|
13
|
+#include "cmDspCtx.h"
|
|
14
|
+#include "cmDspClass.h"
|
|
15
|
+#include "cmDspStore.h"
|
|
16
|
+
|
|
17
|
+typedef struct
|
|
18
|
+{
|
|
19
|
+ unsigned symId;
|
|
20
|
+ cmDspValue_t value;
|
|
21
|
+} cmDspStoreVar_t;
|
|
22
|
+
|
|
23
|
+typedef struct
|
|
24
|
+{
|
|
25
|
+ cmErr_t err;
|
|
26
|
+ cmDspStoreVar_t* array;
|
|
27
|
+ unsigned allocCnt;
|
|
28
|
+ unsigned growCnt;
|
|
29
|
+ unsigned curCnt;
|
|
30
|
+} cmDspStore_t;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+cmDspStoreH_t cmDspStoreNullHandle = cmSTATIC_NULL_HANDLE;
|
|
34
|
+
|
|
35
|
+cmDspStore_t* _cmDspStoreHandleToPtr( cmDspStoreH_t h )
|
|
36
|
+{
|
|
37
|
+ cmDspStore_t* p = (cmDspStore_t*)h.h;
|
|
38
|
+ assert( p != NULL );
|
|
39
|
+ return p;
|
|
40
|
+}
|
|
41
|
+
|
|
42
|
+cmDspRC_t _cmDspStoreFree( cmDspStore_t* p )
|
|
43
|
+{
|
|
44
|
+ cmMemFree(p->array);
|
|
45
|
+ cmMemFree(p);
|
|
46
|
+ return kOkDspRC;
|
|
47
|
+}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+cmDspRC_t cmDspStoreAlloc( cmCtx_t* ctx, cmDspStoreH_t* hp, unsigned initStoreCnt, unsigned growStoreCnt )
|
|
51
|
+{
|
|
52
|
+ cmDspRC_t rc;
|
|
53
|
+ if((rc = cmDspStoreFree(hp)) != kOkDspRC )
|
|
54
|
+ return rc;
|
|
55
|
+
|
|
56
|
+ cmDspStore_t* p = cmMemAllocZ(cmDspStore_t,1);
|
|
57
|
+
|
|
58
|
+ cmErrSetup(&p->err,&ctx->rpt,"cmDspStore");
|
|
59
|
+
|
|
60
|
+ p->array = cmMemAllocZ(cmDspStoreVar_t,initStoreCnt);
|
|
61
|
+ p->allocCnt = initStoreCnt;
|
|
62
|
+ p->curCnt = 0;
|
|
63
|
+ p->growCnt = growStoreCnt;
|
|
64
|
+
|
|
65
|
+ hp->h = p;
|
|
66
|
+
|
|
67
|
+ return rc;
|
|
68
|
+}
|
|
69
|
+
|
|
70
|
+cmDspRC_t cmDspStoreFree( cmDspStoreH_t *hp )
|
|
71
|
+{
|
|
72
|
+ cmDspRC_t rc = kOkDspRC;
|
|
73
|
+ if(hp==NULL || cmDspStoreIsValid(*hp)==false )
|
|
74
|
+ return rc;
|
|
75
|
+
|
|
76
|
+ cmDspStore_t* p = _cmDspStoreHandleToPtr(*hp);
|
|
77
|
+
|
|
78
|
+ if((rc = _cmDspStoreFree(p)) != kOkDspRC )
|
|
79
|
+ return rc;
|
|
80
|
+
|
|
81
|
+ hp->h = NULL;
|
|
82
|
+
|
|
83
|
+ return rc;
|
|
84
|
+}
|
|
85
|
+
|
|
86
|
+bool cmDspStoreIsValid( cmDspStoreH_t h )
|
|
87
|
+{ return h.h; }
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+cmDspStoreVar_t* _cmDspStoreSymToPtr( cmDspStore_t* p, unsigned symId )
|
|
91
|
+{
|
|
92
|
+ cmDspStoreVar_t* vp = p->array;
|
|
93
|
+ cmDspStoreVar_t* ep = p->array + p->curCnt;
|
|
94
|
+ for(; vp<ep; ++vp)
|
|
95
|
+ if( vp->symId == symId )
|
|
96
|
+ return vp;
|
|
97
|
+ return NULL;
|
|
98
|
+}
|
|
99
|
+
|
|
100
|
+cmDspStoreVar_t* _cmDspStoreIdToPtr( cmDspStore_t* p, unsigned id )
|
|
101
|
+{
|
|
102
|
+ if( id < p->curCnt )
|
|
103
|
+ return p->array + id;
|
|
104
|
+
|
|
105
|
+ return NULL;
|
|
106
|
+}
|
|
107
|
+
|
|
108
|
+cmDspStoreVar_t* _cmDspStoreAppend( cmDspStore_t* p )
|
|
109
|
+{
|
|
110
|
+ cmDspStoreVar_t* vp = NULL;
|
|
111
|
+
|
|
112
|
+ if( p->curCnt >= p->allocCnt )
|
|
113
|
+ {
|
|
114
|
+ p->allocCnt += p->growCnt;
|
|
115
|
+ p->array = cmMemResizePZ(cmDspStoreVar_t,p->array,p->allocCnt);
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ vp = p->array + p->curCnt;
|
|
119
|
+
|
|
120
|
+ p->curCnt += 1;
|
|
121
|
+
|
|
122
|
+ return vp;
|
|
123
|
+}
|
|
124
|
+
|
|
125
|
+unsigned cmDspStoreSymToId( cmDspStoreH_t h, unsigned symId )
|
|
126
|
+{
|
|
127
|
+ cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
|
|
128
|
+ const cmDspStoreVar_t* vp;
|
|
129
|
+ if((vp = _cmDspStoreSymToPtr(p,symId)) == NULL )
|
|
130
|
+ return cmInvalidId;
|
|
131
|
+ return vp - p->array;
|
|
132
|
+}
|
|
133
|
+
|
|
134
|
+unsigned cmDspStoreIdToSym( cmDspStoreH_t h, unsigned id )
|
|
135
|
+{
|
|
136
|
+ cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
|
|
137
|
+ const cmDspStoreVar_t* vp;
|
|
138
|
+ if((vp = _cmDspStoreIdToPtr(p,id)) == NULL )
|
|
139
|
+ return cmInvalidId;
|
|
140
|
+ return vp->symId;
|
|
141
|
+}
|
|
142
|
+
|
|
143
|
+const cmDspValue_t* cmDspStoreIdToValue( cmDspStoreH_t h, unsigned id )
|
|
144
|
+{
|
|
145
|
+ cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
|
|
146
|
+ const cmDspStoreVar_t* vp;
|
|
147
|
+ if((vp = _cmDspStoreIdToPtr(p,id)) == NULL )
|
|
148
|
+ return NULL;
|
|
149
|
+ return &vp->value;
|
|
150
|
+}
|
|
151
|
+
|
|
152
|
+cmDspRC_t cmDspStoreSetValueViaId( cmDspStoreH_t h, unsigned id, const cmDspValue_t* val )
|
|
153
|
+{
|
|
154
|
+ cmDspRC_t rc = kOkDspRC;
|
|
155
|
+ cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
|
|
156
|
+ cmDspStoreVar_t* vp = NULL;
|
|
157
|
+
|
|
158
|
+ if((vp = _cmDspStoreIdToPtr(p,id)) == NULL )
|
|
159
|
+ return cmErrMsg(&p->err,kVarNotFoundDspRC,"There is not global variable at with id:%i\n",id);
|
|
160
|
+
|
|
161
|
+ cmDsvCopy(&vp->value,val);
|
|
162
|
+ return rc;
|
|
163
|
+}
|
|
164
|
+
|
|
165
|
+unsigned cmDspStoreSetValueViaSym( cmDspStoreH_t h, unsigned symId, const cmDspValue_t* val )
|
|
166
|
+{
|
|
167
|
+ cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
|
|
168
|
+ cmDspStoreVar_t* vp = NULL;
|
|
169
|
+
|
|
170
|
+ if((vp = _cmDspStoreSymToPtr(p,symId)) == NULL )
|
|
171
|
+ vp = _cmDspStoreAppend(p);
|
|
172
|
+
|
|
173
|
+ assert(vp != NULL );
|
|
174
|
+
|
|
175
|
+ cmDsvCopy(&vp->value,val);
|
|
176
|
+ vp->symId = symId;
|
|
177
|
+
|
|
178
|
+ return vp - p->array;
|
|
179
|
+}
|