Difference between pages "r6:Function:slist get user data from element" and "r6:Function:slist new"

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/slist/slist_new.c
  /inc/liblfds.h
  /inc/liblfds.h


==Prototype==
==Prototype==
  int slist_get_user_data_from_element( struct slist_element *se, void **user_data );
  int slist_new( struct slist_state **ss,
                void (*user_data_delete_function)(void *user_data, void *user_state),
                void *user_state );


==Parameters==
==Parameters==
''struct slist_element *se''
''struct slist_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 pointer to a pointer onto which is allocated the state which represents an slist.  Set to NULL if slist creation fails.


''void **user_data''
''void (*user_data_delete_function)(void *user_data, void *user_state)''
: A pointer to a pointer into which the user data will be placed.
: A callback function, which can be NULL.  This function is called with the user data void pointer from each element after that element is logically deleted, giving the user an opportunity to delete any allocated state.
 
''void *user_state''
: This is passed to each call of ''user_data_delete_function'' as the second argument to that function.  The user is expected to use this to pass state information into his delete function.


==Return Value==
==Return Value==
Returns 1 on success, 0 on failure. The only cause of failure is if you try to get the user data from an element which has been logically deleted.
Returns 1 on successful list creation, 0 otherwise. On failure, ''*ss'' will also be set to NULL.


==Notes==
==Notes==
This function gets the user data void pointer in the slist element.  
This function instantiates a slist.  The values of ''user_data_delete_function'' and ''user_state'' are stored in the slist state for later use by ''[[r6:Function:slist_delete|slist_delete]]'', ''[[r6:Function:slist_delete_element|slist_delete_element]]'' and ''[[r6:Function:slist_delete_all_elements|slist_delete_all_elements]]''.


==See Also==
==See Also==
* [[r6:API:SList|SList]]
* [[r6:API:SList|SList]]
* [[r6:Function:slist_set_user_data_in_element|slist_set_user_data_in_element]]
* [[r6:Function:slist_delete|slist_delete]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/slist/slist_new.c
/inc/liblfds.h

Prototype

int slist_new( struct slist_state **ss,
               void (*user_data_delete_function)(void *user_data, void *user_state),
               void *user_state );

Parameters

struct slist_state **ss

A pointer to a pointer onto which is allocated the state which represents an slist. Set to NULL if slist creation fails.

void (*user_data_delete_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 after that element is logically deleted, giving the user an opportunity to delete any allocated state.

void *user_state

This is passed to each call of user_data_delete_function as the second argument to that function. The user is expected to use this to pass state information into his delete function.

Return Value

Returns 1 on successful list creation, 0 otherwise. On failure, *ss will also be set to NULL.

Notes

This function instantiates a slist. The values of user_data_delete_function and user_state are stored in the slist state for later use by slist_delete, slist_delete_element and slist_delete_all_elements.

See Also