Difference between pages "r6:Function:slist set user data in element" and "r6:Function:stack clear"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
==Source Files==
==Source Files==
  /src/slist/slist_get_and_set.c
  /src/stack/stack_delete.c
  /inc/liblfds.h
  /inc/liblfds.h


==Prototype==
==Prototype==
  int slist_set_user_data_in_element( struct slist_element *se, void *user_data );
  void stack_clear( struct stack_state *ss,
                  void (*user_data_clear_function)(void *user_data, void *user_state),
                  void *user_state );


==Parameters==
==Parameters==
''struct slist_element *se''
''struct stack_state *ss''
: A pointer to an slist element as allocated by ''[[r6:Function:slist_new_head|slist_new_head]]'' or ''[[r6:Function:slist_new_next|slist_new_next]]''.
: A stack state as allocated by ''[[r6:Function:stack_new|stack_new]]''.


''void *user_data''
''void (*user_data_init_function)(void *user_data, void *user_state)''
: A void pointer of user data which will be placed into the slist element.
: A callback function, which can be NULL.  This function is called with the user data void pointer from each element before that element is popped, giving the user an opportunity to delete any allocated state.
 
''void *user_state''
: This pointer is passed into the ''user_data_init_function'' as its second argument, enabling the caller to pass state into the callback function.


==Return Value==
==Return Value==
Returns 1 on success, 0 on failure.  The only cause of failure is if you try to set the user data in an element which has been logically deleted.
No return value.


==Notes==
==Notes==
This function sets the user data void pointer in the slist element.
This function empties the stack, popping every element.  Each element, after being popped, is passed to ''user_data_clear_function''.


==See Also==
==See Also==
* [[r6:API:SList|SList]]
* [[r6:API:Stack|Stack]]
* [[r6:Function:slist_get_user_data_from_element|slist_get_user_data_from_element]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/stack/stack_delete.c
/inc/liblfds.h

Prototype

void stack_clear( struct stack_state *ss,
                  void (*user_data_clear_function)(void *user_data, void *user_state),
                  void *user_state );

Parameters

struct stack_state *ss

A stack state as allocated by stack_new.

void (*user_data_init_function)(void *user_data, void *user_state)

A callback function, which can be NULL. This function is called with the user data void pointer from each element before that element is popped, giving the user an opportunity to delete any allocated state.

void *user_state

This pointer is passed into the user_data_init_function as its second argument, enabling the caller to pass state into the callback function.

Return Value

No return value.

Notes

This function empties the stack, popping every element. Each element, after being popped, is passed to user_data_clear_function.

See Also