You can assign a value with set. If needed, the array will allocate new elements up to idx.
C++ : template <class T> void TCODList::set(const T elt, int idx)
C : void TCOD_list_set(TCOD_list_t l,const void *elt, int idx)
Parameter | Description |
elt | Element to put in the array. |
idx | Index of the element. 0 <= idx |
l | In the C version, the handler, returned by a constructor. |
Example :
C++ : TCODList<int> intList; // the array is empty (contains 0 elements)
intList.set(5,0); // the array contains 1 element at position 0, value = 5
intList.set(7,2); // the array contains 3 elements : 5, 0, 7
C : TCOD_list_t intList = TCOD_list_new();
TCOD_list_set(intList,(const void *)5,0);
TCOD_list_set(intList,(const void *)7,2);
You can retrieve a value with get.
C++ : template <class T> T TCODList::get(int idx) const
C : void * TCOD_list_get(TCOD_list_t l,int idx)
Parameter | Description |
idx | Index of the element. 0 <= idx < size of the array |
l | In the C version, the handler, returned by a constructor. |
Example :
C++ : TCODList<int> intList;
intList.set(5,0);
int val = intList.get(0); // val == 5
C : TCOD_list_t intList = TCOD_list_new();
TCOD_list_set(intList,(const void *)5,0);
int val = (int)TCOD_list_get(intList,0); /* val == 5 */
You can check if an array is empty with :
C++ : template <class T> bool TCODList::isEmpty() const
C : bool TCOD_list_is_empty(TCOD_list_t l)
Parameter | Description |
l | In the C version, the handler, returned by a constructor. |
Example :
C++ : TCODList<int> intList;
bool empty=intList.isEmpty(); // empty == true
intList.set(3,0);
empty=intList.isEmpty(); // empty == false
C : TCOD_list_t intList = TCOD_list_new();
bool empty=TCOD_list_is_empty(intList); /* empty == true */
TCOD_list_set(intList,(const void *)5,0);
empty=TCOD_list_is_empty(intList); /* empty == false */
You can get the size of an array with :
C++ : template <class T> int TCODList::size() const
C : int TCOD_list_size(TCOD_list_t l)
Parameter | Description |
l | In the C version, the handler, returned by a constructor. |
Example :
C++ : TCODList<int> intList;
int size=intList.size(); // size == 0
intList.set(3,0);
size=intList.size(); // size == 1
C : TCOD_list_t intList = TCOD_list_new();
int size=TCOD_list_size(intList); /* size == 0 */
TCOD_list_set(intList,(const void *)5,0);
size=TCOD_list_size(intList); /* size == 1 */
You can check if an array contains a specific element with :
C++ : template <class T> bool TCODList::contains(const T elt) const
C : bool TCOD_list_contains(TCOD_list_t l,const void * elt)
Parameter | Description |
elt | The element. |
l | In the C version, the handler, returned by a constructor. |
Example :
C++ : TCODList<int> intList;
intList.set(3,0);
bool has3 = intList.contains(3); // has3 == true
bool has4 = intList.contains(4); // has4 == false
C : TCOD_list_t intList = TCOD_list_new();
TCOD_list_set(intList,(const void *)3,0);
bool has3 = TCOD_list_contains(intList,(const void *)3); /* has3 == true */
bool has4 = TCOD_list_contains(intList,(const void *)4); /* has4 == false */