ban4jp -
/
BTstack_test
https://mbed.org/forum/ja/topic/4890/
Fork of BTstack by
BTstack/btstack/linked_list.h@3:316daabf0d24, 2014-05-09 (annotated)
- Committer:
- ban4jp
- Date:
- Fri May 09 15:54:35 2014 +0000
- Revision:
- 3:316daabf0d24
- Parent:
- 0:1ed23ab1345f
??????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:1ed23ab1345f | 1 | /* |
va009039 | 0:1ed23ab1345f | 2 | * Copyright (C) 2009 by Matthias Ringwald |
va009039 | 0:1ed23ab1345f | 3 | * |
va009039 | 0:1ed23ab1345f | 4 | * Redistribution and use in source and binary forms, with or without |
va009039 | 0:1ed23ab1345f | 5 | * modification, are permitted provided that the following conditions |
va009039 | 0:1ed23ab1345f | 6 | * are met: |
va009039 | 0:1ed23ab1345f | 7 | * |
va009039 | 0:1ed23ab1345f | 8 | * 1. Redistributions of source code must retain the above copyright |
va009039 | 0:1ed23ab1345f | 9 | * notice, this list of conditions and the following disclaimer. |
va009039 | 0:1ed23ab1345f | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
va009039 | 0:1ed23ab1345f | 11 | * notice, this list of conditions and the following disclaimer in the |
va009039 | 0:1ed23ab1345f | 12 | * documentation and/or other materials provided with the distribution. |
va009039 | 0:1ed23ab1345f | 13 | * 3. Neither the name of the copyright holders nor the names of |
va009039 | 0:1ed23ab1345f | 14 | * contributors may be used to endorse or promote products derived |
va009039 | 0:1ed23ab1345f | 15 | * from this software without specific prior written permission. |
va009039 | 0:1ed23ab1345f | 16 | * |
va009039 | 0:1ed23ab1345f | 17 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
va009039 | 0:1ed23ab1345f | 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
va009039 | 0:1ed23ab1345f | 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
va009039 | 0:1ed23ab1345f | 20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
va009039 | 0:1ed23ab1345f | 21 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
va009039 | 0:1ed23ab1345f | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
va009039 | 0:1ed23ab1345f | 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
va009039 | 0:1ed23ab1345f | 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
va009039 | 0:1ed23ab1345f | 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
va009039 | 0:1ed23ab1345f | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
va009039 | 0:1ed23ab1345f | 27 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
va009039 | 0:1ed23ab1345f | 28 | * SUCH DAMAGE. |
va009039 | 0:1ed23ab1345f | 29 | * |
va009039 | 0:1ed23ab1345f | 30 | */ |
va009039 | 0:1ed23ab1345f | 31 | |
va009039 | 0:1ed23ab1345f | 32 | /* |
va009039 | 0:1ed23ab1345f | 33 | * linked_list.h |
va009039 | 0:1ed23ab1345f | 34 | * |
va009039 | 0:1ed23ab1345f | 35 | * Created by Matthias Ringwald on 7/13/09. |
va009039 | 0:1ed23ab1345f | 36 | */ |
va009039 | 0:1ed23ab1345f | 37 | |
va009039 | 0:1ed23ab1345f | 38 | #pragma once |
va009039 | 0:1ed23ab1345f | 39 | |
va009039 | 0:1ed23ab1345f | 40 | #if defined __cplusplus |
va009039 | 0:1ed23ab1345f | 41 | extern "C" { |
va009039 | 0:1ed23ab1345f | 42 | #endif |
va009039 | 0:1ed23ab1345f | 43 | |
va009039 | 0:1ed23ab1345f | 44 | typedef struct linked_item { |
va009039 | 0:1ed23ab1345f | 45 | struct linked_item *next; // <-- next element in list, or NULL |
va009039 | 0:1ed23ab1345f | 46 | void *user_data; // <-- pointer to struct base |
va009039 | 0:1ed23ab1345f | 47 | } linked_item_t; |
va009039 | 0:1ed23ab1345f | 48 | |
va009039 | 0:1ed23ab1345f | 49 | typedef linked_item_t * linked_list_t; |
va009039 | 0:1ed23ab1345f | 50 | |
va009039 | 0:1ed23ab1345f | 51 | void linked_item_set_user(linked_item_t *item, void *user_data); // <-- set user data |
va009039 | 0:1ed23ab1345f | 52 | void * linked_item_get_user(linked_item_t *item); // <-- get user data |
va009039 | 0:1ed23ab1345f | 53 | int linked_list_empty(linked_list_t * list); |
va009039 | 0:1ed23ab1345f | 54 | void linked_list_add(linked_list_t * list, linked_item_t *item); // <-- add item to list as first element |
va009039 | 0:1ed23ab1345f | 55 | void linked_list_add_tail(linked_list_t * list, linked_item_t *item); // <-- add item to list as last element |
va009039 | 0:1ed23ab1345f | 56 | int linked_list_remove(linked_list_t * list, linked_item_t *item); // <-- remove item from list |
va009039 | 0:1ed23ab1345f | 57 | linked_item_t * linked_list_get_last_item(linked_list_t * list); // <-- find the last item in the list |
va009039 | 0:1ed23ab1345f | 58 | |
va009039 | 0:1ed23ab1345f | 59 | void test_linked_list(void); |
va009039 | 0:1ed23ab1345f | 60 | |
va009039 | 0:1ed23ab1345f | 61 | #if defined __cplusplus |
va009039 | 0:1ed23ab1345f | 62 | } |
va009039 | 0:1ed23ab1345f | 63 | #endif |