86 [[deprecated(
"TCODList is unsuitable as a C++ container.")]]
TCODList() =
default;
107 for (
void** it = TCOD_list_begin(l); it != TCOD_list_end(l); ++it) {
108 push(*
static_cast<T*
>(
static_cast<void*
>(it)));
113 while (allocSize < rhs.allocSize) allocate();
114 fillSize = rhs.fillSize;
116 for (T* t = rhs.
begin(); t != rhs.end(); ++t) {
145 if (array)
delete[] array;
150 swap(lhs.array, rhs.array);
151 swap(lhs.fillSize, rhs.fillSize);
152 swap(lhs.allocSize, rhs.allocSize);
166 [[deprecated(
"TCODList is unsuitable as a C++ container.")]]
TCODList(
int nbElements) {
168 allocSize = nbElements;
169 array =
new T[nbElements];
194 void set(
const T elt,
int idx) {
195 if ( idx < 0 )
return;
196 while ( allocSize < idx+1 ) allocate();
198 if ( idx+1 > fillSize ) fillSize = idx+1;
241 return ( fillSize == 0 );
285 for (T* curElt =
begin(); curElt != end(); ++curElt) {
286 if (*curElt == elt) {
return true; }
312 if ( fillSize+1 >= allocSize ) allocate();
313 for (
int idx=fillSize; idx > before; idx--) {
314 array[idx]=array[idx-1];
318 return &array[before];
343 for ( T* curElt =
begin(); curElt != end(); curElt ++) {
344 if ( *curElt == elt ) {
350 void removeFast(
const T elt) {
351 for ( T* curElt =
begin(); curElt != end(); curElt ++) {
352 if ( *curElt == elt ) {
381 for (T *t=l2.
begin(); t!= l2.end(); t++) {
427 for ( T* curElt =
begin(); curElt != end(); curElt ++ ) {
456 while (head < tail) {
457 std::swap(*head, *tail);
483 if ( fillSize+1 >= allocSize ) allocate();
484 array[fillSize++] = elt;
508 if ( fillSize == 0 )
return T{};
509 return array[--fillSize];
533 if ( fillSize == 0 )
return T{};
534 return array[fillSize-1];
567 if ( fillSize == 0 )
return (T *)NULL;
571 if ( fillSize == 0 )
return (T *)NULL;
572 return &array[fillSize];
614 for ( T* curElt = elt; curElt < end()-1; curElt ++) {
615 *curElt = *(curElt+1);
618 if ( fillSize == 0 )
return ((T *)NULL)-1;
621 T *removeFast(T *elt) {
622 *elt = array[fillSize-1];
624 if ( fillSize == 0 )
return ((T *)NULL)-1;
630 int newSize = allocSize * 2;
631 if ( newSize == 0 ) newSize = 16;
632 T *newArray =
new T[ newSize ];
634 if ( fillSize > 0 ) memcpy(newArray, array,
sizeof(T)*fillSize);
TCODList(const TCOD_list_t l)
You can create a list by duplicating an existing list.
Definition list.hpp:106
TCODList()=default
You can create an empty list with the default constructor.
T get(int idx) const
You can retrieve a value with get.
Definition list.hpp:219
virtual ~TCODList()
You can delete a list, freeing any allocated resources.
Definition list.hpp:144
T * insertBefore(const T elt, int before)
Definition list.hpp:311
bool contains(const T elt) const
Definition list.hpp:283
void push(const T elt)
You can push an element on the stack (append it to the end of the list) :
Definition list.hpp:482
TCODList(int nbElements)
You can also create an empty list and pre-allocate memory for elements.
Definition list.hpp:166
T peek() const
You can read the last element of the stack without removing it :
Definition list.hpp:532
void remove(const T elt)
The _fast versions replace the element to remove with the last element of the list.
Definition list.hpp:342
int size() const
Definition list.hpp:261
T pop()
You can pop an element from the stack (remove the last element of the list).
Definition list.hpp:507
void set(const T elt, int idx)
You can assign a value with set.
Definition list.hpp:194
void clearAndDelete()
For lists containing pointers, you can clear the list and delete (or free for C) the elements :
Definition list.hpp:426
void addAll(const TCODList< T > &l2)
You can concatenate two lists.
Definition list.hpp:380
void clear()
Definition list.hpp:401
T * begin() const
You can iterate through the elements of the list using an iterator.
Definition list.hpp:566
void reverse()
This function reverses the order of the elements in the list.
Definition list.hpp:453
T * remove(T *elt)
You can remove an element from the list while iterating.
Definition list.hpp:613
bool isEmpty() const
Definition list.hpp:240
Deprecated libtcod list module.