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 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
|
/* @source enstable ***********************************************************
**
** Ensembl Table functions
**
** @author Copyright (C) 1999 Ensembl Developers
** @author Copyright (C) 2006 Michael K. Schuster
** @version $Revision: 1.34 $
** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
** @modified $Date: 2013/02/17 13:08:58 $ by $Author: mks $
** @@
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
**
******************************************************************************/
/* ========================================================================= */
/* ============================= include files ============================= */
/* ========================================================================= */
#include "enstable.h"
/* ========================================================================= */
/* =============================== constants =============================== */
/* ========================================================================= */
/* ========================================================================= */
/* =========================== global variables ============================ */
/* ========================================================================= */
/* ========================================================================= */
/* ============================= private data ============================== */
/* ========================================================================= */
/* ========================================================================= */
/* =========================== private constants =========================== */
/* ========================================================================= */
/* ========================================================================= */
/* =========================== private variables =========================== */
/* ========================================================================= */
/* ========================================================================= */
/* =========================== private functions =========================== */
/* ========================================================================= */
static void tablestrToList(void **Pkey,
void **Pvalue,
void *cl);
static void tableuintToList(void **Pkey,
void **Pvalue,
void *cl);
static AjBool tableuintliststrMatch(AjPStr *Pstr, void *cl);
/* ========================================================================= */
/* ======================= All functions by section ======================== */
/* ========================================================================= */
/* @filesection enstable ******************************************************
**
** @nam1rule ens Function belongs to the Ensembl library
**
******************************************************************************/
/* @datasection [AjPTable] AJAX Table *****************************************
**
** @nam2rule Table Functions for manipulating AJAX Table objects
**
******************************************************************************/
/* @datasection [AjPTable] AJAX Table *****************************************
**
** @nam2rule Tablestr Functions for manipulating AJAX Table objects of
** AJAX String key data and
** generic value data
**
******************************************************************************/
/* @section cast **************************************************************
**
** Cast AJAX Table objects into AJAX List objects and vice versa.
**
** @fdata [AjPTable]
**
** @nam3rule From Convert from an AJAX object
** @nam3rule To Convert to an AJAX object
** @nam4rule List Convert between an AJAX List
**
** @argrule * table [AjPTable] AJAX Table
** @argrule FromList FobjectGetKey [AjPStr function]
** Get AJAX String key function address
** @argrule * list [AjPList] AJAX List
**
** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
**
** @fcategory new
******************************************************************************/
/* @func ensTablestrFromList **************************************************
**
** Moves generic objects from an AJAX List into an AJAX Table of
** AJAX String key data and generic value data.
**
** Empty nodes of the AJAX List are ignored.
**
** This function relies on ajTablePutClean and expects keydel and valdel
** functions set in the AJAX Table to delete duplicate key and value data.
** The last key and value pair will win.
**
** @param [u] table [AjPTable] AJAX Table of AJAX unsigned integer key data
** @param [f] FobjectGetKey [AjPStr function]
** Get AJAX String key function address
** @param [u] list [AjPList] AJAX List
**
** @return [AjBool] ajTrue upon success, ajFalse otherwise
**
** @release 6.6.0
** @@
******************************************************************************/
AjBool ensTablestrFromList(
AjPTable table,
AjPStr (*FobjectGetKey) (const void *object),
AjPList list)
{
void *object = NULL;
AjPStr key = NULL;
if (!table)
return ajFalse;
if (!FobjectGetKey)
return ajFalse;
if (!list)
return ajFalse;
while (ajListPop(list, (void **) &object))
{
if (!object)
continue;
key = ajStrNewS((*FobjectGetKey) (object));
ajTablePutClean(table,
(void *) key,
(void *) object,
(void (*)(void **)) NULL,
(void (*)(void **)) NULL);
}
return ajTrue;
}
/* @funcstatic tablestrToList *************************************************
**
** An ajTableMapDel "apply" function to clear an AJAX Table of
** AJAX String key data and generic value data.
**
** This function deletes the AJAX String key data
** and moves the generic value data onto the AJAX List.
**
** @param [d] Pkey [void**] AJAX String key data address
** @param [d] Pvalue [void**] Generic value data address
** @param [u] cl [void*] AJAX List, passed in from ajTableMapDel
** @see ajTableMapDel
**
** @return [void]
**
** @release 6.6.0
** @@
******************************************************************************/
static void tablestrToList(void **Pkey,
void **Pvalue,
void *cl)
{
if (!Pkey)
return;
if (!Pvalue)
return;
if (!cl)
return;
ajStrDel((AjPStr *) Pkey);
ajListPushAppend(cl, *Pvalue);
*Pvalue = NULL;
return;
}
/* @func ensTablestrToList ****************************************************
**
** Moves generic value data from an AJAX Table of
** AJAX String key data and
** generic value data onto an AJAX List.
**
** @param [u] table [AjPTable] AJAX Table
** @param [u] list [AjPList] AJAX List
**
** @return [AjBool] ajTrue upon success, ajFalse otherwise
**
** @release 6.6.0
** @@
**
******************************************************************************/
AjBool ensTablestrToList(AjPTable table, AjPList list)
{
if (!table)
return ajFalse;
if (!list)
return ajFalse;
ajTableMapDel(table, &tablestrToList, (void *) list);
return ajTrue;
}
/* @datasection [AjPTable] AJAX Table *****************************************
**
** @nam2rule Tableuint Functions for manipulating AJAX Table objects of
** AJAX unsigned integer key data and
** generic value data
**
******************************************************************************/
/* @section cast **************************************************************
**
** Cast AJAX Table objects into AJAX List objects and vice versa.
**
** @fdata [AjPTable]
**
** @nam3rule From Convert from an AJAX object
** @nam3rule To Convert to an AJAX object
** @nam4rule List Convert between an AJAX List
**
** @argrule * table [AjPTable] AJAX Table
** @argrule FromList FobjectGetIdentifier [ajuint function]
** Get AJAX unsigned integer key function address
** @argrule * list [AjPList] AJAX List
**
** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
**
** @fcategory new
******************************************************************************/
/* @func ensTableuintFromList *************************************************
**
** Moves data from an AJAX List into an AJAX Table of
** AJAX unsigned integer key data and generic value data.
**
** Empty nodes of the AJAX List are ignored.
**
** This function relies on ajTablePutClean and expects keydel and valdel
** functions set in the AJAX Table to delete duplicate key and value data.
** The last key and value pair will win.
**
** @param [u] table [AjPTable]
** AJAX Table of AJAX unsigned integer key data and generic value data
** @param [f] FobjectGetIdentifier [ajuint function]
** Get AJAX unsigned integer key function address
** @param [u] list [AjPList] AJAX List
**
** @return [AjBool] ajTrue upon success, ajFalse otherwise
**
** @release 6.6.0
** @@
******************************************************************************/
AjBool ensTableuintFromList(
AjPTable table,
ajuint (*FobjectGetIdentifier) (const void *object),
AjPList list)
{
void *object = NULL;
ajuint *Pidentifier = NULL;
if (!table)
return ajFalse;
if (!FobjectGetIdentifier)
return ajFalse;
if (!list)
return ajFalse;
while (ajListPop(list, (void **) &object))
{
if (!object)
continue;
AJNEW0(Pidentifier);
*Pidentifier = (*FobjectGetIdentifier) (object);
ajTablePutClean(table,
(void *) Pidentifier,
(void *) object,
(void (*)(void **)) NULL,
(void (*)(void **)) NULL);
}
return ajTrue;
}
/* @funcstatic tableuintToList ************************************************
**
** An ajTableMapDel "apply" function to clear an AJAX Table of
** AJAX unsigned integer key data and generic value data.
**
** This function deletes the AJAX unsigned integer key data
** and moves the generic value data onto the AJAX List.
**
** @param [d] Pkey [void**] AJAX unsigned integer key data address
** @param [d] Pvalue [void**] Generic value data address
** @param [u] cl [void*] AJAX List, passed in from ajTableMapDel
** @see ajTableMapDel
**
** @return [void]
**
** @release 6.6.0
** @@
******************************************************************************/
static void tableuintToList(void **Pkey,
void **Pvalue,
void *cl)
{
if (!Pkey)
return;
if (!Pvalue)
return;
if (!cl)
return;
ajMemFree(Pkey);
ajListPushAppend(cl, *Pvalue);
*Pvalue = NULL;
return;
}
/* @func ensTableuintToList ***************************************************
**
** Moves generic value data from an AJAX Table of
** AJAX unsigned integer key data and
** generic value data onto an AJAX List.
**
** @param [u] table [AjPTable]
** AJAX Table od AJAX unsigned integer key data and generic value data
** @param [u] list [AjPList] AJAX List
**
** @return [AjBool] ajTrue upon success, ajFalse otherwise
**
** @release 6.6.0
** @@
**
******************************************************************************/
AjBool ensTableuintToList(AjPTable table, AjPList list)
{
if (!table)
return ajFalse;
if (!list)
return ajFalse;
ajTableMapDel(table, &tableuintToList, (void *) list);
return ajTrue;
}
/* @datasection [AjPTable] AJAX Table *****************************************
**
** @nam2rule Tableuintliststr Functions for manipulating AJAX Table objects of
** AJAX unsigned integer key data and
** AJAX String-List value data
**
******************************************************************************/
/* @section constructors ******************************************************
**
** These constructors return a new AJAX Table by pointer.
** It is the responsibility of the user to first destroy any previous
** Table. The target pointer does not need to be initialised to
** NULL, but it is good programming practice to do so anyway.
**
** @fdata [AjPTable]
**
** @nam3rule New Constructor
** @nam4rule Len Constructor with an initial length
**
** @argrule Len size [ajuint] Number of key-value pairs
**
** @valrule * [AjPTable] AJAX Table or NULL
**
** @fcategory new
******************************************************************************/
/* @func ensTableuintliststrNewLen ********************************************
**
** Creates, initialises, and returns a new, empty AJAX Table that can hold an
** arbitrary number of key-value pairs.
** The AJAX Table is initialised with comparison, hash and key deletion
** functions suitable for AJAX unsigned integer keys.
**
** @param [r] size [ajuint] Number of key-value pairs
**
** @return [AjPTable] AJAX Table or NULL
**
** @release 6.4.0
** @@
**
******************************************************************************/
AjPTable ensTableuintliststrNewLen(ajuint size)
{
AjPTable table = NULL;
table = ajTableuintNew(size);
ajTableSetDestroyvalue(table, (void (*)(void **)) &ajListstrFreeData);
return table;
}
/* @section destructors *******************************************************
**
** Destruction destroys all internal data structures and frees the memory
** allocated for an AJAX Table object.
**
** @fdata [AjPTable]
**
** @nam3rule Clear Clear
** @nam3rule Delete Destroy (free) an AJAX Table of
** AJAX unsigned integer key data and
** AJAX String-List value data
**
** @argrule Clear table [AjPTable] AJAX Table
** @argrule Delete Ptable [AjPTable*] AJAX Table address
**
** @valrule * [void]
**
** @fcategory delete
******************************************************************************/
/* @func ensTableuintliststrClear *********************************************
**
** Utility function to clear an AJAX Table of
** AJAX unsigned integer key data and
** AJAX String-List value data.
**
** @param [u] table [AjPTable] AJAX Table
**
** @return [void]
**
** @release 6.4.0
** @@
******************************************************************************/
void ensTableuintliststrClear(AjPTable table)
{
ajTableClearDelete(table);
return;
}
/* @func ensTableuintliststrDelete ********************************************
**
** Utility function to clear and delete an AJAX Table of
** AJAX unsigned integer key data and
** AJAX String-List value data.
**
** @param [d] Ptable [AjPTable*] AJAX Table address
**
** @return [void]
**
** @release 6.4.0
** @@
******************************************************************************/
void ensTableuintliststrDelete(AjPTable *Ptable)
{
ajTableDel(Ptable);
return;
}
/* @section register **********************************************************
**
** Registers AJAX String objects in an AJAX Table of
** AJAX unsigned integer key data and
** AJAX String-List value data.
**
** @fdata [AjPTable]
**
** @nam3rule Register Register an AJAX String
**
** @argrule Register table [AjPTable] AJAX Table
** @argrule Register identifier [ajuint] AJAX unsigned integer identifier
** @argrule Register str [AjPStr] AJAX String
**
** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
**
** @fcategory use
******************************************************************************/
/* @funcstatic tableuintliststrMatch ******************************************
**
** An ajListstrMapfind "apply" function to match AJAX String objects in an
** AJAX String-List.
**
** @param [u] Pstr [AjPStr*] AJAX String address
** @param [u] cl [void*] AJAX String
** @see ajListstrMapfind
**
** @return [AjBool] ajTrue: A particular AJAX String has already been indexed.
** ajFalse: A particular AJAX String has not been indexed
** before, but has been added now.
**
** @release 6.4.0
** @@
******************************************************************************/
static AjBool tableuintliststrMatch(AjPStr *Pstr, void *cl)
{
if (!Pstr)
return ajFalse;
if (!cl)
return ajFalse;
return ajStrMatchS(*Pstr, (AjPStr) cl);
}
/* @func ensTableuintliststrRegister ******************************************
**
** For an AJAX Table of AJAX unsigned integer key data and AJAX String-List
** value data check, whether an AJAX String has already been indexed for a
** particular AJAX unsigned integer.
**
** @param [u] table [AjPTable] AJAX Table
** @param [rN] identifier [ajuint] AJAX unsigned integer identifier
** @param [u] str [AjPStr] AJAX String
**
** @return [AjBool] ajTrue: A particular AJAX String has already been indexed.
** ajFalse: A particular AJAX String has not been indexed
** before, but has been added now.
**
** @release 6.4.0
** @@
******************************************************************************/
AjBool ensTableuintliststrRegister(AjPTable table,
ajuint identifier,
AjPStr str)
{
ajuint *Pidentifier = NULL;
AjPList list = NULL;
if (ajDebugTest("ensTableuintliststrRegister"))
ajDebug("ensTableuintliststrRegister\n"
" table %p\n"
" identifier %u\n"
" str '%S'\n",
table,
identifier,
str);
if (!table)
return ajFalse;
if (!str)
return ajFalse;
list = (AjPList) ajTableFetchmodV(table, (const void *) &identifier);
if (list)
{
if (ajListstrMapfind(list, &tableuintliststrMatch, (void *) str))
return ajTrue;
else
{
ajListstrPushAppend(list, ajStrNewS(str));
return ajFalse;
}
}
else
{
AJNEW0(Pidentifier);
*Pidentifier = identifier;
list = ajListstrNew();
ajTablePut(table, (void *) Pidentifier, (void *) list);
ajListstrPushAppend(list, ajStrNewS(str));
return ajFalse;
}
}
|