elst.h

来自「一个google的OCR源码」· C头文件 代码 · 共 1,147 行 · 第 1/4 页

H
1,147
字号
/*********************************************************************** *                          ELIST_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 ELIST_ITERATOR::add_list_before(ELIST *list_to_add) {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::add_list_before", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::add_list_before", ABORT, NULL);  if (!list_to_add)    BAD_PARAMETER.error ("ELIST_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 ();      if (current) {             //not extracted        list_to_add->last->next = current;      }      else {                     //current extracted        list_to_add->last->next = next;        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;  }}/*********************************************************************** *                          ELIST_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 ELIST_LINK *ELIST_ITERATOR::extract() {  ELIST_LINK *extracted_link;  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::extract", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::extract", ABORT, NULL);  if (!current)                  //list empty or                                 //element extracted    NULL_CURRENT.error ("ELIST_ITERATOR::extract",      ABORT, NULL);  #endif  if (list->singleton ())        //special case where                                 //we do need to    prev = next = list->last = NULL;  //      change the iterator  else {    prev->next = next;           //remove from list    if (current == list->last) {      list->last = prev;      ex_current_was_last = TRUE;    }    else      ex_current_was_last = FALSE;    ex_current_was_cycle_pt = (current == cycle_pt) ? TRUE : FALSE;  }  extracted_link = current;  extracted_link->next = NULL;   //for safety  current = NULL;  return extracted_link;}/*********************************************************************** *                          ELIST_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 ELIST_LINK *ELIST_ITERATOR::move_to_first() {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::move_to_first", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::move_to_first", ABORT, NULL);  #endif  current = list->First ();  prev = list->last;  next = current ? current->next : NULL;  return current;}/*********************************************************************** *                          ELIST_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 ELIST_ITERATOR::mark_cycle_pt() {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::mark_cycle_pt", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::mark_cycle_pt", ABORT, NULL);  #endif  if (current)    cycle_pt = current;  else    ex_current_was_cycle_pt = TRUE;  started_cycling = FALSE;}/*********************************************************************** *                          ELIST_ITERATOR::at_first() * *  Are we at the start of the list? * **********************************************************************/inline BOOL8 ELIST_ITERATOR::at_first() {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::at_first", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_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}/*********************************************************************** *                          ELIST_ITERATOR::at_last() * *  Are we at the end of the list? * **********************************************************************/inline BOOL8 ELIST_ITERATOR::at_last() {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::at_last", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_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}/*********************************************************************** *                          ELIST_ITERATOR::cycled_list() * *  Have we returned to the cycle_pt since it was set? * **********************************************************************/inline BOOL8 ELIST_ITERATOR::cycled_list() {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::cycled_list", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::cycled_list", ABORT, NULL);  #endif  return ((list->empty ()) || ((current == cycle_pt) && started_cycling));}/*********************************************************************** *                          ELIST_ITERATOR::length() * *  Return the length of the list * **********************************************************************/inline inT32 ELIST_ITERATOR::length() {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::length", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::length", ABORT, NULL);  #endif  return list->length ();}/*********************************************************************** *                          ELIST_ITERATOR::sort() * *  Sort the elements of the list, then reposition at the start. * **********************************************************************/inline voidELIST_ITERATOR::sort (           //sort elementsint comparator (                 //comparison routineconst void *, const void *)) {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::sort", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::sort", ABORT, NULL);  #endif  list->sort (comparator);  move_to_first();}/*********************************************************************** *                          ELIST_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 ELIST_ITERATOR::add_to_end(  // element to add                                       ELIST_LINK *new_element) {  #ifdef _DEBUG  if (!this)    NULL_OBJECT.error ("ELIST_ITERATOR::add_to_end", ABORT, NULL);  if (!list)    NO_LIST.error ("ELIST_ITERATOR::add_to_end", ABORT, NULL);  if (!new_element)    BAD_PARAMETER.error ("ELIST_ITERATOR::add_to_end", ABORT,      "new_element is NULL");  if (new_element->next)    STILL_LINKED.error ("ELIST_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;      list->last->next = new_element;      list->last = new_element;    }  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?