#ifndef LLIST_H
#define LLIST_H

#include <stddef.h>

#define LDATA_STR_SIZE 80

typedef struct lnode lnode;
typedef struct llist llist;

/* unused yet
typedef enum llfindflags
{
    LLFIND_FWD =    0x0001,
    LLFIND_REV =    0x0002,

    LLFIND_LT =     0x0010,
    LLFIND_GT =     0x0020,
    LLFIND_EQ =     0x0030

} llfindflags;
*/

/*  list callbacks
    ==============
*/

/*  ldata_free_cb:
    a callback to free data pointed to by lnode
    if unset, the list will simply use free().
*/
typedef void    (*ldata_free_cb)(      void* data );

/*  ldata_dup_cb:
    a callback to duplicate data pointed to by lnode
    if unset, the list will simply use malloc and memcpy.
*/
typedef void*   (*ldata_dup_cb)( const void* data );

/*  ldata_cmp_cb:
    a callback to compare items of data pointed to by
    two lnodes.

    returns:
        -1  d1 < d2
        0   d1 == d2
        1   d1 > d2
*/
typedef int     (*ldata_cmp_cb)( const void* d1,
                                 const void* d2   );

/*  ldata_sel_cb
    a callback to determe if the selected flag of an
    lnode should be true or false.
*/
typedef _Bool   (*ldata_sel_cb)( const void* data,
                                 const void* crit );

/*  ldata_edit_cb
    a callback which will edit the data pointed to by
    an lnode.
*/
typedef void    (*ldata_edit_cb)(      void* data,
                                 const void* val  );

/*  ldata_copy_cb
    a callback to be used for copying data items.
    if unset, the list will simply use memcpy.
*/
typedef void    (*ldata_copy_cb)(      void* dest,
                                 const void* src  );

/*  ldata_mod_cb
    a callback which can be used to modify data during
    copy/cut operations on a list. (ie for items containing
    positional information, you may want to adjust the cut/copied
    data to start from position zero. )
*/
typedef void    (*ldata_mod_cb)( void* data, void* init);

/*  ldata_dump_cb
    a callback to display the contents of the data
*/
typedef void    (*ldata_dump_cb)(const void* data );


/*  ldata_str_cb
    a callback used to get a string representation of an item
    of data stored in the list.
*/
typedef char*   (*ldata_str_cb)(const void* data, int level);


/************************************************************************
    lnode
 ************************************************************************/

void*   lnode_data(const lnode*);
lnode*  lnode_prev(const lnode*);
lnode*  lnode_next(const lnode*);

void    lnode_select(lnode*);
void    lnode_unselect(lnode*);
_Bool   lnode_selected(const lnode*);

/*  lnode_dump dumps contents of an lnode, prefixed by msg string
    and suffixed by the string returned by the ldata_str_cb callback.
    level is how verbose the callback should be. 0 none, 1 a little, etc.
*/
void    lnode_dump(const char* msg, const lnode*,
                   ldata_str_cb, int level);


/************************************************************************
    llist
 ************************************************************************/

llist*  llist_new(  size_t data_size,
                    ldata_free_cb,   // only if data needs ptrs free'd
                    ldata_dup_cb,    // only if data cannot be memcpy'd
                    ldata_copy_cb,   // only if data cannot be memcpy'd
                    ldata_cmp_cb,    // for sorted insertion
                    ldata_str_cb );

llist*  llist_dup(  llist*);

void    llist_free( llist*);

lnode*  llist_head(   const llist*);
lnode*  llist_tail(   const llist*);
size_t  llist_lnode_count(  const llist*);

lnode*  llist_unlink(   llist*, lnode*);
lnode*  llist_add_data( llist*, void* data);

lnode*  llist_select(       const llist*, ldata_sel_cb, const void* crit);
lnode*  llist_select_invert(const llist*);
void    llist_select_all(   const llist*, _Bool sel);

llist*  llist_cut(      llist*, _Bool sel, ldata_mod_cb, void* mod);
llist*  llist_copy(     llist*, _Bool sel, ldata_mod_cb, void* mod);
void    llist_delete(   llist*, _Bool sel);

void    llist_paste(llist* dest,
                    const llist* src,
                    ldata_edit_cb,
                    void* offset     );

void    llist_edit( llist*, ldata_edit_cb, void* val, _Bool sel);

void    llist_sort( llist*);

void*   llist_to_array(const llist*);

void    llist_dump(const llist*, ldata_dump_cb);

#endif


_______________________________________________
NetBehaviour mailing list
[email protected]
http://www.netbehaviour.org/mailman/listinfo/netbehaviour

Reply via email to