hello

Dependents:   nespresso_demo nespresso_endpoint EnvoyNespressoEndpointColorDetectorV2

Fork of nsdl by Robert Taylor

Committer:
GeofferyOmlette
Date:
Wed Jun 04 15:38:26 2014 +0000
Revision:
0:f6e4e1bbb3fe
hello

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GeofferyOmlette 0:f6e4e1bbb3fe 1 /*
GeofferyOmlette 0:f6e4e1bbb3fe 2 * sn_linked_list.h
GeofferyOmlette 0:f6e4e1bbb3fe 3 *
GeofferyOmlette 0:f6e4e1bbb3fe 4 * Created on: 9.8.2011
GeofferyOmlette 0:f6e4e1bbb3fe 5 * Author: user
GeofferyOmlette 0:f6e4e1bbb3fe 6 */
GeofferyOmlette 0:f6e4e1bbb3fe 7
GeofferyOmlette 0:f6e4e1bbb3fe 8 #ifdef __cplusplus
GeofferyOmlette 0:f6e4e1bbb3fe 9 extern "C" {
GeofferyOmlette 0:f6e4e1bbb3fe 10 #endif
GeofferyOmlette 0:f6e4e1bbb3fe 11
GeofferyOmlette 0:f6e4e1bbb3fe 12 #ifndef SN_LINKED_LIST_H_
GeofferyOmlette 0:f6e4e1bbb3fe 13 #define SN_LINKED_LIST_H_
GeofferyOmlette 0:f6e4e1bbb3fe 14
GeofferyOmlette 0:f6e4e1bbb3fe 15 #define SN_LINKED_LIST_ERROR_NO_ERROR 0
GeofferyOmlette 0:f6e4e1bbb3fe 16 #define SN_LINKED_LIST_ERROR_INVALID_LIST_POINTER 1
GeofferyOmlette 0:f6e4e1bbb3fe 17 #define SN_LINKED_LIST_ERROR_LIST_NOT_EMPTY 2
GeofferyOmlette 0:f6e4e1bbb3fe 18 #define SN_LINKED_LIST_ERROR_NO_DATA_TO_ADD 3
GeofferyOmlette 0:f6e4e1bbb3fe 19 #define SN_LINKED_LIST_ERROR_DATA_ALLOCATOIN_FAILED 4
GeofferyOmlette 0:f6e4e1bbb3fe 20 #define SN_LINKED_LIST_ERROR_NOTHING_TO_REMOVE 5
GeofferyOmlette 0:f6e4e1bbb3fe 21
GeofferyOmlette 0:f6e4e1bbb3fe 22 struct sn_linked_list_node
GeofferyOmlette 0:f6e4e1bbb3fe 23 {
GeofferyOmlette 0:f6e4e1bbb3fe 24 struct sn_linked_list_node *next_node;
GeofferyOmlette 0:f6e4e1bbb3fe 25 struct sn_linked_list_node *previous_node;
GeofferyOmlette 0:f6e4e1bbb3fe 26 void *data;
GeofferyOmlette 0:f6e4e1bbb3fe 27 };
GeofferyOmlette 0:f6e4e1bbb3fe 28
GeofferyOmlette 0:f6e4e1bbb3fe 29 typedef struct sn_linked_list_t_
GeofferyOmlette 0:f6e4e1bbb3fe 30 {
GeofferyOmlette 0:f6e4e1bbb3fe 31 struct sn_linked_list_node *first_node;
GeofferyOmlette 0:f6e4e1bbb3fe 32 struct sn_linked_list_node *current_node;
GeofferyOmlette 0:f6e4e1bbb3fe 33 uint16_t node_count;
GeofferyOmlette 0:f6e4e1bbb3fe 34 }sn_linked_list_t;
GeofferyOmlette 0:f6e4e1bbb3fe 35
GeofferyOmlette 0:f6e4e1bbb3fe 36 /* \brief This function MUST be called once before starting to use other functionalities in this file. */
GeofferyOmlette 0:f6e4e1bbb3fe 37 extern void sn_linked_list_init(void *(*linked_list_alloc_function)(uint16_t), void (*linked_list_free_function)(void*));
GeofferyOmlette 0:f6e4e1bbb3fe 38
GeofferyOmlette 0:f6e4e1bbb3fe 39 /* \brief Creates a new linked list and returns a pointer to it, returns value NULL on allocation error */
GeofferyOmlette 0:f6e4e1bbb3fe 40 extern sn_linked_list_t *sn_linked_list_create(void);
GeofferyOmlette 0:f6e4e1bbb3fe 41
GeofferyOmlette 0:f6e4e1bbb3fe 42 /* \brief Removes empty linked list.
GeofferyOmlette 0:f6e4e1bbb3fe 43 * Note that the list will NOT be removed unless it is empty */
GeofferyOmlette 0:f6e4e1bbb3fe 44 extern int8_t sn_linked_list_free(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 45
GeofferyOmlette 0:f6e4e1bbb3fe 46 /* \brief Adds node to a linked list */
GeofferyOmlette 0:f6e4e1bbb3fe 47 extern int8_t sn_linked_list_add_node(sn_linked_list_t *linked_list, void *data);
GeofferyOmlette 0:f6e4e1bbb3fe 48
GeofferyOmlette 0:f6e4e1bbb3fe 49 /* \brief Returns a pointer to data on first node and sets it as a current node.
GeofferyOmlette 0:f6e4e1bbb3fe 50 * Returns NULL pointer if list is empty
GeofferyOmlette 0:f6e4e1bbb3fe 51 * Note that node first added to list is the last node on list and first node on list is the most recently added. */
GeofferyOmlette 0:f6e4e1bbb3fe 52 extern void *sn_linked_list_get_first_node(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 53
GeofferyOmlette 0:f6e4e1bbb3fe 54 /* \brief Returns a pointer to next node and a NULL pointer if next node does not exist
GeofferyOmlette 0:f6e4e1bbb3fe 55 * Note that you need to call sn_linked_list_get_first_node or
GeofferyOmlette 0:f6e4e1bbb3fe 56 * sn_linked_list_get_last_node and sn_linked_list_get_previous_node before using this function */
GeofferyOmlette 0:f6e4e1bbb3fe 57 extern void *sn_linked_list_get_next_node(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 58
GeofferyOmlette 0:f6e4e1bbb3fe 59 /* \brief Returns a pointer to current node and a NULL pointer if current node does not exist */
GeofferyOmlette 0:f6e4e1bbb3fe 60 extern void *sn_linked_list_get_current_node(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 61
GeofferyOmlette 0:f6e4e1bbb3fe 62 /* \brief Returns a pointer to next node and a NULL pointer if next node does not exist
GeofferyOmlette 0:f6e4e1bbb3fe 63 * * Note that you need to call sn_linked_list_get_last_node or
GeofferyOmlette 0:f6e4e1bbb3fe 64 * sn_linked_list_get_first_node and sn_linked_list_get_next_node before using this function */
GeofferyOmlette 0:f6e4e1bbb3fe 65 extern void *sn_linked_list_get_previous_node(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 66
GeofferyOmlette 0:f6e4e1bbb3fe 67 /* \brief Returns a pointer to last node on list and a NULL pointer if list is empty or error occurs.
GeofferyOmlette 0:f6e4e1bbb3fe 68 * Sets last node as current node. */
GeofferyOmlette 0:f6e4e1bbb3fe 69 extern void *sn_linked_list_get_last_node(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 70
GeofferyOmlette 0:f6e4e1bbb3fe 71 /* \brief Removes current node from list. Sets next node as current node or
GeofferyOmlette 0:f6e4e1bbb3fe 72 * if next node is null sets pointer to previous node.
GeofferyOmlette 0:f6e4e1bbb3fe 73 * Returns data pointer from removed node or NULL pointer if there is no current node.
GeofferyOmlette 0:f6e4e1bbb3fe 74 * Note that linked list does NOT free the data in current node. */
GeofferyOmlette 0:f6e4e1bbb3fe 75 extern void *sn_linked_list_remove_current_node(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 76
GeofferyOmlette 0:f6e4e1bbb3fe 77 /* \brief Updates current node to contain data given in the data parameter.
GeofferyOmlette 0:f6e4e1bbb3fe 78 * Note that this function does NOT free data that current node held before this function call.
GeofferyOmlette 0:f6e4e1bbb3fe 79 * If error is returned, nothing has been done. */
GeofferyOmlette 0:f6e4e1bbb3fe 80 extern int8_t sn_linked_list_update_current_node(sn_linked_list_t *linked_list, void *data);
GeofferyOmlette 0:f6e4e1bbb3fe 81
GeofferyOmlette 0:f6e4e1bbb3fe 82 /* \brief Returns number of nodes that are currently stored in list.
GeofferyOmlette 0:f6e4e1bbb3fe 83 * Note: if list contains over 65535 nodes, this function can NOT be used */
GeofferyOmlette 0:f6e4e1bbb3fe 84 extern uint16_t sn_linked_list_count_nodes(sn_linked_list_t *linked_list);
GeofferyOmlette 0:f6e4e1bbb3fe 85
GeofferyOmlette 0:f6e4e1bbb3fe 86 #endif /* SN_LINKED_LIST_H_ */
GeofferyOmlette 0:f6e4e1bbb3fe 87
GeofferyOmlette 0:f6e4e1bbb3fe 88 #ifdef __cplusplus
GeofferyOmlette 0:f6e4e1bbb3fe 89 }
GeofferyOmlette 0:f6e4e1bbb3fe 90 #endif