1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
/* objacces.c
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government have not placed any restriction on its use or reproduction.
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* Please cite the author in any work or product based on this material.
*
* ===========================================================================
*
* File Name: objacces.c
*
* Author: James Ostell
*
* Version Creation Date: 1/1/91
*
* $Revision: 6.1 $
*
* File Description: Object manager for module NCBI-Access
*
* Modifications:
* --------------------------------------------------------------------------
* Date Name Description of modification
* ------- ---------- -----------------------------------------------------
* 05-13-93 Schuler All public functions are now declared LIBCALL.
*
* $Log: objacces.c,v $
* Revision 6.1 2004/04/01 13:43:07 lavr
* Spell "occurred", "occurrence", and "occurring"
*
* Revision 6.0 1997/08/25 18:49:05 madden
* Revision changed to 6.0
*
* Revision 4.1 1997/06/19 18:40:33 vakatov
* [WIN32,MSVC++] Adopted for the "NCBIOBJ.LIB" DLL'ization
*
* Revision 4.0 1995/07/26 13:48:06 ostell
* force revision to 4.0
*
* Revision 3.1 1995/05/15 21:22:00 ostell
* added Log line
*
*
*
* ==========================================================================
*/
#include <asnacces.h> /* the AsnTool header */
#include <objacces.h> /* the general objects interface */
static Boolean loaded = FALSE;
/*****************************************************************************
*
* AccessAsnLoad()
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL AccessAsnLoad (void)
{
if (loaded)
return TRUE;
if (AsnLoad())
loaded = TRUE;
return loaded;
}
/*****************************************************************************
*
* LinkSet Routines
*
*****************************************************************************/
/*****************************************************************************
*
* LinkSetNew()
*
*****************************************************************************/
NLM_EXTERN LinkSetPtr LIBCALL LinkSetNew (void)
{
return (LinkSetPtr)MemNew(sizeof(LinkSet));
}
/*****************************************************************************
*
* LinkSetFree(lsp)
*
*****************************************************************************/
NLM_EXTERN LinkSetPtr LIBCALL LinkSetFree (LinkSetPtr lsp)
{
if (lsp == NULL)
return (LinkSetPtr)NULL;
MemFree(lsp->uids);
MemFree(lsp->weights);
return (LinkSetPtr)MemFree(lsp);
}
/*****************************************************************************
*
* LinkSetAsnWrite(lsp, aip, atp)
* atp is the current type (if identifier of a parent struct)
* if atp == NULL, then assumes it stands alone (LinkSet ::=)
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL LinkSetAsnWrite (LinkSetPtr lsp, AsnIoPtr aip, AsnTypePtr orig)
{
DataVal av;
AsnTypePtr atp;
Int4 num, i;
Int4Ptr ptr;
Boolean retval = FALSE;
if (! loaded)
{
if (! AccessAsnLoad())
return FALSE;
}
if (aip == NULL)
return FALSE;
atp = AsnLinkType(orig, LINK_SET); /* link local tree */
if (atp == NULL)
return FALSE;
if (lsp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
if (! AsnOpenStruct(aip, atp, (Pointer)lsp))
goto erret;
num = lsp->num;
av.intvalue = num;
if (! AsnWrite(aip, LINK_SET_num, &av))
goto erret;
ptr = lsp->uids;
if (! AsnOpenStruct(aip, LINK_SET_uids, (Pointer)lsp->uids))
goto erret;
for (i = 0; i < num; i++)
{
av.intvalue = ptr[i];
if (! AsnWrite(aip, LINK_SET_uids_E, &av))
goto erret;
}
if (! AsnCloseStruct(aip, LINK_SET_uids, (Pointer)lsp->uids))
goto erret;
if (lsp->weights != NULL)
{
ptr = lsp->weights;
if (! AsnOpenStruct(aip, LINK_SET_weights, (Pointer)lsp->weights))
goto erret;
for (i = 0; i < num; i++)
{
av.intvalue = ptr[i];
if (! AsnWrite(aip, LINK_SET_weights_E, &av))
goto erret;
}
if (! AsnCloseStruct(aip, LINK_SET_weights, (Pointer)lsp->weights))
goto erret;
}
if (! AsnCloseStruct(aip, atp, (Pointer)lsp))
goto erret;
retval = TRUE;
erret:
AsnUnlinkType(orig); /* unlink local tree */
return retval;
}
/*****************************************************************************
*
* LinkSetAsnRead(aip, atp)
* atp is the current type (if identifier of a parent struct)
* assumption is readIdent has occurred
* if atp == NULL, then assumes it stands alone and read ident
* has not occurred.
*
*****************************************************************************/
NLM_EXTERN LinkSetPtr LIBCALL LinkSetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
{
DataVal av;
AsnTypePtr atp;
LinkSetPtr lsp=NULL;
Int4 num, i;
Int4Ptr ptr;
if (! loaded)
{
if (! AccessAsnLoad())
return lsp;
}
if (aip == NULL)
return lsp;
if (orig == NULL) /* LinkSet ::= (self contained) */
atp = AsnReadId(aip, amp, LINK_SET);
else
atp = AsnLinkType(orig, LINK_SET); /* link in local tree */
if (atp == NULL)
return lsp;
lsp = LinkSetNew();
if (lsp == NULL)
goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
goto erret;
atp = AsnReadId(aip, amp, atp); /* find the num */
if (atp == NULL)
goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
goto erret;
num = av.intvalue;
lsp->num = num;
atp = AsnReadId(aip, amp, atp); /* start seq of uids */
if (atp == NULL)
goto erret;
if (AsnReadVal(aip, atp, &av) <= 0)
goto erret;
ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1))); /* 0 sentinel at end */
if (ptr == NULL)
goto erret;
lsp->uids = ptr;
i = 0;
while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_uids_E)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
ptr[i] = av.intvalue;
i++;
if (i > num)
break;
}
if (atp == NULL)
goto erret;
if (i != num)
{
ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of uids in Link-set. line %ld",
aip->linenumber);
goto erret;
}
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end seq of */
atp = AsnReadId(aip, amp, atp);
if (atp == NULL)
goto erret;
if (atp == LINK_SET_weights)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1))); /* 0 sentinel at end */
if (ptr == NULL)
goto erret;
lsp->weights = ptr;
i = 0;
while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_weights_E)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
ptr[i] = av.intvalue;
i++;
if (i > num)
break;
}
if (atp == NULL)
goto erret;
if (i != num)
{
ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of weights in Link-set. line %ld",
aip->linenumber);
goto erret;
}
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end seq of */
if ((atp = AsnReadId(aip, amp, atp)) == NULL)
goto erret;
}
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
ret:
AsnUnlinkType(orig); /* unlink local tree */
return lsp;
erret:
lsp = LinkSetFree(lsp);
goto ret;
}
|