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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
|
/* objres.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: objres.c
*
* Author: James Ostell
*
* Version Creation Date: 4/1/91
*
* $Revision: 6.6 $
*
* File Description: Object manager for module NCBI-Seqres
*
* Modifications:
* --------------------------------------------------------------------------
* Date Name Description of modification
* ------- ---------- -----------------------------------------------------
* 05-13-93 Schuler All public functions are now declared LIBCALL.
*
*
* $Log: objres.c,v $
* Revision 6.6 2004/05/12 20:41:56 kans
* set aip->io_failure in several erret blocks for compatibility of old object loaders with new ones
*
* Revision 6.5 2004/04/01 13:43:08 lavr
* Spell "occurred", "occurrence", and "occurring"
*
* Revision 6.4 1998/12/09 20:37:52 kans
* changed compl to compr to avoid new c++ symbol collision
*
* Revision 6.3 1998/08/26 17:43:19 kans
* fixed -v -fd warnings in label functions
*
* Revision 6.2 1998/08/24 18:28:08 kans
* removed solaris -v -fd warnings
*
* Revision 6.1 1997/10/10 17:50:49 bazhin
* Fixed bug related to freing memory in SeqGraphFree() function.
*
* Revision 6.0 1997/08/25 18:50:38 madden
* Revision changed to 6.0
*
* Revision 4.2 1997/06/19 18:41:52 vakatov
* [WIN32,MSVC++] Adopted for the "NCBIOBJ.LIB" DLL'ization
*
* Revision 4.1 1996/12/09 16:57:20 kans
* fixed SeqGraphAsnRead to look for both end-structs
*
* Revision 4.0 1995/07/26 13:48:06 ostell
* force revision to 4.0
*
* Revision 3.5 1995/05/15 21:22:00 ostell
* added Log line
*
*
*
* ==========================================================================
*/
#include <objres.h> /* the SeqRes interface */
#include <asnres.h> /* the AsnTool header */
#include <objmgr.h>
/*****************************************************************************
*
* SeqGraph ObjMgr Routines
*
*****************************************************************************/
static CharPtr graphtypename = "SeqGraph";
static Pointer LIBCALLBACK SeqGraphNewFunc (void)
{
return (Pointer) SeqGraphNew();
}
static Pointer LIBCALLBACK SeqGraphFreeFunc (Pointer data)
{
return (Pointer) SeqGraphFree ((SeqGraphPtr) data);
}
static Boolean LIBCALLBACK SeqGraphAsnWriteFunc (Pointer data, AsnIoPtr aip, AsnTypePtr atp)
{
return SeqGraphAsnWrite((SeqGraphPtr)data, aip, atp);
}
static Pointer LIBCALLBACK SeqGraphAsnReadFunc (AsnIoPtr aip, AsnTypePtr atp)
{
return (Pointer) SeqGraphAsnRead (aip, atp);
}
static Int2 LIBCALLBACK SeqGraphLabelFunc ( Pointer data, CharPtr buffer, Int2 buflen, Uint1 content)
{
return SeqGraphLabel((SeqGraphPtr)data, buffer, buflen, content);
}
NLM_EXTERN Int2 LIBCALL SeqGraphLabel (SeqGraphPtr sgp, CharPtr buffer, Int2 buflen, Uint1 content)
{
Int2 rsult = 0;
if ((sgp == NULL) || (buflen < 1))
return 0;
switch (content)
{
case OM_LABEL_BOTH:
case OM_LABEL_CONTENT:
case OM_LABEL_SUMMARY:
case OM_LABEL_TYPE:
default:
rsult = LabelCopy(buffer, graphtypename, buflen);
}
return rsult;
}
static Boolean loaded = FALSE;
/*****************************************************************************
*
* SeqResAsnLoad()
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL SeqResAsnLoad (void)
{
if (loaded)
return TRUE;
loaded = TRUE;
if (! SeqLocAsnLoad())
{
loaded = FALSE;
return FALSE;
}
if (! AsnLoad())
{
loaded = FALSE;
return FALSE;
}
ObjMgrTypeLoad(OBJ_SEQGRAPH, "Seq-graph", graphtypename, "Sequence Graph",
SEQ_GRAPH, SeqGraphNewFunc, SeqGraphAsnReadFunc, SeqGraphAsnWriteFunc,
SeqGraphFreeFunc, SeqGraphLabelFunc, NULL);
return TRUE;
}
/*****************************************************************************
*
* SeqRes Routines
*
*****************************************************************************/
/*****************************************************************************
*
* SeqGraph
*
*****************************************************************************/
/*****************************************************************************
*
* SeqGraphNew()
*
*****************************************************************************/
NLM_EXTERN SeqGraphPtr LIBCALL SeqGraphNew (void)
{
return (SeqGraphPtr)MemNew(sizeof(SeqGraph));
}
/*****************************************************************************
*
* SeqGraphFree(sgp)
* Frees one SeqGraph and associated data
*
*****************************************************************************/
NLM_EXTERN SeqGraphPtr LIBCALL SeqGraphFree (SeqGraphPtr sgp)
{
if (sgp == NULL)
return sgp;
MemFree(sgp->title);
MemFree(sgp->comment);
SeqLocFree(sgp->loc);
MemFree(sgp->titlex);
MemFree(sgp->titley);
if (sgp->flags[2] != 3) /* real or int */
MemFree(sgp->values);
else /* byte */
BSFree((ByteStorePtr)(sgp->values));
ObjMgrDelete(OBJ_SEQGRAPH, (Pointer)sgp);
return (SeqGraphPtr)MemFree(sgp);
}
/*****************************************************************************
*
* SeqGraphAsnWrite(sgp, aip, atp)
* atp is the current type (if identifier of a parent struct)
* if atp == NULL, then assumes it stands alone (SeqGraph ::=)
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL SeqGraphAsnWrite (SeqGraphPtr sgp, AsnIoPtr aip, AsnTypePtr orig)
{
DataVal av;
AsnTypePtr atp;
Int4 numval, i;
FloatHiPtr rp;
Int4Ptr ip;
Boolean retval = FALSE;
if (! loaded)
{
if (! SeqResAsnLoad())
return FALSE;
}
if (aip == NULL)
return FALSE;
atp = AsnLinkType(orig, SEQ_GRAPH); /* link local tree */
if (atp == NULL) return FALSE;
if (sgp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
if (! AsnOpenStruct(aip, atp, (Pointer)sgp)) goto erret;
if (sgp->title != NULL)
{
av.ptrvalue = sgp->title;
if (! AsnWrite(aip, SEQ_GRAPH_title, &av)) goto erret;
}
if (sgp->comment != NULL)
{
av.ptrvalue = sgp->comment;
if (! AsnWrite(aip, SEQ_GRAPH_comment, &av)) goto erret;
}
if (! SeqLocAsnWrite(sgp->loc, aip, SEQ_GRAPH_loc)) goto erret;
if (sgp->titlex != NULL)
{
av.ptrvalue = sgp->titlex;
if (! AsnWrite(aip, SEQ_GRAPH_title_x, &av)) goto erret;
}
if (sgp->titley != NULL)
{
av.ptrvalue = sgp->titley;
if (! AsnWrite(aip,SEQ_GRAPH_title_y, &av)) goto erret;
}
if (sgp->flags[0])
{
av.intvalue = sgp->compr;
if (! AsnWrite(aip, SEQ_GRAPH_comp, &av)) goto erret;
}
if (sgp->flags[1])
{
av.realvalue = sgp->a;
if (! AsnWrite(aip, SEQ_GRAPH_a, &av)) goto erret;
av.realvalue = sgp->b;
if (! AsnWrite(aip, SEQ_GRAPH_b, &av)) goto erret;
}
numval = sgp->numval;
av.intvalue = numval;
if (! AsnWrite(aip, SEQ_GRAPH_numval, &av)) goto erret;
av.ptrvalue = (Pointer)sgp;
if (! AsnWriteChoice(aip, SEQ_GRAPH_graph, (Int2)sgp->flags[2], &av)) goto erret;
if (sgp->flags[2] == 1) /* real graph */
{
rp = (FloatHiPtr) sgp->values;
if (! AsnOpenStruct(aip, SEQ_GRAPH_graph_real, (Pointer)sgp)) goto erret;
if (! AsnWrite(aip, REAL_GRAPH_max, &sgp->max)) goto erret;
if (! AsnWrite(aip, REAL_GRAPH_min, &sgp->min)) goto erret;
if (! AsnWrite(aip, REAL_GRAPH_axis, &sgp->axis)) goto erret;
if (! AsnOpenStruct(aip, REAL_GRAPH_values, sgp->values)) goto erret;
for (i = 0; i < numval; i++)
{
av.realvalue = rp[i];
if (! AsnWrite(aip, REAL_GRAPH_values_E, &av)) goto erret;
}
if (! AsnCloseStruct(aip, REAL_GRAPH_values, sgp->values)) goto erret;
if (! AsnCloseStruct(aip, SEQ_GRAPH_graph_real, (Pointer)sgp)) goto erret;
}
else if (sgp->flags[2] == 2) /* int graph */
{
ip = (Int4Ptr) sgp->values;
if (! AsnOpenStruct(aip, SEQ_GRAPH_graph_int, (Pointer)sgp)) goto erret;
if (! AsnWrite(aip, INT_GRAPH_max, &sgp->max)) goto erret;
if (! AsnWrite(aip, INT_GRAPH_min, &sgp->min)) goto erret;
if (! AsnWrite(aip, INT_GRAPH_axis, &sgp->axis)) goto erret;
if (! AsnOpenStruct(aip, INT_GRAPH_values, sgp->values)) goto erret;
for (i = 0; i < numval; i++)
{
av.intvalue = ip[i];
if (! AsnWrite(aip, INT_GRAPH_values_E, &av)) goto erret;
}
if (! AsnCloseStruct(aip, INT_GRAPH_values, sgp->values)) goto erret;
if (! AsnCloseStruct(aip, SEQ_GRAPH_graph_int, (Pointer)sgp)) goto erret;
}
else if (sgp->flags[2] == 3) /* byte graph */
{
if (! AsnOpenStruct(aip, SEQ_GRAPH_graph_byte, (Pointer)sgp)) goto erret;
if (! AsnWrite(aip, BYTE_GRAPH_max, &sgp->max)) goto erret;
if (! AsnWrite(aip, BYTE_GRAPH_min, &sgp->min)) goto erret;
if (! AsnWrite(aip, BYTE_GRAPH_axis, &sgp->axis)) goto erret;
av.ptrvalue = sgp->values; /* write the byte store */
if (! AsnWrite(aip, BYTE_GRAPH_values, &av)) goto erret;
if (! AsnCloseStruct(aip, SEQ_GRAPH_graph_byte, (Pointer)sgp)) goto erret;
}
if (! AsnCloseStruct(aip, atp, (Pointer)sgp)) goto erret;
retval = TRUE;
erret:
AsnUnlinkType(orig); /* unlink local tree */
return retval;
}
/*****************************************************************************
*
* SeqGraphAsnRead(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 SeqGraphPtr LIBCALL SeqGraphAsnRead (AsnIoPtr aip, AsnTypePtr orig)
{
DataVal av;
AsnTypePtr atp;
SeqGraphPtr sgp=NULL;
Int4 numval, i;
Int4Ptr ip;
FloatHiPtr rp;
if (! loaded)
{
if (! SeqResAsnLoad())
return sgp;
}
if (aip == NULL)
return sgp;
if (orig == NULL) /* SeqGraph ::= (self contained) */
atp = AsnReadId(aip, amp, SEQ_GRAPH);
else
atp = AsnLinkType(orig, SEQ_GRAPH); /* link in local tree */
if (atp == NULL) return sgp;
sgp = SeqGraphNew();
if (sgp == NULL) goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* get the values */
if (atp == SEQ_GRAPH_title)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
sgp->title = (CharPtr)av.ptrvalue;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
}
if (atp == SEQ_GRAPH_comment)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
sgp->comment = (CharPtr)av.ptrvalue;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
}
sgp->loc = SeqLocAsnRead(aip, atp);
if (sgp->loc == NULL) goto erret;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (atp == SEQ_GRAPH_title_x)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
sgp->titlex = (CharPtr)av.ptrvalue;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
}
if (atp ==SEQ_GRAPH_title_y)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
sgp->titley = (CharPtr)av.ptrvalue;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
}
if (atp == SEQ_GRAPH_comp)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
sgp->compr = av.intvalue;
sgp->flags[0] = 1;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
}
if (atp == SEQ_GRAPH_a)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
sgp->a = av.realvalue;
sgp->b = 0.0; /* set a default */
sgp->flags[1] = 1;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
}
if (atp == SEQ_GRAPH_b)
{
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
sgp->b = av.realvalue;
if (! sgp->flags[1]) /* no a was read */
{
sgp->flags[1] = 1;
sgp->a = 1.0; /* set default */
}
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
}
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* numval */
numval = av.intvalue;
sgp->numval = numval;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the CHOICE */
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* find what kind of choice */
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
if (atp == SEQ_GRAPH_graph_real)
sgp->flags[2] = 1;
else if (atp == SEQ_GRAPH_graph_int)
sgp->flags[2] = 2;
else if (atp == SEQ_GRAPH_graph_byte)
sgp->flags[2] = 3;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &sgp->max) <= 0) goto erret;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &sgp->min) <= 0) goto erret;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &sgp->axis) <= 0) goto erret;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
if (atp == REAL_GRAPH_values)
{
sgp->values = (FloatHiPtr)MemNew((size_t)(sizeof(FloatHi) * numval));
if (sgp->values == NULL) goto erret;
rp = (FloatHiPtr)sgp->values;
for (i = 0; i < numval; i++)
{
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (atp != REAL_GRAPH_values_E)
{
ErrPost(CTX_NCBIOBJ,1, "Too few real values in Seq-graph");
goto erret;
}
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
rp[i] = av.realvalue;
}
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF */
}
else if (atp == INT_GRAPH_values)
{
sgp->values = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * numval));
ip = (Int4Ptr)sgp->values;
if (ip == NULL) goto erret;
for (i = 0; i < numval; i++)
{
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (atp != INT_GRAPH_values_E)
{
ErrPost(CTX_NCBIOBJ,1, "Too few integer values in Seq-graph");
goto erret;
}
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
ip[i] = av.intvalue;
}
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end SEQ OF */
}
else if (atp == BYTE_GRAPH_values)
sgp->values = av.ptrvalue; /* already in a bytestore */
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* end struct of Seq-graph.graph */
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; /* end struct of Seq-graph */
if (AsnReadVal(aip, atp, &av) <= 0) goto erret;
ret:
AsnUnlinkType(orig); /* unlink local tree */
return sgp;
erret:
aip->io_failure = TRUE;
sgp = SeqGraphFree(sgp);
goto ret;
}
/*****************************************************************************
*
* SeqGraphSetAsnWrite(sgp, aip, set, element)
*
*****************************************************************************/
NLM_EXTERN Boolean LIBCALL SeqGraphSetAsnWrite (SeqGraphPtr sgp, AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
{
AsnTypePtr atp;
SeqGraphPtr oldsgp;
Boolean retval = FALSE;
if (! loaded)
{
if (! SeqResAsnLoad())
return FALSE;
}
if (aip == NULL)
return FALSE;
atp = AsnLinkType(element, SEQ_GRAPH); /* link local tree */
if (atp == NULL) return FALSE;
oldsgp = sgp;
if (! AsnOpenStruct(aip, set, (Pointer)oldsgp)) goto erret; /* set of */
while (sgp != NULL)
{
if (! SeqGraphAsnWrite(sgp, aip, atp)) goto erret;
sgp = sgp->next;
}
if (! AsnCloseStruct(aip, set, (Pointer)oldsgp)) goto erret;
retval = TRUE;
erret:
AsnUnlinkType(element); /* unlink local tree */
return retval;
}
/*****************************************************************************
*
* SeqGraphSetAsnRead(aip, atp)
*
*****************************************************************************/
NLM_EXTERN SeqGraphPtr LIBCALL SeqGraphSetAsnRead (AsnIoPtr aip, AsnTypePtr set, AsnTypePtr element)
{
DataVal av;
AsnTypePtr atp;
SeqGraphPtr sgp, first = NULL, curr = NULL;
if (! loaded)
{
if (! SeqResAsnLoad())
return first;
}
if (aip == NULL)
return first;
AsnLinkType(element, SEQ_GRAPH); /* link in local tree */
atp = set;
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the start struct */
while ((atp = AsnReadId(aip, amp, atp)) == element) /* get the values */
{
sgp = SeqGraphAsnRead(aip, atp);
if (sgp == NULL) goto erret;
if (first == NULL)
first = sgp;
else
curr->next = sgp;
curr = sgp;
}
if (atp == NULL) goto erret;
if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */
ret:
AsnUnlinkType(element); /* unlink local tree */
return first;
erret:
while (first != NULL)
{
curr = first;
first = curr->next;
SeqGraphFree(curr);
}
goto ret;
}
|