GRU - Generic Reusable Utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
gru_list.h
Go to the documentation of this file.
1 /*
2  Copyright 2016 Otavio Rodolfo Piske
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 #ifndef LIST_H
17 #define LIST_H
18 
19 #include <assert.h>
20 #include <inttypes.h>
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include "common/gru_base.h"
27 #include "common/gru_status.h"
29 #include "gru_node.h"
30 #include "gru_node_info.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct gru_list_t_ {
39 } gru_list_t;
40 
46 
52 
59 gru_export uint32_t gru_list_count(const gru_list_t *list);
60 
70 gru_export const gru_node_t *gru_list_append(gru_list_t *list, const void *data);
71 
80  gru_list_t *list, const void *data, uint32_t position);
81 
88 gru_export gru_node_t *gru_list_remove(gru_list_t *list, uint32_t position);
89 
98  gru_list_t *list, compare_function_t comparable, const void *other);
99 
106 gru_export const gru_node_t *gru_list_get(const gru_list_t *list, uint32_t position);
107 
116 gru_export void gru_list_for_each_compare(const gru_list_t *list, bool uniqueness,
117  compare_function_t comparable, const void *compare, void *result);
118 
126  const gru_list_t *list, handle_function_t handle, void *data);
127 
136  const gru_list_t *list, handle_function_info_t handle, void *data);
137 
146 gru_export const void *gru_list_get_item(
147  const gru_list_t *list, compare_function_t comparable, const void *other);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif
Definition: gru_node.h:25
const void * gru_list_get_item(const gru_list_t *list, compare_function_t comparable, const void *other)
Traverses the list comparing the data.
Definition: gru_list.c:266
const gru_node_t * gru_list_get(const gru_list_t *list, uint32_t position)
Gets a node from the list at the given position.
Definition: gru_list.c:195
gru_list_t * gru_list_new(gru_status_t *status)
Creates a new list.
Definition: gru_list.c:18
gru_node_t * current
Definition: gru_list.h:38
gru_node_t * gru_list_insert(gru_list_t *list, const void *data, uint32_t position)
Inserts an item in the list.
Definition: gru_list.c:120
Definition: gru_list.h:36
const gru_node_t * gru_list_append(gru_list_t *list, const void *data)
Appends an item in the list.
Definition: gru_list.c:99
void gru_list_for_each(const gru_list_t *list, handle_function_t handle, void *data)
Traverses the list executing a set of operations.
Definition: gru_list.c:227
void gru_list_for_each_ex(const gru_list_t *list, handle_function_info_t handle, void *data)
Traverses the list executing a set of operations and passes through node information (ie...
Definition: gru_list.c:243
#define gru_export
Definition: gru_portable.h:19
void(* handle_function_info_t)(const void *, gru_node_info_t info, void *)
A handler function for the collections module that also receiver node information.
Definition: gru_collection_callbacks.h:40
struct gru_list_t_ gru_list_t
bool gru_list_remove_item(gru_list_t *list, compare_function_t comparable, const void *other)
Removes a node that matches a given data as returned by comparable.
Definition: gru_list.c:164
gru_node_t * root
Definition: gru_list.h:37
uint32_t gru_list_count(const gru_list_t *list)
Returns the number of items in a list.
Definition: gru_list.c:84
gru_node_t * gru_list_remove(gru_list_t *list, uint32_t position)
Removes an item from a list.
Definition: gru_list.c:145
void(* handle_function_t)(const void *, void *)
Handler function for the collections module.
Definition: gru_collection_callbacks.h:35
Status type.
Definition: gru_status.h:47
bool(* compare_function_t)(const void *, const void *data, void *result)
Comparator function for the collections module.
Definition: gru_collection_callbacks.h:30
void gru_list_destroy(gru_list_t **list)
Ensures that the list is properly destroyed.
Definition: gru_list.c:36
void gru_list_for_each_compare(const gru_list_t *list, bool uniqueness, compare_function_t comparable, const void *other, void *result)
Traverses the list comparing the data.
Definition: gru_list.c:207