mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-21 17:13:09 +08:00
Modernize CLIST code
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
fd187b0c18
commit
b47ce5643b
@ -35,15 +35,12 @@ namespace tesseract {
|
||||
|
||||
void CLIST::internal_deep_clear( // destroy all links
|
||||
void (*zapper)(void *)) { // ptr to zapper functn
|
||||
CLIST_LINK *ptr;
|
||||
CLIST_LINK *next;
|
||||
|
||||
if (!empty()) {
|
||||
ptr = last->next; // set to first
|
||||
auto ptr = last->next; // set to first
|
||||
last->next = nullptr; // break circle
|
||||
last = nullptr; // set list empty
|
||||
while (ptr) {
|
||||
next = ptr->next;
|
||||
auto next = ptr->next;
|
||||
zapper(ptr->data);
|
||||
delete (ptr);
|
||||
ptr = next;
|
||||
@ -61,15 +58,12 @@ void CLIST::internal_deep_clear( // destroy all links
|
||||
**********************************************************************/
|
||||
|
||||
void CLIST::shallow_clear() { // destroy all links
|
||||
CLIST_LINK *ptr;
|
||||
CLIST_LINK *next;
|
||||
|
||||
if (!empty()) {
|
||||
ptr = last->next; // set to first
|
||||
auto ptr = last->next; // set to first
|
||||
last->next = nullptr; // break circle
|
||||
last = nullptr; // set list empty
|
||||
while (ptr) {
|
||||
next = ptr->next;
|
||||
auto next = ptr->next;
|
||||
delete (ptr);
|
||||
ptr = next;
|
||||
}
|
||||
@ -325,8 +319,6 @@ void CLIST_ITERATOR::exchange( // positions of 2 links
|
||||
CLIST_ITERATOR *other_it) { // other iterator
|
||||
constexpr ERRCODE DONT_EXCHANGE_DELETED("Can't exchange deleted elements of lists");
|
||||
|
||||
CLIST_LINK *old_current;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!list)
|
||||
NO_LIST.error("CLIST_ITERATOR::exchange", ABORT, nullptr);
|
||||
@ -402,7 +394,7 @@ non-adjacent elements. */
|
||||
|
||||
/* The actual exchange - in all cases*/
|
||||
|
||||
old_current = current;
|
||||
auto old_current = current;
|
||||
current = other_it->current;
|
||||
other_it->current = old_current;
|
||||
}
|
||||
@ -420,7 +412,6 @@ non-adjacent elements. */
|
||||
CLIST_LINK *CLIST_ITERATOR::extract_sublist( // from this current
|
||||
CLIST_ITERATOR *other_it) { // to other current
|
||||
CLIST_ITERATOR temp_it = *this;
|
||||
CLIST_LINK *end_of_new_list;
|
||||
|
||||
constexpr ERRCODE BAD_SUBLIST("Can't find sublist end point in original list");
|
||||
#ifndef NDEBUG
|
||||
@ -468,7 +459,7 @@ CLIST_LINK *CLIST_ITERATOR::extract_sublist( // from this current
|
||||
|
||||
// circularise sublist
|
||||
other_it->current->next = current;
|
||||
end_of_new_list = other_it->current;
|
||||
auto end_of_new_list = other_it->current;
|
||||
|
||||
// sublist = whole list
|
||||
if (prev == other_it->current) {
|
||||
|
@ -290,8 +290,6 @@ inline CLIST_ITERATOR::CLIST_ITERATOR(CLIST *list_to_iterate) {
|
||||
|
||||
inline void CLIST_ITERATOR::add_after_then_move( // element to add
|
||||
void *new_data) {
|
||||
CLIST_LINK *new_element;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("CLIST_ITERATOR::add_after_then_move", ABORT, nullptr);
|
||||
@ -301,7 +299,7 @@ inline void CLIST_ITERATOR::add_after_then_move( // element to add
|
||||
}
|
||||
#endif
|
||||
|
||||
new_element = new CLIST_LINK;
|
||||
auto new_element = new CLIST_LINK;
|
||||
new_element->data = new_data;
|
||||
|
||||
if (list->empty()) {
|
||||
@ -339,8 +337,6 @@ inline void CLIST_ITERATOR::add_after_then_move( // element to add
|
||||
|
||||
inline void CLIST_ITERATOR::add_after_stay_put( // element to add
|
||||
void *new_data) {
|
||||
CLIST_LINK *new_element;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("CLIST_ITERATOR::add_after_stay_put", ABORT, nullptr);
|
||||
@ -350,7 +346,7 @@ inline void CLIST_ITERATOR::add_after_stay_put( // element to add
|
||||
}
|
||||
#endif
|
||||
|
||||
new_element = new CLIST_LINK;
|
||||
auto new_element = new CLIST_LINK;
|
||||
new_element->data = new_data;
|
||||
|
||||
if (list->empty()) {
|
||||
@ -390,8 +386,6 @@ inline void CLIST_ITERATOR::add_after_stay_put( // element to add
|
||||
|
||||
inline void CLIST_ITERATOR::add_before_then_move( // element to add
|
||||
void *new_data) {
|
||||
CLIST_LINK *new_element;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("CLIST_ITERATOR::add_before_then_move", ABORT, nullptr);
|
||||
@ -401,7 +395,7 @@ inline void CLIST_ITERATOR::add_before_then_move( // element to add
|
||||
}
|
||||
#endif
|
||||
|
||||
new_element = new CLIST_LINK;
|
||||
auto new_element = new CLIST_LINK;
|
||||
new_element->data = new_data;
|
||||
|
||||
if (list->empty()) {
|
||||
@ -435,8 +429,6 @@ inline void CLIST_ITERATOR::add_before_then_move( // element to add
|
||||
|
||||
inline void CLIST_ITERATOR::add_before_stay_put( // element to add
|
||||
void *new_data) {
|
||||
CLIST_LINK *new_element;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("CLIST_ITERATOR::add_before_stay_put", ABORT, nullptr);
|
||||
@ -446,7 +438,7 @@ inline void CLIST_ITERATOR::add_before_stay_put( // element to add
|
||||
}
|
||||
#endif
|
||||
|
||||
new_element = new CLIST_LINK;
|
||||
auto new_element = new CLIST_LINK;
|
||||
new_element->data = new_data;
|
||||
|
||||
if (list->empty()) {
|
||||
@ -574,8 +566,6 @@ inline void CLIST_ITERATOR::add_list_before(CLIST *list_to_add) {
|
||||
**********************************************************************/
|
||||
|
||||
inline void *CLIST_ITERATOR::extract() {
|
||||
void *extracted_data;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("CLIST_ITERATOR::extract", ABORT, nullptr);
|
||||
@ -601,7 +591,7 @@ inline void *CLIST_ITERATOR::extract() {
|
||||
}
|
||||
// Always set ex_current_was_cycle_pt so an add/forward will work in a loop.
|
||||
ex_current_was_cycle_pt = (current == cycle_pt);
|
||||
extracted_data = current->data;
|
||||
auto extracted_data = current->data;
|
||||
delete (current); // destroy CONS cell
|
||||
current = nullptr;
|
||||
return extracted_data;
|
||||
@ -759,8 +749,6 @@ inline void CLIST_ITERATOR::sort( // sort elements
|
||||
|
||||
inline void CLIST_ITERATOR::add_to_end( // element to add
|
||||
void *new_data) {
|
||||
CLIST_LINK *new_element;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!list) {
|
||||
NO_LIST.error("CLIST_ITERATOR::add_to_end", ABORT, nullptr);
|
||||
@ -777,7 +765,7 @@ inline void CLIST_ITERATOR::add_to_end( // element to add
|
||||
this->add_before_stay_put(new_data);
|
||||
list->last = prev;
|
||||
} else { // Iteratr is elsewhere
|
||||
new_element = new CLIST_LINK;
|
||||
auto new_element = new CLIST_LINK;
|
||||
new_element->data = new_data;
|
||||
|
||||
new_element->next = list->last->next;
|
||||
|
Loading…
Reference in New Issue
Block a user