29 #ifndef GLOBALS_LIST_H 30 #define GLOBALS_LIST_H 32 #include "os/memory.h" 43 template <
class T,
class A=DefaultAllocator>
52 friend class List<T,A>;
119 _FORCE_INLINE_ T&
get() {
125 _FORCE_INLINE_
const T&
get()
const {
131 _FORCE_INLINE_
void set(
const T& p_value) {
156 bool erase(
const Element* p_I) {
158 ERR_FAIL_COND_V(!p_I,
false);
159 ERR_FAIL_COND_V(p_I->data!=
this,
false);
169 p_I->prev_ptr->next_ptr=p_I->next_ptr;
172 p_I->next_ptr->prev_ptr=p_I->prev_ptr;
174 memdelete_allocator<Element,A>(
const_cast<Element*
>(p_I) );
189 _FORCE_INLINE_
const Element*
front()
const {
191 return _data?_data->first:0;
198 return _data?_data->first:0;
204 _FORCE_INLINE_
const Element*
back()
const {
206 return _data?_data->last:0;
212 _FORCE_INLINE_ Element*
back() {
214 return _data?_data->last:0;
224 _data=memnew_allocator(_Data,A);
230 Element* n = memnew_allocator(Element,A);
231 n->value = (T&)value;
233 n->prev_ptr=_data->last;
239 _data->last->next_ptr=n;
254 if (_data && _data->last)
265 _data=memnew_allocator(_Data,A);
271 Element* n = memnew_allocator(Element,A);
272 n->value = (T&)value;
274 n->next_ptr = _data->first;
279 _data->first->prev_ptr=n;
294 if (_data && _data->first)
302 Element*
find(
const T_v& p_val) {
304 Element* it =
front();
306 if (it->value == p_val)
return it;
319 bool ret = _data->erase(p_I);
321 if (_data->size_cache==0) {
322 memdelete_allocator<_Data,A>(_data);
337 Element* I =
find(value);
346 return (!_data || !_data->size_cache);
359 _FORCE_INLINE_
int size()
const {
361 return _data?_data->size_cache:0;
365 void swap(Element* p_A, Element *p_B) {
367 ERR_FAIL_COND(!p_A || !p_B);
368 ERR_FAIL_COND(p_A->data!=_data);
369 ERR_FAIL_COND(p_B->data!=_data);
371 Element* A_prev=p_A->prev_ptr;
372 Element* A_next=p_A->next_ptr;
374 p_A->next_ptr=p_B->next_ptr;
375 p_A->prev_ptr=p_B->prev_ptr;
377 p_B->next_ptr=A_next;
378 p_B->prev_ptr=A_prev;
381 p_A->prev_ptr->next_ptr=p_A;
383 p_A->next_ptr->prev_ptr=p_A;
386 p_B->prev_ptr->next_ptr=p_B;
388 p_B->next_ptr->prev_ptr=p_B;
397 const Element *it=p_list.
front();
406 T& operator[](
int p_index) {
408 if (p_index<0 || p_index>=size()) {
410 ERR_FAIL_COND_V(p_index<0 || p_index>=size(),aux);
425 ERR_FAIL_V( *((T*)0) );
428 const T& operator[](
int p_index)
const {
430 if (p_index<0 || p_index>=size()) {
432 ERR_FAIL_COND_V(p_index<0 || p_index>=size(),aux);
435 const Element *I=
front();
447 ERR_FAIL_V( *((T*)0) );
451 void move_to_back(Element* p_I) {
453 ERR_FAIL_COND(p_I->data!=_data);
457 if (_data->first==p_I) {
458 _data->first=p_I->next_ptr;
461 if (_data->last==p_I)
462 _data->last=p_I->prev_ptr;
465 p_I->prev_ptr->next_ptr=p_I->next_ptr;
468 p_I->next_ptr->prev_ptr=p_I->prev_ptr;
471 _data->last->next_ptr=p_I;
472 p_I->prev_ptr=_data->last;
481 Element *F =
front();
483 for(
int i=0;i<s;i++) {
485 SWAP( F->value, B->value );
491 void move_to_front(Element* p_I) {
493 ERR_FAIL_COND(p_I->data!=_data);
497 if (_data->first==p_I) {
498 _data->first=p_I->next_ptr;
501 if (_data->last==p_I)
502 _data->last=p_I->prev_ptr;
505 p_I->prev_ptr->next_ptr=p_I->next_ptr;
508 p_I->next_ptr->prev_ptr=p_I->prev_ptr;
510 _data->first->prev_ptr=p_I;
511 p_I->next_ptr=_data->first;
517 void move_before(Element* value, Element* where) {
519 if (value->prev_ptr) {
520 value->prev_ptr->next_ptr = value->next_ptr;
523 _data->first = value->next_ptr;
525 if (value->next_ptr) {
526 value->next_ptr->prev_ptr = value->prev_ptr;
529 _data->last = value->prev_ptr;
532 value->next_ptr = where;
534 value->prev_ptr = _data->last;
539 value->prev_ptr = where->prev_ptr;
541 if (where->prev_ptr) {
542 where->prev_ptr->next_ptr = value;
544 _data->first = value;
547 where->prev_ptr = value;
556 sort_custom< Comparator<T> >();
560 void sort_custom_inplace() {
565 Element *from=
front();
566 Element *current=from;
571 Element *
next=current->next_ptr;
574 current->next_ptr=NULL;
578 current->prev_ptr=NULL;
579 current->next_ptr=from;
583 while( find && less(find->value,current->value) ) {
585 current->prev_ptr=
find;
586 current->next_ptr=find->next_ptr;
590 if (current->prev_ptr)
591 current->prev_ptr->next_ptr=current;
595 if (current->next_ptr)
596 current->next_ptr->prev_ptr=current;
601 current->prev_ptr=NULL;
602 current->next_ptr=NULL;
616 _FORCE_INLINE_
bool operator()(
const Element *a,
const Element* b)
const {
618 return compare(a->value,b->value);
643 sort.sort(aux_buffer,s);
645 _data->first=aux_buffer[0];
646 aux_buffer[0]->prev_ptr=NULL;
647 aux_buffer[0]->next_ptr=aux_buffer[1];
649 _data->last=aux_buffer[s-1];
650 aux_buffer[s-1]->prev_ptr=aux_buffer[s-2];
651 aux_buffer[s-1]->next_ptr=NULL;
653 for(
int i=1;i<s-1;i++) {
655 aux_buffer[i]->prev_ptr=aux_buffer[i-1];
656 aux_buffer[i]->next_ptr=aux_buffer[i+1];
660 memdelete_arr(aux_buffer);
670 const Element *it=p_list.
front();
686 ERR_FAIL_COND(_data->size_cache);
687 memdelete_allocator<_Data,A>(_data);
void sort()
Definition: list.h:554
void operator=(const List &p_list)
Definition: list.h:394
Element * push_back(const T &value)
Definition: list.h:220
_FORCE_INLINE_ Element * front()
Definition: list.h:197
_FORCE_INLINE_ const Element * prev() const
Definition: list.h:78
List(const List &p_list)
Definition: list.h:667
Element * push_front(const T &value)
Definition: list.h:261
_FORCE_INLINE_ const Element * front() const
Definition: list.h:189
bool erase(const T &value)
Definition: list.h:335
_FORCE_INLINE_ bool empty() const
Definition: list.h:344
_FORCE_INLINE_ const Element * back() const
Definition: list.h:204
_FORCE_INLINE_ const Element * next() const
Definition: list.h:63
bool erase(const Element *p_I)
Definition: list.h:316
_FORCE_INLINE_ Element * prev()
Definition: list.h:85
Element * find(const T_v &p_val)
Definition: list.h:302
_FORCE_INLINE_ const T * operator->() const
Definition: list.h:99
_FORCE_INLINE_ Element * back()
Definition: list.h:212
_FORCE_INLINE_ const T & operator*() const
Definition: list.h:93
_FORCE_INLINE_ Element * next()
Definition: list.h:70
void clear()
Definition: list.h:352
_FORCE_INLINE_ T * operator->()
Definition: list.h:112