The Pedigree Project  0.1
lists.cc
1 /*
2  * Copyright (c) 2007 Kevin Wolf
3  *
4  * This program is free software. It comes without any warranty, to
5  * the extent permitted by applicable law. You can redistribute it
6  * and/or modify it under the terms of the Do What The Fuck You Want
7  * To Public License, Version 2, as published by Sam Hocevar. See
8  * http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9  */
10 
11 #include "cdi/lists.h"
12 #include "pedigree/kernel/compiler.h"
13 #include "pedigree/kernel/processor/types.h"
14 
15 typedef struct {
16  struct list_node* anchor;
17  unsigned long size;
18 } list_t;
19 
20 extern "C"
21 {
22 list_t* list_create(void);
23 void list_destroy(list_t* list);
24 list_t* list_push(list_t* list, void* value);
25 void* list_pop(list_t* list);
26 int list_is_empty(list_t* list);
27 void* list_get_element_at(list_t* list, int index);
28 list_t* list_insert(list_t* list, int index, void* value);
29 void* list_remove(list_t* list, int index);
30 unsigned long list_size(list_t* list);
31 };
32 
33 
35  struct list_node* anchor;
36  size_t size;
37 };
38 
42 EXPORTED_PUBLIC cdi_list_t cdi_list_create()
43 {
44  return reinterpret_cast<cdi_list_t>(list_create());
45 }
46 
51 EXPORTED_PUBLIC void cdi_list_destroy(cdi_list_t list)
52 {
53  list_t* l = reinterpret_cast<list_t*>(list);
54  list_destroy(l);
55 }
56 
60 EXPORTED_PUBLIC cdi_list_t cdi_list_push(cdi_list_t list, void* value)
61 {
62  list_t* l = reinterpret_cast<list_t*>(list);
63  return reinterpret_cast<cdi_list_t>(list_push(l, value));
64 }
65 
69 EXPORTED_PUBLIC void* cdi_list_pop(cdi_list_t list)
70 {
71  list_t* l = reinterpret_cast<list_t*>(list);
72  return list_pop(l);
73 }
74 
79 EXPORTED_PUBLIC size_t cdi_list_empty(cdi_list_t list)
80 {
81  list_t* l = reinterpret_cast<list_t*>(list);
82  return list_is_empty(l);
83 }
84 
88 EXPORTED_PUBLIC void* cdi_list_get(cdi_list_t list, size_t index)
89 {
90  list_t* l = reinterpret_cast<list_t*>(list);
91  return list_get_element_at(l, index);
92 }
93 
99 EXPORTED_PUBLIC cdi_list_t cdi_list_insert(cdi_list_t list, size_t index, void* value)
100 {
101  list_t* l = reinterpret_cast<list_t*>(list);
102  return reinterpret_cast<cdi_list_t>(list_insert(l, index, value));
103 }
104 
108 EXPORTED_PUBLIC void* cdi_list_remove(cdi_list_t list, size_t index)
109 {
110  list_t* l = reinterpret_cast<list_t*>(list);
111  return list_remove(l, index);
112 }
113 
117 EXPORTED_PUBLIC size_t cdi_list_size(cdi_list_t list)
118 {
119  list_t* l = reinterpret_cast<list_t*>(list);
120  return list_size(l);
121 }
Definition: _list.cc:32