1 /***************************************************************************** 2 * list.h 3 ***************************************************************************** 4 * Copyright (C) 2010-2017 L-SMASH project 5 * 6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com> 7 * 8 * Permission to use, copy, modify, and/or distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 *****************************************************************************/ 20 21 /* This file is available under an ISC license. */ 22 23 typedef void (*lsmash_entry_data_eliminator)( void *data ); /* very same as free() of standard C lib; void free( void * ); 24 * If 'data' is equal to NULL, the eliminator must do nothing. */ 25 26 typedef struct lsmash_entry_tag lsmash_entry_t; 27 28 struct lsmash_entry_tag 29 { 30 lsmash_entry_t *next; 31 lsmash_entry_t *prev; 32 void *data; 33 }; 34 35 typedef struct 36 { 37 lsmash_entry_t *head; 38 lsmash_entry_t *tail; 39 lsmash_entry_t *last_accessed_entry; 40 uint32_t last_accessed_number; 41 uint32_t entry_count; 42 lsmash_entry_data_eliminator eliminator; 43 } lsmash_entry_list_t; 44 45 /* Utility macros to avoid 'lsmash_entry_data_eliminator' casts to the 'eliminator' argument */ 46 #define lsmash_list_init( list, eliminator ) \ 47 lsmash_list_init_orig( list, (lsmash_entry_data_eliminator)(eliminator) ) 48 #define lsmash_list_init_simple( list ) \ 49 lsmash_list_init_orig( list, (lsmash_entry_data_eliminator)lsmash_free ) 50 51 #define lsmash_list_create( eliminator ) \ 52 lsmash_list_create_orig( (lsmash_entry_data_eliminator)(eliminator) ) 53 #define lsmash_list_create_simple() \ 54 lsmash_list_create_orig( (lsmash_entry_data_eliminator)lsmash_free ) 55 56 /* functions for internal usage */ 57 void lsmash_list_init_orig 58 ( 59 lsmash_entry_list_t *list, 60 lsmash_entry_data_eliminator eliminator 61 ); 62 63 lsmash_entry_list_t *lsmash_list_create_orig 64 ( 65 lsmash_entry_data_eliminator eliminator 66 ); 67 68 void lsmash_list_destroy 69 ( 70 lsmash_entry_list_t *list 71 ); 72 73 int lsmash_list_add_entry 74 ( 75 lsmash_entry_list_t *list, 76 void *data 77 ); 78 79 int lsmash_list_remove_entry_direct 80 ( 81 lsmash_entry_list_t *list, 82 lsmash_entry_t *entry 83 ); 84 85 int lsmash_list_remove_entry 86 ( 87 lsmash_entry_list_t *list, 88 uint32_t entry_number 89 ); 90 91 int lsmash_list_remove_entry_tail 92 ( 93 lsmash_entry_list_t *list 94 ); 95 96 void lsmash_list_remove_entries 97 ( 98 lsmash_entry_list_t *list 99 ); 100 101 void lsmash_list_move_entries 102 ( 103 lsmash_entry_list_t *dst, 104 lsmash_entry_list_t *src 105 ); 106 107 lsmash_entry_t *lsmash_list_get_entry 108 ( 109 lsmash_entry_list_t *list, 110 uint32_t entry_number 111 ); 112 113 void *lsmash_list_get_entry_data 114 ( 115 lsmash_entry_list_t *list, 116 uint32_t entry_number 117 ); 118