2010-06-03 21:24:43 +08:00
|
|
|
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
|
|
|
See the COPYRIGHT file for more information. */
|
|
|
|
#ifndef NCLIST_H
|
|
|
|
#define NCLIST_H 1
|
|
|
|
|
|
|
|
/* Define the type of the elements in the list*/
|
|
|
|
|
|
|
|
#if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__)
|
|
|
|
#define EXTERNC extern "C"
|
|
|
|
#else
|
|
|
|
#define EXTERNC extern
|
|
|
|
#endif
|
|
|
|
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int nclistnull(void*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
typedef struct NClist {
|
2012-08-20 05:12:35 +08:00
|
|
|
unsigned long alloc;
|
|
|
|
unsigned long length;
|
|
|
|
void** content;
|
2010-06-03 21:24:43 +08:00
|
|
|
} NClist;
|
|
|
|
|
|
|
|
EXTERNC NClist* nclistnew(void);
|
|
|
|
EXTERNC int nclistfree(NClist*);
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int nclistsetalloc(NClist*,unsigned long);
|
|
|
|
EXTERNC int nclistsetlength(NClist*,unsigned long);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Set the ith element */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int nclistset(NClist*,unsigned long,void*);
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Get value at position i */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC void* nclistget(NClist*,unsigned long);/* Return the ith element of l */
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Insert at position i; will push up elements i..|seq|. */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int nclistinsert(NClist*,unsigned long,void*);
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Remove element at position i; will move higher elements down */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC void* nclistremove(NClist* l, unsigned long i);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Tail operations */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int nclistpush(NClist*,void*); /* Add at Tail */
|
|
|
|
EXTERNC void* nclistpop(NClist*);
|
|
|
|
EXTERNC void* nclisttop(NClist*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Duplicate and return the content (null terminate) */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC void** nclistdup(NClist*);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Look for value match */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int nclistcontains(NClist*, void*);
|
2010-12-16 05:45:05 +08:00
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Remove element by value; only removes first encountered */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int nclistelemremove(NClist* l, void* elem);
|
2011-11-14 12:20:19 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* remove duplicates */
|
|
|
|
EXTERNC int nclistunique(NClist*);
|
2010-12-16 05:45:05 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Create a clone of a list */
|
|
|
|
EXTERNC NClist* nclistclone(NClist*);
|
|
|
|
|
|
|
|
/* Following are always "in-lined"*/
|
2012-08-20 05:12:35 +08:00
|
|
|
#define nclistclear(l) nclistsetlength((l),0)
|
2010-06-03 21:24:43 +08:00
|
|
|
#define nclistextend(l,len) nclistsetalloc((l),(len)+(l->alloc))
|
2012-08-09 07:15:18 +08:00
|
|
|
#define nclistcontents(l) ((l)==NULL?NULL:(l)->content)
|
2012-08-20 05:12:35 +08:00
|
|
|
#define nclistlength(l) ((l)==NULL?0:(l)->length)
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#endif /*NCLIST_H*/
|