|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/object/objacces.c |
source navigation diff markup identifier search freetext search file search |
1 /* objacces.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: objacces.c
27 *
28 * Author: James Ostell
29 *
30 * Version Creation Date: 1/1/91
31 *
32 * $Revision: 6.1 $
33 *
34 * File Description: Object manager for module NCBI-Access
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 * 05-13-93 Schuler All public functions are now declared LIBCALL.
41 *
42 * $Log: objacces.c,v $
43 * Revision 6.1 2004/04/01 13:43:07 lavr
44 * Spell "occurred", "occurrence", and "occurring"
45 *
46 * Revision 6.0 1997/08/25 18:49:05 madden
47 * Revision changed to 6.0
48 *
49 * Revision 4.1 1997/06/19 18:40:33 vakatov
50 * [WIN32,MSVC++] Adopted for the "NCBIOBJ.LIB" DLL'ization
51 *
52 * Revision 4.0 1995/07/26 13:48:06 ostell
53 * force revision to 4.0
54 *
55 * Revision 3.1 1995/05/15 21:22:00 ostell
56 * added Log line
57 *
58 *
59 *
60 * ==========================================================================
61 */
62 #include <asnacces.h> /* the AsnTool header */
63 #include <objacces.h> /* the general objects interface */
64
65 static Boolean loaded = FALSE;
66
67 /*****************************************************************************
68 *
69 * AccessAsnLoad()
70 *
71 *****************************************************************************/
72 NLM_EXTERN Boolean LIBCALL AccessAsnLoad (void)
73 {
74 if (loaded)
75 return TRUE;
76
77 if (AsnLoad())
78 loaded = TRUE;
79 return loaded;
80 }
81
82 /*****************************************************************************
83 *
84 * LinkSet Routines
85 *
86 *****************************************************************************/
87
88
89 /*****************************************************************************
90 *
91 * LinkSetNew()
92 *
93 *****************************************************************************/
94 NLM_EXTERN LinkSetPtr LIBCALL LinkSetNew (void)
95 {
96 return (LinkSetPtr)MemNew(sizeof(LinkSet));
97 }
98 /*****************************************************************************
99 *
100 * LinkSetFree(lsp)
101 *
102 *****************************************************************************/
103 NLM_EXTERN LinkSetPtr LIBCALL LinkSetFree (LinkSetPtr lsp)
104 {
105 if (lsp == NULL)
106 return (LinkSetPtr)NULL;
107 MemFree(lsp->uids);
108 MemFree(lsp->weights);
109 return (LinkSetPtr)MemFree(lsp);
110 }
111
112 /*****************************************************************************
113 *
114 * LinkSetAsnWrite(lsp, aip, atp)
115 * atp is the current type (if identifier of a parent struct)
116 * if atp == NULL, then assumes it stands alone (LinkSet ::=)
117 *
118 *****************************************************************************/
119 NLM_EXTERN Boolean LIBCALL LinkSetAsnWrite (LinkSetPtr lsp, AsnIoPtr aip, AsnTypePtr orig)
120 {
121 DataVal av;
122 AsnTypePtr atp;
123 Int4 num, i;
124 Int4Ptr ptr;
125 Boolean retval = FALSE;
126
127 if (! loaded)
128 {
129 if (! AccessAsnLoad())
130 return FALSE;
131 }
132
133 if (aip == NULL)
134 return FALSE;
135
136 atp = AsnLinkType(orig, LINK_SET); /* link local tree */
137 if (atp == NULL)
138 return FALSE;
139
140 if (lsp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
141
142 if (! AsnOpenStruct(aip, atp, (Pointer)lsp))
143 goto erret;
144 num = lsp->num;
145 av.intvalue = num;
146 if (! AsnWrite(aip, LINK_SET_num, &av))
147 goto erret;
148 ptr = lsp->uids;
149 if (! AsnOpenStruct(aip, LINK_SET_uids, (Pointer)lsp->uids))
150 goto erret;
151 for (i = 0; i < num; i++)
152 {
153 av.intvalue = ptr[i];
154 if (! AsnWrite(aip, LINK_SET_uids_E, &av))
155 goto erret;
156 }
157 if (! AsnCloseStruct(aip, LINK_SET_uids, (Pointer)lsp->uids))
158 goto erret;
159 if (lsp->weights != NULL)
160 {
161 ptr = lsp->weights;
162 if (! AsnOpenStruct(aip, LINK_SET_weights, (Pointer)lsp->weights))
163 goto erret;
164 for (i = 0; i < num; i++)
165 {
166 av.intvalue = ptr[i];
167 if (! AsnWrite(aip, LINK_SET_weights_E, &av))
168 goto erret;
169 }
170 if (! AsnCloseStruct(aip, LINK_SET_weights, (Pointer)lsp->weights))
171 goto erret;
172 }
173 if (! AsnCloseStruct(aip, atp, (Pointer)lsp))
174 goto erret;
175 retval = TRUE;
176 erret:
177 AsnUnlinkType(orig); /* unlink local tree */
178 return retval;
179 }
180
181 /*****************************************************************************
182 *
183 * LinkSetAsnRead(aip, atp)
184 * atp is the current type (if identifier of a parent struct)
185 * assumption is readIdent has occurred
186 * if atp == NULL, then assumes it stands alone and read ident
187 * has not occurred.
188 *
189 *****************************************************************************/
190 NLM_EXTERN LinkSetPtr LIBCALL LinkSetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
191 {
192 DataVal av;
193 AsnTypePtr atp;
194 LinkSetPtr lsp=NULL;
195 Int4 num, i;
196 Int4Ptr ptr;
197
198 if (! loaded)
199 {
200 if (! AccessAsnLoad())
201 return lsp;
202 }
203
204 if (aip == NULL)
205 return lsp;
206
207 if (orig == NULL) /* LinkSet ::= (self contained) */
208 atp = AsnReadId(aip, amp, LINK_SET);
209 else
210 atp = AsnLinkType(orig, LINK_SET); /* link in local tree */
211 if (atp == NULL)
212 return lsp;
213
214 lsp = LinkSetNew();
215 if (lsp == NULL)
216 goto erret;
217
218 if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
219 goto erret;
220 atp = AsnReadId(aip, amp, atp); /* find the num */
221 if (atp == NULL)
222 goto erret;
223 if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
224 goto erret;
225 num = av.intvalue;
226 lsp->num = num;
227
228 atp = AsnReadId(aip, amp, atp); /* start seq of uids */
229 if (atp == NULL)
230 goto erret;
231 if (AsnReadVal(aip, atp, &av) <= 0)
232 goto erret;
233 ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1))); /* 0 sentinel at end */
234 if (ptr == NULL)
235 goto erret;
236 lsp->uids = ptr;
237 i = 0;
238 while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_uids_E)
239 {
240 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
241 ptr[i] = av.intvalue;
242 i++;
243 if (i > num)
244 break;
245 }
246 if (atp == NULL)
247 goto erret;
248 if (i != num)
249 {
250 ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of uids in Link-set. line %ld",
251 aip->linenumber);
252 goto erret;
253 }
254 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end seq of */
255
256 atp = AsnReadId(aip, amp, atp);
257 if (atp == NULL)
258 goto erret;
259 if (atp == LINK_SET_weights)
260 {
261 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
262 ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1))); /* 0 sentinel at end */
263 if (ptr == NULL)
264 goto erret;
265 lsp->weights = ptr;
266 i = 0;
267 while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_weights_E)
268 {
269 if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
270 ptr[i] = av.intvalue;
271 i++;
272 if (i > num)
273 break;
274 }
275 if (atp == NULL)
276 goto erret;
277 if (i != num)
278 {
279 ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of weights in Link-set. line %ld",
280 aip->linenumber);
281 goto erret;
282 }
283 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end seq of */
284
285 if ((atp = AsnReadId(aip, amp, atp)) == NULL)
286 goto erret;
287 }
288
289 if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
290 ret:
291 AsnUnlinkType(orig); /* unlink local tree */
292 return lsp;
293 erret:
294 lsp = LinkSetFree(lsp);
295 goto ret;
296 }
297
298 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |