Minor cleanups in list implementation:
- Reconcile lam_list_item base class string debugging name - Use NULL instead of 0 - Ensure to decrement list length in remove_first() - Protect function prototypes from C++ munging - Add lam_list_get_begin() to be symmetrical with lam_list_get_end() This commit was SVN r497.
Этот коммит содержится в:
родитель
095ac4525e
Коммит
b9c2371df6
@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
lam_class_info_t lam_list_item_cls = {"lam_list_link_item_t", &lam_object_cls,
|
lam_class_info_t lam_list_item_cls = {"lam_list_item_t", &lam_object_cls,
|
||||||
(class_init_t) lam_list_item_init, (class_destroy_t)lam_obj_destroy};
|
(class_init_t) lam_list_item_init, (class_destroy_t)lam_obj_destroy};
|
||||||
lam_class_info_t lam_list_cls = {"lam_list_t", &lam_object_cls,
|
lam_class_info_t lam_list_cls = {"lam_list_t", &lam_object_cls,
|
||||||
(class_init_t)lam_list_init, (class_destroy_t)lam_list_destroy};
|
(class_init_t)lam_list_init, (class_destroy_t)lam_list_destroy};
|
||||||
@ -24,7 +24,7 @@ lam_class_info_t lam_list_cls = {"lam_list_t", &lam_object_cls,
|
|||||||
void lam_list_item_init(lam_list_item_t *item)
|
void lam_list_item_init(lam_list_item_t *item)
|
||||||
{
|
{
|
||||||
SUPER_INIT(item, lam_list_item_cls.cls_parent);
|
SUPER_INIT(item, lam_list_item_cls.cls_parent);
|
||||||
item->lam_list_next = item->lam_list_prev = 0;
|
item->lam_list_next = item->lam_list_prev = NULL;
|
||||||
item->lam_list_type = 0;
|
item->lam_list_type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,14 +38,15 @@ void lam_list_item_init(lam_list_item_t *item)
|
|||||||
void lam_list_init(lam_list_t *list)
|
void lam_list_init(lam_list_t *list)
|
||||||
{
|
{
|
||||||
SUPER_INIT(list, lam_list_cls.cls_parent);
|
SUPER_INIT(list, lam_list_cls.cls_parent);
|
||||||
list->lam_list_head.lam_list_next=&(list->lam_list_tail);
|
list->lam_list_head.lam_list_prev = NULL;
|
||||||
list->lam_list_head.lam_list_prev=(lam_list_item_t *)NULL;
|
list->lam_list_head.lam_list_next = &list->lam_list_tail;
|
||||||
list->lam_list_tail.lam_list_prev=(lam_list_item_t *)NULL;
|
list->lam_list_tail.lam_list_prev = &list->lam_list_head;
|
||||||
list->lam_list_tail.lam_list_prev=&(list->lam_list_head);
|
list->lam_list_tail.lam_list_next = NULL;
|
||||||
list->lam_list_type = 0;
|
list->lam_list_type = 0;
|
||||||
list->lam_list_length = 0;
|
list->lam_list_length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lam_list_destroy(lam_list_t *list)
|
void lam_list_destroy(lam_list_t *list)
|
||||||
{
|
{
|
||||||
/* release all items in list */
|
/* release all items in list */
|
||||||
@ -54,7 +55,6 @@ void lam_list_destroy(lam_list_t *list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds item to the end of the list.
|
* Adds item to the end of the list.
|
||||||
*
|
*
|
||||||
@ -65,7 +65,6 @@ void lam_list_destroy(lam_list_t *list)
|
|||||||
*/
|
*/
|
||||||
void lam_list_append(lam_list_t *list, lam_list_item_t *item)
|
void lam_list_append(lam_list_t *list, lam_list_item_t *item)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* set new element's previous pointer */
|
/* set new element's previous pointer */
|
||||||
item->lam_list_prev=list->lam_list_tail.lam_list_prev;
|
item->lam_list_prev=list->lam_list_tail.lam_list_prev;
|
||||||
|
|
||||||
@ -148,6 +147,9 @@ lam_list_item_t *lam_list_remove_first(lam_list_t *list)
|
|||||||
if ( 0 == list->lam_list_length )
|
if ( 0 == list->lam_list_length )
|
||||||
return (lam_list_item_t *)NULL;
|
return (lam_list_item_t *)NULL;
|
||||||
|
|
||||||
|
/* reset list length counter */
|
||||||
|
list->lam_list_length--;
|
||||||
|
|
||||||
/* get pointer to first element on the list */
|
/* get pointer to first element on the list */
|
||||||
item = list->lam_list_head.lam_list_next;
|
item = list->lam_list_head.lam_list_next;
|
||||||
|
|
||||||
|
@ -34,8 +34,14 @@ typedef struct lam_list_item
|
|||||||
struct lam_list_item *lam_list_prev;
|
struct lam_list_item *lam_list_prev;
|
||||||
} lam_list_item_t;
|
} lam_list_item_t;
|
||||||
|
|
||||||
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
void lam_list_item_init(lam_list_item_t *item);
|
void lam_list_item_init(lam_list_item_t *item);
|
||||||
void lam_list_item_destroy(lam_list_item_t *item);
|
void lam_list_item_destroy(lam_list_item_t *item);
|
||||||
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define lam_list_get_next(item) \
|
#define lam_list_get_next(item) \
|
||||||
((item) ? (((lam_list_item_t*)(item))->lam_list_next) : 0)
|
((item) ? (((lam_list_item_t*)(item))->lam_list_next) : 0)
|
||||||
@ -59,8 +65,14 @@ typedef struct lam_list
|
|||||||
} lam_list_t;
|
} lam_list_t;
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
void lam_list_init(lam_list_t *list);
|
void lam_list_init(lam_list_t *list);
|
||||||
void lam_list_destroy(lam_list_t *list);
|
void lam_list_destroy(lam_list_t *list);
|
||||||
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inlined accessor functions
|
* Inlined accessor functions
|
||||||
@ -102,6 +114,14 @@ static inline lam_list_item_t* lam_list_get_last(lam_list_t* list)
|
|||||||
return list->lam_list_tail.lam_list_prev;
|
return list->lam_list_tail.lam_list_prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns beginning of list, an invalid list entry.
|
||||||
|
*/
|
||||||
|
static inline lam_list_item_t* lam_list_get_begin(lam_list_t* list)
|
||||||
|
{
|
||||||
|
return &(list->lam_list_head);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns end of list, an invalid list entry.
|
* Returns end of list, an invalid list entry.
|
||||||
*/
|
*/
|
||||||
@ -152,6 +172,9 @@ static inline lam_list_item_t *lam_list_remove_item
|
|||||||
return item->lam_list_prev;
|
return item->lam_list_prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Adds item to the end of the list but does not retain item.
|
* Adds item to the end of the list but does not retain item.
|
||||||
*/
|
*/
|
||||||
@ -175,7 +198,6 @@ int lam_list_insert(lam_list_t *list, lam_list_item_t *item, long long idx);
|
|||||||
/*
|
/*
|
||||||
* Adds item to the front of the list and retains item.
|
* Adds item to the front of the list and retains item.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void lam_list_prepend(lam_list_t *list, lam_list_item_t *item);
|
void lam_list_prepend(lam_list_t *list, lam_list_item_t *item);
|
||||||
|
|
||||||
|
|
||||||
@ -189,5 +211,8 @@ lam_list_item_t *lam_list_remove_first(lam_list_t *list);
|
|||||||
* Removes and returns last item on list.
|
* Removes and returns last item on list.
|
||||||
*/
|
*/
|
||||||
lam_list_item_t *lam_list_remove_last(lam_list_t *list);
|
lam_list_item_t *lam_list_remove_last(lam_list_t *list);
|
||||||
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* LAM_LIST_H */
|
#endif /* LAM_LIST_H */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user