2012-08-01 04:34:13 +08:00
|
|
|
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
|
|
|
See the COPYRIGHT file for more information. */
|
|
|
|
#ifndef OCLIST_H
|
|
|
|
#define OCLIST_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 oclistnull(void*);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
typedef struct OClist {
|
2014-03-09 11:41:30 +08:00
|
|
|
size_t alloc;
|
|
|
|
size_t length;
|
2012-08-20 05:12:35 +08:00
|
|
|
void** content;
|
2012-08-01 04:34:13 +08:00
|
|
|
} OClist;
|
|
|
|
|
2012-08-09 07:15:18 +08:00
|
|
|
EXTERNC OClist* oclistnew(void);
|
2012-08-01 04:34:13 +08:00
|
|
|
EXTERNC int oclistfree(OClist*);
|
2014-03-09 11:41:30 +08:00
|
|
|
EXTERNC int oclistsetalloc(OClist*,size_t);
|
|
|
|
EXTERNC int oclistsetlength(OClist*,size_t);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Set the ith element */
|
2014-03-09 11:41:30 +08:00
|
|
|
EXTERNC int oclistset(OClist*,size_t,void*);
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Get value at position i */
|
2014-03-09 11:41:30 +08:00
|
|
|
EXTERNC void* oclistget(OClist*,size_t);/* Return the ith element of l */
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Insert at position i; will push up elements i..|seq|. */
|
2014-03-09 11:41:30 +08:00
|
|
|
EXTERNC int oclistinsert(OClist*,size_t,void*);
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Remove element at position i; will move higher elements down */
|
2014-03-09 11:41:30 +08:00
|
|
|
EXTERNC void* oclistremove(OClist* l, size_t i);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Tail operations */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int oclistpush(OClist*,void*); /* Add at Tail */
|
|
|
|
EXTERNC void* oclistpop(OClist*);
|
|
|
|
EXTERNC void* oclisttop(OClist*);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Duplicate and return the content (null terminate) */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC void** oclistdup(OClist*);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Look for value match */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int oclistcontains(OClist*, void*);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2012-08-09 07:15:18 +08:00
|
|
|
/* Remove element by value; only removes first encountered */
|
2012-08-20 05:12:35 +08:00
|
|
|
EXTERNC int oclistelemremove(OClist* l, void* elem);
|
2012-08-09 07:15:18 +08:00
|
|
|
|
|
|
|
/* remove duplicates */
|
|
|
|
EXTERNC int oclistunique(OClist*);
|
|
|
|
|
|
|
|
/* Create a clone of a list */
|
|
|
|
EXTERNC OClist* oclistclone(OClist*);
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Following are always "in-lined"*/
|
2012-08-20 05:12:35 +08:00
|
|
|
#define oclistclear(l) oclistsetlength((l),0)
|
2012-08-01 04:34:13 +08:00
|
|
|
#define oclistextend(l,len) oclistsetalloc((l),(len)+(l->alloc))
|
2012-08-09 07:15:18 +08:00
|
|
|
#define oclistcontents(l) ((l)==NULL?NULL:(l)->content)
|
2012-08-20 05:12:35 +08:00
|
|
|
#define oclistlength(l) ((l)==NULL?0:(l)->length)
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
#endif /*OCLIST_H*/
|