netcdf-c/include/nclist.h

63 lines
1.8 KiB
C
Raw Normal View History

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
EXTERNC int nclistnull(void*);
2010-06-03 21:24:43 +08:00
typedef struct NClist {
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*);
EXTERNC int nclistsetalloc(NClist*,unsigned long);
EXTERNC int nclistsetlength(NClist*,unsigned long);
2010-06-03 21:24:43 +08:00
/* Set the ith element */
EXTERNC int nclistset(NClist*,unsigned long,void*);
2010-06-03 21:24:43 +08:00
/* Get value at position i */
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|. */
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 */
EXTERNC void* nclistremove(NClist* l, unsigned long i);
2010-06-03 21:24:43 +08:00
/* Tail operations */
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) */
EXTERNC void** nclistdup(NClist*);
2010-06-03 21:24:43 +08:00
/* Look for value match */
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 */
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"*/
#define nclistclear(l) nclistsetlength((l),0)
2010-06-03 21:24:43 +08:00
#define nclistextend(l,len) nclistsetalloc((l),(len)+(l->alloc))
#define nclistcontents(l) ((l)==NULL?NULL:(l)->content)
#define nclistlength(l) ((l)==NULL?0:(l)->length)
2010-06-03 21:24:43 +08:00
#endif /*NCLIST_H*/