|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/asnlib/asngenob.c |
source navigation diff markup identifier search freetext search file search |
1 /* asngenob.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: asngenob.c
27 *
28 * Author: Sirotkin/Epstein
29 *
30 * Version Creation Date: 4/21/94
31 *
32 * $Revision: 6.2 $
33 *
34 * File Description:
35 * Generic routines shared by object loaders which are automatically
36 * generated by ASNCODE.
37 *
38 * Modifications:
39 * --------------------------------------------------------------------------
40 * Date Name Description of modification
41 * ------- ---------- -----------------------------------------------------
42 *
43 * $Log: asngenob.c,v $
44 * Revision 6.2 2000/12/12 15:56:12 ostell
45 * added support BigInt
46 *
47 * Revision 6.1 1997/10/29 02:40:56 vakatov
48 * Type castings to pass through the C++ compiler
49 *
50 * Revision 6.0 1997/08/25 18:09:57 madden
51 * Revision changed to 6.0
52 *
53 * Revision 5.1 1996/12/03 21:43:48 vakatov
54 * Adopted for 32-bit MS-Windows DLLs
55 *
56 * Revision 5.0 1996/05/28 14:00:29 ostell
57 * Set to revision 5.0
58 *
59 * Revision 4.0 1995/07/26 13:47:38 ostell
60 * force revision to 4.0
61 *
62 * Revision 1.3 1995/05/15 18:38:28 ostell
63 * added Log line
64 *
65 *
66 * ==========================================================================
67 */
68
69 #include <asn.h>
70
71 typedef struct struct__Generic_linked_list {
72 struct struct__Generic_linked_list PNTR next;
73 } AsnGenericLinkedList, PNTR AsnGenericLinkListPtr;
74
75
76 NLM_EXTERN ValNodePtr LIBCALL AsnGenericBaseSeqOfAsnRead (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr orig, int whichvalslot, BoolPtr isError)
77 {
78 AsnTypePtr start_atp;
79 ValNodePtr current;
80 ValNodePtr head = NULL;
81 ValNodePtr prev = NULL;
82 AsnTypePtr atp = orig;
83 DataVal av;
84
85 if (isError != NULL)
86 *isError = FALSE;
87
88 if (aip == NULL)
89 return NULL;
90
91 if (AsnReadVal (aip, atp, &av) <= 0) /* START_STRUCT */
92 goto erret;
93
94 start_atp = atp;
95
96 while ((atp = AsnReadId (aip, amp, atp)) != start_atp) {
97 if (atp == NULL)
98 goto erret;
99
100 current = ValNodeNew (prev);
101 if (current == NULL)
102 goto erret;
103 switch (whichvalslot) {
104 case ASNCODE_PTRVAL_SLOT:
105 case ASNCODE_BYTEVAL_SLOT:
106 if (AsnReadVal (aip, atp, &av) <= 0)
107 goto erret;
108 current->data.ptrvalue = av.ptrvalue;
109 break;
110 case ASNCODE_REALVAL_SLOT:
111 if (AsnReadVal (aip, atp, &av) <= 0)
112 goto erret;
113 current->data.realvalue = av.realvalue;
114 break;
115 case ASNCODE_INTVAL_SLOT:
116 if (AsnReadVal (aip, atp, &av) <= 0)
117 goto erret;
118 current->data.intvalue = av.intvalue;
119 break;
120 case ASNCODE_BIGINTVAL_SLOT:
121 if (AsnReadVal (aip, atp, &av) <= 0)
122 goto erret;
123 current->data.bigintvalue = av.bigintvalue;
124 break;
125 case ASNCODE_BOOLVAL_SLOT:
126 if (AsnReadVal (aip, atp, &av) <= 0)
127 goto erret;
128 current->data.boolvalue = av.boolvalue;
129 break;
130 }
131
132 if (head == NULL)
133 head = current;
134 else
135 prev->next = current;
136 prev = current;
137 }
138 if (AsnReadVal (aip, atp, &av) <= 0) /* END_STRUCT */
139 goto erret;
140
141 ret:
142 return head;
143
144 erret:
145 head = ValNodeFree (head);
146 if (isError != NULL)
147 *isError = TRUE;
148 goto ret;
149 }
150
151 NLM_EXTERN Boolean LIBCALL AsnGenericBaseSeqOfAsnWrite (ValNodePtr ptr, int whichvalslot, AsnIoPtr aip, AsnTypePtr bag_atp, AsnTypePtr element_atp)
152 {
153 Boolean retval = FALSE;
154
155 if (ptr == NULL && bag_atp->optional)
156 return TRUE;
157
158 if (!AsnOpenStruct (aip, bag_atp, ptr))
159 goto ret;
160
161 if (ptr != NULL) {
162 ValNodePtr current;
163
164 for (current = ptr; current; current = current->next) {
165 switch (whichvalslot) {
166 case ASNCODE_PTRVAL_SLOT:
167 case ASNCODE_BYTEVAL_SLOT:
168 case ASNCODE_REALVAL_SLOT:
169 case ASNCODE_INTVAL_SLOT:
170 case ASNCODE_BIGINTVAL_SLOT:
171 case ASNCODE_BOOLVAL_SLOT:
172 if (AsnWrite (aip, element_atp, &(current->data)) <= 0)
173 goto ret;
174 break;
175 }
176 }
177
178 }
179 if (!AsnCloseStruct (aip, bag_atp, ptr)) {
180 goto ret;
181 }
182 retval = TRUE;
183
184 ret:
185 return retval;
186 }
187
188
189 NLM_EXTERN Boolean LIBCALL AsnGenericBaseSeqOfFree (ValNodePtr ptr, int whichvalslot)
190 {
191 Boolean retval = TRUE;
192 ValNodePtr current, nextcur;
193
194 for (current = ptr; current; current = nextcur) {
195 nextcur = current->next;
196 switch (whichvalslot) {
197 case ASNCODE_BYTEVAL_SLOT:
198 BSFree ((ByteStorePtr)current->data.ptrvalue);
199 break;
200 case ASNCODE_PTRVAL_SLOT:
201 MemFree (current->data.ptrvalue);
202 current->data.ptrvalue = NULL;
203 break;
204 case ASNCODE_REALVAL_SLOT:
205 case ASNCODE_INTVAL_SLOT:
206 case ASNCODE_BIGINTVAL_SLOT:
207 case ASNCODE_BOOLVAL_SLOT:
208 /* No-op */
209 break;
210 }
211 }
212
213 ValNodeFree (ptr);
214 return retval;
215 }
216
217
218 NLM_EXTERN Pointer AsnGenericUserSeqOfAsnRead (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr orig, BoolPtr isError, AsnReadFunc readfunc, AsnOptFreeFunc freefunc)
219 {
220 AsnTypePtr start_atp;
221 AsnGenericLinkListPtr current;
222 AsnGenericLinkListPtr head = NULL;
223 AsnGenericLinkListPtr prev = NULL;
224 AsnTypePtr atp = orig;
225 DataVal av;
226
227 if (isError != NULL)
228 *isError = FALSE;
229
230 if (aip == NULL)
231 return NULL;
232
233 if (AsnReadVal (aip, atp, &av) <= 0) /* START_STRUCT */
234 goto erret;
235
236 start_atp = atp;
237
238 while ((atp = AsnReadId (aip, amp, atp)) != start_atp) {
239 if (atp == NULL)
240 goto erret;
241
242 current = (AsnGenericLinkListPtr) readfunc (aip, atp);
243 if (current == NULL)
244 goto erret;
245
246 if (head == NULL)
247 head = current;
248 else
249 prev->next = current;
250 prev = current;
251 }
252 if (AsnReadVal (aip, atp, &av) <= 0) /* END_STRUCT */
253 goto erret;
254
255 ret:
256 return (Pointer) head;
257
258 erret:
259 head = (AsnGenericLinkListPtr) freefunc (head);
260 if (isError != NULL)
261 *isError = TRUE;
262
263 goto ret;
264 }
265
266
267 NLM_EXTERN Boolean LIBCALL AsnGenericUserSeqOfAsnWrite (Pointer ptr, AsnWriteFunc writefunc, AsnIoPtr aip, AsnTypePtr bag_atp, AsnTypePtr element_atp)
268 {
269 Boolean retval = FALSE;
270
271 if (ptr == NULL && bag_atp->optional)
272 return TRUE;
273
274 if (!AsnOpenStruct (aip, bag_atp, ptr))
275 goto ret;
276
277 if (ptr != NULL) {
278 AsnGenericLinkListPtr current;
279
280 for (current = (AsnGenericLinkListPtr) ptr; current; current = current->next) {
281 if (!writefunc (current, aip, element_atp))
282 goto ret;
283 }
284
285 }
286 if (!AsnCloseStruct (aip, bag_atp, ptr)) {
287 goto ret;
288 }
289 retval = TRUE;
290
291 ret:
292 return retval;
293 }
294
295
296 NLM_EXTERN Boolean LIBCALL AsnGenericUserSeqOfFree (Pointer ptr, AsnOptFreeFunc freefunc)
297 {
298 Boolean retval = TRUE;
299 AsnGenericLinkListPtr current, nextcur;
300
301 for (current = (AsnGenericLinkListPtr) ptr; current; current = nextcur) {
302 nextcur = current->next;
303 freefunc (current);
304 }
305
306 return retval;
307 }
308
309
310 NLM_EXTERN Pointer LIBCALL AsnGenericChoiceSeqOfAsnRead (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr orig, BoolPtr isError, AsnReadFunc readfunc, AsnOptFreeFunc freefunc)
311 {
312 AsnTypePtr start_atp;
313 ValNodePtr current;
314 ValNodePtr head = NULL;
315 ValNodePtr prev = NULL;
316 AsnTypePtr atp = orig;
317 DataVal av;
318
319 if (isError != NULL)
320 *isError = FALSE;
321
322 if (aip == NULL)
323 return NULL;
324
325 if (AsnReadVal (aip, atp, &av) <= 0) /* START_STRUCT */
326 goto erret;
327
328 start_atp = atp;
329
330 while ((atp = AsnReadId (aip, amp, atp)) != start_atp) {
331 if (atp == NULL)
332 goto erret;
333
334 current = (ValNodePtr) readfunc (aip, atp);
335 if (current == NULL)
336 goto erret;
337
338 if (head == NULL)
339 head = current;
340 else
341 prev->next = current;
342 prev = current;
343 }
344 if (AsnReadVal (aip, atp, &av) <= 0) /* END_STRUCT */
345 goto erret;
346
347 ret:
348 return (Pointer) head;
349
350 erret:
351 head = (ValNodePtr) freefunc (head);
352 if (isError != NULL)
353 *isError = TRUE;
354
355 goto ret;
356 }
357
358
359 NLM_EXTERN Boolean LIBCALL AsnGenericChoiceSeqOfAsnWrite (Pointer ptr, AsnWriteFunc writefunc, AsnIoPtr aip, AsnTypePtr bag_atp, AsnTypePtr element_atp)
360 {
361 Boolean retval = FALSE;
362
363 if (ptr == NULL && bag_atp->optional)
364 return TRUE;
365
366 if (!AsnOpenStruct (aip, bag_atp, ptr))
367 goto ret;
368
369 if (ptr != NULL) {
370 ValNodePtr current;
371
372 for (current = (ValNodePtr) ptr; current; current = current->next) {
373 if (!writefunc (current, aip, element_atp))
374 goto ret;
375 }
376
377 }
378 if (!AsnCloseStruct (aip, bag_atp, ptr)) {
379 goto ret;
380 }
381 retval = TRUE;
382
383 ret:
384 return retval;
385 }
386
387 NLM_EXTERN Boolean LIBCALL AsnGenericChoiceSeqOfFree (Pointer ptr, AsnOptFreeFunc freefunc)
388 {
389 Boolean retval = TRUE;
390 ValNodePtr current, nextcur;
391
392 for (current = (ValNodePtr) ptr; current; current = nextcur) {
393 nextcur = current->next;
394 freefunc (current);
395 }
396
397 return retval;
398 }
399 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |