/usr/include/tesseract/elst2.h is in libtesseract-dev 3.02.01-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 | /**********************************************************************
* File: elst2.h (Formerly elist2.h)
* Description: Double linked embedded list module include file.
* Author: Phil Cheatle
* Created: Wed Jan 23 11:04:47 GMT 1991
*
* (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** http://www.apache.org/licenses/LICENSE-2.0
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*
**********************************************************************/
#ifndef ELST2_H
#define ELST2_H
#include <stdio.h>
#include "host.h"
#include "serialis.h"
#include "lsterr.h"
class ELIST2_ITERATOR;
/**********************************************************************
DESIGN NOTE
===========
It would probably be possible to implement the ELIST2 classes as derived
classes from ELIST. I haven't done this because:
a) I think it would be harder to understand the code
(Though the problem with not inheriting is that changes to ELIST must be
reflected in ELIST2 and vice versa)
b) Most of the code is inline so:
i) The duplication in source does not affect the run time code size - the
code is copied inline anyway!
ii) The compiler should have a bit less work to do!
**********************************************************************/
/**********************************************************************
* CLASS - ELIST2_LINK
*
* Generic link class for doubly linked lists with embedded links
*
* Note: No destructor - elements are assumed to be destroyed EITHER after
* they have been extracted from a list OR by the ELIST2 destructor which
* walks the list.
**********************************************************************/
class DLLSYM ELIST2_LINK
{
friend class ELIST2_ITERATOR;
friend class ELIST2;
ELIST2_LINK *prev;
ELIST2_LINK *next;
public:
ELIST2_LINK() { //constructor
prev = next = NULL;
}
ELIST2_LINK( //copy constructor
const ELIST2_LINK &) { //dont copy link
prev = next = NULL;
}
void operator= ( //dont copy links
const ELIST2_LINK &) {
prev = next = NULL;
}
};
/**********************************************************************
* CLASS - ELIST2
*
* Generic list class for doubly linked lists with embedded links
**********************************************************************/
class DLLSYM ELIST2
{
friend class ELIST2_ITERATOR;
ELIST2_LINK *last; //End of list
//(Points to head)
ELIST2_LINK *First() { // return first
return last ? last->next : NULL;
}
public:
ELIST2() { //constructor
last = NULL;
}
void internal_clear ( //destroy all links
void (*zapper) (ELIST2_LINK *));
//ptr to zapper functn
bool empty() const { //is list empty?
return !last;
}
bool singleton() const {
return last ? (last == last->next) : false;
}
void shallow_copy( //dangerous!!
ELIST2 *from_list) { //beware destructors!!
last = from_list->last;
}
//ptr to copier functn
void internal_deep_copy (ELIST2_LINK * (*copier) (ELIST2_LINK *),
const ELIST2 * list); //list being copied
void assign_to_sublist( //to this list
ELIST2_ITERATOR *start_it, //from list start
ELIST2_ITERATOR *end_it); //from list end
inT32 length() const; // # elements in list
void sort ( //sort elements
int comparator ( //comparison routine
const void *, const void *));
// Assuming list has been sorted already, insert new_link to
// keep the list sorted according to the same comparison function.
// Comparision function is the same as used by sort, i.e. uses double
// indirection. Time is O(1) to add to beginning or end.
// Time is linear to add pre-sorted items to an empty list.
void add_sorted(int comparator(const void*, const void*),
ELIST2_LINK* new_link);
};
/***********************************************************************
* CLASS - ELIST2_ITERATOR
*
* Generic iterator class for doubly linked lists with embedded links
**********************************************************************/
class DLLSYM ELIST2_ITERATOR
{
friend void ELIST2::assign_to_sublist(ELIST2_ITERATOR *, ELIST2_ITERATOR *);
ELIST2 *list; //List being iterated
ELIST2_LINK *prev; //prev element
ELIST2_LINK *current; //current element
ELIST2_LINK *next; //next element
BOOL8 ex_current_was_last; //current extracted
//was end of list
BOOL8 ex_current_was_cycle_pt; //current extracted
//was cycle point
ELIST2_LINK *cycle_pt; //point we are cycling
//the list to.
BOOL8 started_cycling; //Have we moved off
//the start?
ELIST2_LINK *extract_sublist( //from this current...
ELIST2_ITERATOR *other_it); //to other current
public:
ELIST2_ITERATOR() { //constructor
list = NULL;
} //unassigned list
ELIST2_ITERATOR( //constructor
ELIST2 *list_to_iterate);
void set_to_list( //change list
ELIST2 *list_to_iterate);
void add_after_then_move( //add after current &
ELIST2_LINK *new_link); //move to new
void add_after_stay_put( //add after current &
ELIST2_LINK *new_link); //stay at current
void add_before_then_move( //add before current &
ELIST2_LINK *new_link); //move to new
void add_before_stay_put( //add before current &
ELIST2_LINK *new_link); //stay at current
void add_list_after( //add a list &
ELIST2 *list_to_add); //stay at current
void add_list_before( //add a list &
ELIST2 *list_to_add); //move to it 1st item
ELIST2_LINK *data() { //get current data
#ifndef NDEBUG
if (!current)
NULL_DATA.error ("ELIST2_ITERATOR::data", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::data", ABORT, NULL);
#endif
return current;
}
ELIST2_LINK *data_relative( //get data + or - ...
inT8 offset); //offset from current
ELIST2_LINK *forward(); //move to next element
ELIST2_LINK *backward(); //move to prev element
ELIST2_LINK *extract(); //remove from list
//go to start of list
ELIST2_LINK *move_to_first();
ELIST2_LINK *move_to_last(); //go to end of list
void mark_cycle_pt(); //remember current
BOOL8 empty() { //is list empty?
#ifndef NDEBUG
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::empty", ABORT, NULL);
#endif
return list->empty ();
}
BOOL8 current_extracted() { //current extracted?
return !current;
}
BOOL8 at_first(); //Current is first?
BOOL8 at_last(); //Current is last?
BOOL8 cycled_list(); //Completed a cycle?
void add_to_end( //add at end &
ELIST2_LINK *new_link); //dont move
void exchange( //positions of 2 links
ELIST2_ITERATOR *other_it); //other iterator
inT32 length(); //# elements in list
void sort ( //sort elements
int comparator ( //comparison routine
const void *, const void *));
};
/***********************************************************************
* ELIST2_ITERATOR::set_to_list
*
* (Re-)initialise the iterator to point to the start of the list_to_iterate
* over.
**********************************************************************/
inline void ELIST2_ITERATOR::set_to_list( //change list
ELIST2 *list_to_iterate) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::set_to_list", ABORT, NULL);
if (!list_to_iterate)
BAD_PARAMETER.error ("ELIST2_ITERATOR::set_to_list", ABORT,
"list_to_iterate is NULL");
#endif
list = list_to_iterate;
prev = list->last;
current = list->First ();
next = current ? current->next : NULL;
cycle_pt = NULL; //await explicit set
started_cycling = FALSE;
ex_current_was_last = FALSE;
ex_current_was_cycle_pt = FALSE;
}
/***********************************************************************
* ELIST2_ITERATOR::ELIST2_ITERATOR
*
* CONSTRUCTOR - set iterator to specified list;
**********************************************************************/
inline ELIST2_ITERATOR::ELIST2_ITERATOR(ELIST2 *list_to_iterate) {
set_to_list(list_to_iterate);
}
/***********************************************************************
* ELIST2_ITERATOR::add_after_then_move
*
* Add a new element to the list after the current element and move the
* iterator to the new element.
**********************************************************************/
inline void ELIST2_ITERATOR::add_after_then_move( // element to add
ELIST2_LINK *new_element) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_after_then_move", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
}
else {
new_element->next = next;
next->prev = new_element;
if (current) { //not extracted
new_element->prev = current;
current->next = new_element;
prev = current;
if (current == list->last)
list->last = new_element;
}
else { //current extracted
new_element->prev = prev;
prev->next = new_element;
if (ex_current_was_last)
list->last = new_element;
if (ex_current_was_cycle_pt)
cycle_pt = new_element;
}
}
current = new_element;
}
/***********************************************************************
* ELIST2_ITERATOR::add_after_stay_put
*
* Add a new element to the list after the current element but do not move
* the iterator to the new element.
**********************************************************************/
inline void ELIST2_ITERATOR::add_after_stay_put( // element to add
ELIST2_LINK *new_element) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
ex_current_was_last = FALSE;
current = NULL;
}
else {
new_element->next = next;
next->prev = new_element;
if (current) { //not extracted
new_element->prev = current;
current->next = new_element;
if (prev == current)
prev = new_element;
if (current == list->last)
list->last = new_element;
}
else { //current extracted
new_element->prev = prev;
prev->next = new_element;
if (ex_current_was_last) {
list->last = new_element;
ex_current_was_last = FALSE;
}
}
next = new_element;
}
}
/***********************************************************************
* ELIST2_ITERATOR::add_before_then_move
*
* Add a new element to the list before the current element and move the
* iterator to the new element.
**********************************************************************/
inline void ELIST2_ITERATOR::add_before_then_move( // element to add
ELIST2_LINK *new_element) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_then_move", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
}
else {
prev->next = new_element;
new_element->prev = prev;
if (current) { //not extracted
new_element->next = current;
current->prev = new_element;
next = current;
}
else { //current extracted
new_element->next = next;
next->prev = new_element;
if (ex_current_was_last)
list->last = new_element;
if (ex_current_was_cycle_pt)
cycle_pt = new_element;
}
}
current = new_element;
}
/***********************************************************************
* ELIST2_ITERATOR::add_before_stay_put
*
* Add a new element to the list before the current element but dont move the
* iterator to the new element.
**********************************************************************/
inline void ELIST2_ITERATOR::add_before_stay_put( // element to add
ELIST2_LINK *new_element) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
ex_current_was_last = TRUE;
current = NULL;
}
else {
prev->next = new_element;
new_element->prev = prev;
if (current) { //not extracted
new_element->next = current;
current->prev = new_element;
if (next == current)
next = new_element;
}
else { //current extracted
new_element->next = next;
next->prev = new_element;
if (ex_current_was_last)
list->last = new_element;
}
prev = new_element;
}
}
/***********************************************************************
* ELIST2_ITERATOR::add_list_after
*
* Insert another list to this list after the current element but dont move the
* iterator.
**********************************************************************/
inline void ELIST2_ITERATOR::add_list_after(ELIST2 *list_to_add) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_list_after", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_list_after", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_after", ABORT,
"list_to_add is NULL");
#endif
if (!list_to_add->empty ()) {
if (list->empty ()) {
list->last = list_to_add->last;
prev = list->last;
next = list->First ();
ex_current_was_last = TRUE;
current = NULL;
}
else {
if (current) { //not extracted
current->next = list_to_add->First ();
current->next->prev = current;
if (current == list->last)
list->last = list_to_add->last;
list_to_add->last->next = next;
next->prev = list_to_add->last;
next = current->next;
}
else { //current extracted
prev->next = list_to_add->First ();
prev->next->prev = prev;
if (ex_current_was_last) {
list->last = list_to_add->last;
ex_current_was_last = FALSE;
}
list_to_add->last->next = next;
next->prev = list_to_add->last;
next = prev->next;
}
}
list_to_add->last = NULL;
}
}
/***********************************************************************
* ELIST2_ITERATOR::add_list_before
*
* Insert another list to this list before the current element. Move the
* iterator to the start of the inserted elements
* iterator.
**********************************************************************/
inline void ELIST2_ITERATOR::add_list_before(ELIST2 *list_to_add) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_list_before", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_list_before", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_before", ABORT,
"list_to_add is NULL");
#endif
if (!list_to_add->empty ()) {
if (list->empty ()) {
list->last = list_to_add->last;
prev = list->last;
current = list->First ();
next = current->next;
ex_current_was_last = FALSE;
}
else {
prev->next = list_to_add->First ();
prev->next->prev = prev;
if (current) { //not extracted
list_to_add->last->next = current;
current->prev = list_to_add->last;
}
else { //current extracted
list_to_add->last->next = next;
next->prev = list_to_add->last;
if (ex_current_was_last)
list->last = list_to_add->last;
if (ex_current_was_cycle_pt)
cycle_pt = prev->next;
}
current = prev->next;
next = current->next;
}
list_to_add->last = NULL;
}
}
/***********************************************************************
* ELIST2_ITERATOR::extract
*
* Do extraction by removing current from the list, returning it to the
* caller, but NOT updating the iterator. (So that any calling loop can do
* this.) The iterator's current points to NULL. If the extracted element
* is to be deleted, this is the callers responsibility.
**********************************************************************/
inline ELIST2_LINK *ELIST2_ITERATOR::extract() {
ELIST2_LINK *extracted_link;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::extract", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::extract", ABORT, NULL);
if (!current) //list empty or
//element extracted
NULL_CURRENT.error ("ELIST2_ITERATOR::extract",
ABORT, NULL);
#endif
if (list->singleton()) {
// Special case where we do need to change the iterator.
prev = next = list->last = NULL;
} else {
prev->next = next; //remove from list
next->prev = prev;
if (current == list->last) {
list->last = prev;
ex_current_was_last = TRUE;
} else {
ex_current_was_last = FALSE;
}
}
// Always set ex_current_was_cycle_pt so an add/forward will work in a loop.
ex_current_was_cycle_pt = (current == cycle_pt) ? TRUE : FALSE;
extracted_link = current;
extracted_link->next = NULL; //for safety
extracted_link->prev = NULL; //for safety
current = NULL;
return extracted_link;
}
/***********************************************************************
* ELIST2_ITERATOR::move_to_first()
*
* Move current so that it is set to the start of the list.
* Return data just in case anyone wants it.
**********************************************************************/
inline ELIST2_LINK *ELIST2_ITERATOR::move_to_first() {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::move_to_first", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::move_to_first", ABORT, NULL);
#endif
current = list->First ();
prev = list->last;
next = current ? current->next : NULL;
return current;
}
/***********************************************************************
* ELIST2_ITERATOR::move_to_last()
*
* Move current so that it is set to the end of the list.
* Return data just in case anyone wants it.
**********************************************************************/
inline ELIST2_LINK *ELIST2_ITERATOR::move_to_last() {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::move_to_last", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::move_to_last", ABORT, NULL);
#endif
current = list->last;
prev = current ? current->prev : NULL;
next = current ? current->next : NULL;
return current;
}
/***********************************************************************
* ELIST2_ITERATOR::mark_cycle_pt()
*
* Remember the current location so that we can tell whether we've returned
* to this point later.
*
* If the current point is deleted either now, or in the future, the cycle
* point will be set to the next item which is set to current. This could be
* by a forward, add_after_then_move or add_after_then_move.
**********************************************************************/
inline void ELIST2_ITERATOR::mark_cycle_pt() {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::mark_cycle_pt", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::mark_cycle_pt", ABORT, NULL);
#endif
if (current)
cycle_pt = current;
else
ex_current_was_cycle_pt = TRUE;
started_cycling = FALSE;
}
/***********************************************************************
* ELIST2_ITERATOR::at_first()
*
* Are we at the start of the list?
*
**********************************************************************/
inline BOOL8 ELIST2_ITERATOR::at_first() {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::at_first", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::at_first", ABORT, NULL);
#endif
//we're at a deleted
return ((list->empty ()) || (current == list->First ()) || ((current == NULL) &&
(prev == list->last) && //NON-last pt between
!ex_current_was_last)); //first and last
}
/***********************************************************************
* ELIST2_ITERATOR::at_last()
*
* Are we at the end of the list?
*
**********************************************************************/
inline BOOL8 ELIST2_ITERATOR::at_last() {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::at_last", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::at_last", ABORT, NULL);
#endif
//we're at a deleted
return ((list->empty ()) || (current == list->last) || ((current == NULL) &&
(prev == list->last) && //last point between
ex_current_was_last)); //first and last
}
/***********************************************************************
* ELIST2_ITERATOR::cycled_list()
*
* Have we returned to the cycle_pt since it was set?
*
**********************************************************************/
inline BOOL8 ELIST2_ITERATOR::cycled_list() {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::cycled_list", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::cycled_list", ABORT, NULL);
#endif
return ((list->empty ()) || ((current == cycle_pt) && started_cycling));
}
/***********************************************************************
* ELIST2_ITERATOR::length()
*
* Return the length of the list
*
**********************************************************************/
inline inT32 ELIST2_ITERATOR::length() {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::length", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::length", ABORT, NULL);
#endif
return list->length ();
}
/***********************************************************************
* ELIST2_ITERATOR::sort()
*
* Sort the elements of the list, then reposition at the start.
*
**********************************************************************/
inline void
ELIST2_ITERATOR::sort ( //sort elements
int comparator ( //comparison routine
const void *, const void *)) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::sort", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::sort", ABORT, NULL);
#endif
list->sort (comparator);
move_to_first();
}
/***********************************************************************
* ELIST2_ITERATOR::add_to_end
*
* Add a new element to the end of the list without moving the iterator.
* This is provided because a single linked list cannot move to the last as
* the iterator couldn't set its prev pointer. Adding to the end is
* essential for implementing
queues.
**********************************************************************/
inline void ELIST2_ITERATOR::add_to_end( // element to add
ELIST2_LINK *new_element) {
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_to_end", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
#endif
if (this->at_last ()) {
this->add_after_stay_put (new_element);
}
else {
if (this->at_first ()) {
this->add_before_stay_put (new_element);
list->last = new_element;
}
else { //Iteratr is elsewhere
new_element->next = list->last->next;
new_element->prev = list->last;
list->last->next->prev = new_element;
list->last->next = new_element;
list->last = new_element;
}
}
}
/***********************************************************************
QUOTE_IT MACRO DEFINITION
===========================
Replace <parm> with "<parm>". <parm> may be an arbitrary number of tokens
***********************************************************************/
#define QUOTE_IT( parm ) #parm
/***********************************************************************
ELIST2IZE( CLASSNAME ) MACRO DEFINITION
======================================
CLASSNAME is assumed to be the name of a class which has a baseclass of
ELIST2_LINK.
NOTE: Because we dont use virtual functions in the list code, the list code
will NOT work correctly for classes derived from this.
The macro generates:
- An element deletion function: CLASSNAME##_zapper
- An E_LIST2 subclass: CLASSNAME##_LIST
- An E_LIST2_ITERATOR subclass:
CLASSNAME##_IT
NOTE: Generated names are DELIBERATELY designed to clash with those for
ELISTIZE but NOT with those for CLISTIZE and CLIST2IZE
Two macros are provided: ELIST2IZE and ELIST2IZEH
The ...IZEH macros just define the class names for use in .h files
The ...IZE macros define the code use in .c files
***********************************************************************/
/***********************************************************************
ELIST2IZEH( CLASSNAME ) MACRO
ELIST2IZEH is a concatenation of 3 fragments ELIST2IZEH_A, ELIST2IZEH_B and
ELIST2IZEH_C.
***********************************************************************/
#define ELIST2IZEH_A( CLASSNAME ) \
\
extern DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \
ELIST2_LINK* link); /*link to delete*/
#define ELIST2IZEH_B( CLASSNAME ) \
\
/*********************************************************************** \
* CLASS - CLASSNAME##_LIST \
* \
* List class for class CLASSNAME \
* \
**********************************************************************/ \
\
class DLLSYM CLASSNAME##_LIST : public ELIST2 \
{ \
public: \
CLASSNAME##_LIST():ELIST2() {} \
/* constructor */ \
\
CLASSNAME##_LIST( /* dont construct */ \
const CLASSNAME##_LIST&) /*by initial assign*/\
{ DONT_CONSTRUCT_LIST_BY_COPY.error( QUOTE_IT( CLASSNAME##_LIST ), \
ABORT, NULL ); } \
\
void clear() /* delete elements */\
{ ELIST2::internal_clear( &CLASSNAME##_zapper ); } \
\
~CLASSNAME##_LIST() /* destructor */ \
{ clear(); } \
\
/* Become a deep copy of src_list*/ \
void deep_copy(const CLASSNAME##_LIST* src_list, \
CLASSNAME* (*copier)(const CLASSNAME*)); \
\
void operator=( /* prevent assign */ \
const CLASSNAME##_LIST&) \
{ DONT_ASSIGN_LISTS.error( QUOTE_IT( CLASSNAME##_LIST ), \
ABORT, NULL ); }
#define ELIST2IZEH_C( CLASSNAME ) \
}; \
\
\
\
/*********************************************************************** \
* CLASS - CLASSNAME##_IT \
* \
* Iterator class for class CLASSNAME##_LIST \
* \
* Note: We don't need to coerce pointers to member functions input \
* parameters as these are automatically converted to the type of the base \
* type. ("A ptr to a class may be converted to a pointer to a public base \
* class of that class") \
**********************************************************************/ \
\
class DLLSYM CLASSNAME##_IT : public ELIST2_ITERATOR \
{ \
public: \
CLASSNAME##_IT():ELIST2_ITERATOR(){} \
\
CLASSNAME##_IT( \
CLASSNAME##_LIST* list):ELIST2_ITERATOR(list){} \
\
CLASSNAME* data() \
{ return (CLASSNAME*) ELIST2_ITERATOR::data(); } \
\
CLASSNAME* data_relative( \
inT8 offset) \
{ return (CLASSNAME*) ELIST2_ITERATOR::data_relative( offset ); } \
\
CLASSNAME* forward() \
{ return (CLASSNAME*) ELIST2_ITERATOR::forward(); } \
\
CLASSNAME* backward() \
{ return (CLASSNAME*) ELIST2_ITERATOR::backward(); } \
\
CLASSNAME* extract() \
{ return (CLASSNAME*) ELIST2_ITERATOR::extract(); } \
\
CLASSNAME* move_to_first() \
{ return (CLASSNAME*) ELIST2_ITERATOR::move_to_first(); } \
\
CLASSNAME* move_to_last() \
{ return (CLASSNAME*) ELIST2_ITERATOR::move_to_last(); } \
};
#define ELIST2IZEH( CLASSNAME ) \
\
ELIST2IZEH_A( CLASSNAME ) \
\
ELIST2IZEH_B( CLASSNAME ) \
\
ELIST2IZEH_C( CLASSNAME )
/***********************************************************************
ELIST2IZE( CLASSNAME ) MACRO
***********************************************************************/
#define ELIST2IZE( CLASSNAME ) \
\
/*********************************************************************** \
* CLASSNAME##_zapper \
* \
* A function which can delete a CLASSNAME element. This is passed to the \
* generic clear list member function so that when a list is cleared the \
* elements on the list are properly destroyed from the base class, even \
* though we dont use a virtual destructor function. \
**********************************************************************/ \
\
DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \
ELIST2_LINK* link) /*link to delete*/ \
{ \
delete (CLASSNAME *) link; \
} \
\
/* Become a deep copy of src_list*/ \
void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST* src_list, \
CLASSNAME* (*copier)(const CLASSNAME*)) { \
\
CLASSNAME##_IT from_it(const_cast<CLASSNAME##_LIST*>(src_list)); \
CLASSNAME##_IT to_it(this); \
\
for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward()) \
to_it.add_after_then_move((*copier)(from_it.data())); \
}
#endif
|