📄 clst.h
字号:
BAD_PARAMETER.error ("CLIST_ITERATOR::add_after_stay_put", ABORT, "new_data is NULL"); #endif new_element = new CLIST_LINK; new_element->data = new_data; if (list->empty ()) { new_element->next = new_element; list->last = new_element; prev = next = new_element; ex_current_was_last = FALSE; current = NULL; } else { new_element->next = next; if (current) { //not extracted current->next = new_element; if (prev == current) prev = new_element; if (current == list->last) list->last = new_element; } else { //current extracted prev->next = new_element; if (ex_current_was_last) { list->last = new_element; ex_current_was_last = FALSE; } } next = new_element; }}/*********************************************************************** * CLIST_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 CLIST_ITERATOR::add_before_then_move( // element to add void *new_data) { CLIST_LINK *new_element; #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL); if (!new_data) BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_then_move", ABORT, "new_data is NULL"); #endif new_element = new CLIST_LINK; new_element->data = new_data; if (list->empty ()) { new_element->next = new_element; list->last = new_element; prev = next = new_element; } else { prev->next = new_element; if (current) { //not extracted new_element->next = current; next = current; } else { //current extracted new_element->next = next; if (ex_current_was_last) list->last = new_element; if (ex_current_was_cycle_pt) cycle_pt = new_element; } } current = new_element;}/*********************************************************************** * CLIST_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 CLIST_ITERATOR::add_before_stay_put( // element to add void *new_data) { CLIST_LINK *new_element; #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL); if (!new_data) BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, "new_data is NULL"); #endif new_element = new CLIST_LINK; new_element->data = new_data; if (list->empty ()) { new_element->next = new_element; list->last = new_element; prev = next = new_element; ex_current_was_last = TRUE; current = NULL; } else { prev->next = new_element; if (current) { //not extracted new_element->next = current; if (next == current) next = new_element; } else { //current extracted new_element->next = next; if (ex_current_was_last) list->last = new_element; } prev = new_element; }}/*********************************************************************** * CLIST_ITERATOR::add_list_after * * Insert another list to this list after the current element but dont move the * iterator. **********************************************************************/inline void CLIST_ITERATOR::add_list_after(CLIST *list_to_add) { #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL); if (!list_to_add) BAD_PARAMETER.error ("CLIST_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 (); if (current == list->last) list->last = list_to_add->last; list_to_add->last->next = next; next = current->next; } else { //current extracted prev->next = list_to_add->First (); if (ex_current_was_last) { list->last = list_to_add->last; ex_current_was_last = FALSE; } list_to_add->last->next = next; next = prev->next; } } list_to_add->last = NULL; }}/*********************************************************************** * CLIST_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 CLIST_ITERATOR::add_list_before(CLIST *list_to_add) { #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL); if (!list_to_add) BAD_PARAMETER.error ("CLIST_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; }}/*********************************************************************** * CLIST_ITERATOR::extract * * Do extraction by removing current from the list, deleting the cons cell * and returning the data 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 data is to be deleted, this is the callers responsibility. **********************************************************************/inline void *CLIST_ITERATOR::extract() { void *extracted_data; #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::extract", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::extract", ABORT, NULL); if (!current) //list empty or //element extracted NULL_CURRENT.error ("CLIST_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_data = current->data; delete(current); //destroy CONS cell current = NULL; return extracted_data;}/*********************************************************************** * CLIST_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 void *CLIST_ITERATOR::move_to_first() { #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::move_to_first", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::move_to_first", ABORT, NULL); #endif current = list->First (); prev = list->last; next = current != NULL ? current->next : NULL; return current->data;}/*********************************************************************** * CLIST_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 CLIST_ITERATOR::mark_cycle_pt() { #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::mark_cycle_pt", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::mark_cycle_pt", ABORT, NULL); #endif if (current) cycle_pt = current; else ex_current_was_cycle_pt = TRUE; started_cycling = FALSE;}/*********************************************************************** * CLIST_ITERATOR::at_first() * * Are we at the start of the list? * **********************************************************************/inline BOOL8 CLIST_ITERATOR::at_first() { #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::at_first", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_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}/*********************************************************************** * CLIST_ITERATOR::at_last() * * Are we at the end of the list? * **********************************************************************/inline BOOL8 CLIST_ITERATOR::at_last() { #ifdef _DEBUG if (!this) NULL_OBJECT.error ("CLIST_ITERATOR::at_last", ABORT, NULL); if (!list) NO_LIST.error ("CLIST_ITERATOR::at_last", ABORT, NULL); #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -