TORCS  1.3.9
The Open Racing Car Simulator
List.h
Go to the documentation of this file.
1 /* -*- Mode: C++; -*- */
2 /* VER: $Id$ */
3 // copyright (c) 2004 by Christos Dimitrakakis <dimitrak@idiap.ch>
4 /***************************************************************************
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  ***************************************************************************/
12 #ifndef LIST_H
13 #define LIST_H
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <assert.h>
18 
20 typedef struct ListItem {
21  void* obj;
22  void (*free_obj) (void* obj);
23  struct ListItem* prev;
24  struct ListItem* next;
25 } LISTITEM;
26 
27 
37 typedef struct List {
41  int n;
42  LISTITEM* (*retrieve) (struct List* list, void* ptr);
44 } LIST;
45 
46 
48 LIST* List(void);
50 int ListSize(LIST* list);
52 LISTITEM* ListAppend(LIST* list, void* p);
54 LISTITEM* ListAppend(LIST* list, void* p, void (*free_obj) (void* obj));
58 LISTITEM* LastListItem(LIST* list);
60 LISTITEM* NextListItem(LIST* list);
62 int PopItem(LIST* list);
64 int ClearList(LIST* list);
66 LISTITEM* FindItem (LIST* list, void* ptr);
68 LISTITEM* GetItem (LIST* list, int n);
69 
70 LISTITEM* ListItem(void* ptr, void (*free_obj) (void* obj));
73 LISTITEM* LinkNext(LISTITEM* src, void* ptr, void (*free_obj) (void* obj));
74 LISTITEM* LinkPrev(LISTITEM* src, void* ptr, void (*free_obj) (void* obj));
75 int FreeListItem(LIST* list, LISTITEM* ptr);
76 int RemoveListItem(LIST* list, LISTITEM* ptr);
77 
78 LISTITEM* ListLinearSearchRetrieve (struct List* list, void* ptr);
79 
80 #endif
struct List LIST
A very simple list structure.
struct ListItem * next
next item
Definition: List.h:24
int RemoveListItem(LIST *list, LISTITEM *ptr)
Definition: List.cpp:201
A list item.
Definition: List.h:20
struct ListItem LISTITEM
A list item.
void * obj
data
Definition: List.h:21
LISTITEM * GetPrevItem(LISTITEM *ptr)
Definition: List.cpp:126
LISTITEM * tail
tail item
Definition: List.h:40
LISTITEM * GetNextItem(LISTITEM *ptr)
Definition: List.cpp:115
int FreeListItem(LIST *list, LISTITEM *ptr)
Definition: List.cpp:182
int PopItem(LIST *list)
Remove the topmost item of the list (also frees obj memory)
Definition: List.cpp:252
int n
number of items
Definition: List.h:41
int ClearList(LIST *list)
Clear the list.
Definition: List.cpp:291
LISTITEM * ListLinearSearchRetrieve(struct List *list, void *ptr)
Definition: List.cpp:324
LIST * List(void)
Create a new list.
Definition: List.cpp:16
static Point p[4]
Definition: Convex.cpp:54
void(* free_obj)(void *obj)
free hook
Definition: List.h:22
LISTITEM * ListItem(void *ptr, void(*free_obj)(void *obj))
Definition: List.cpp:164
LISTITEM * head
head item
Definition: List.h:39
int ListSize(LIST *list)
Get the size of the list.
Definition: List.cpp:341
LISTITEM * GetItem(LIST *list, int n)
Get the nth item of the list.
Definition: List.cpp:345
LISTITEM * ListAppend(LIST *list, void *p)
Append an item to the list.
Definition: List.cpp:34
LISTITEM * curr
current item
Definition: List.h:38
LISTITEM * FirstListItem(LIST *list)
Move to the first list item.
Definition: List.cpp:81
struct ListItem * prev
previous item
Definition: List.h:23
A very simple list structure.
Definition: List.h:37
LISTITEM * LastListItem(LIST *list)
Move to the last list item.
Definition: List.cpp:98
LISTITEM * NextListItem(LIST *list)
Advance one item.
Definition: List.cpp:67
LISTITEM * LinkNext(LISTITEM *src, void *ptr, void(*free_obj)(void *obj))
Definition: List.cpp:136
LISTITEM * LinkPrev(LISTITEM *src, void *ptr, void(*free_obj)(void *obj))
Definition: List.cpp:158
LISTITEM * FindItem(LIST *list, void *ptr)
Finds the LISTITEM pointer corresponding to the data.
Definition: List.cpp:318