Xmd/libXmd/include/Xmd/Buffer.h
2023-11-09 23:23:44 -05:00

43 lines
1.7 KiB
C

#ifndef _XmdBuffer_h
#define _XmdBuffer_h
#include <X11/Intrinsic.h>
/* Buffer is a struct that keeps track of a variable length array of data. It
is like a piggy bank, you can add stuff to it and then break it to get access
to all the things you put in. It is intended to be used for reading in
variable length strings and files. */
typedef struct _XmdBuffer XmdBuffer;
/* XmdBufferNew creates a new buffer that contains the specified type. */
#define XmdBufferNew(type) _XmdBufferNew(sizeof(type));
XmdBuffer *_XmdBufferNew (Cardinal size);
/* XmdBufferPush adds a new element to the buffer. If element is NULL, the new
element in the buffer is set to all zeros. */
void XmdBufferPush (XmdBuffer *buffer, void *element);
/* XmdBufferPop copies the last element into element, and removes it from the
buffer. If element is NULL, it removes the element without copying it. */
void XmdBufferPop (XmdBuffer *buffer, void *element);
/* XmdBufferPoke sets a single element of the buffer. If element is NULL, the
element in the buffer is instead set to all zeros. */
void XmdBufferPoke (XmdBuffer *buffer, Cardinal index, void *element);
/* XmdBufferPeek copies the value of a single element of the buffer into
element. If element is NULL, this function does nothing. */
void XmdBufferPeek (XmdBuffer *buffer, Cardinal index, void *element);
/* XmdBufferBreak frees the buffer without freeing its data. Its data is
returned and must be freed manually using XtFree() at some point. */
void *XmdBufferBreak (XmdBuffer *buffer);
/* XmdBufferLength returns the amount of elements stored in a buffer. */
Cardinal XmdBufferLength (XmdBuffer *buffer);
/* XmdBufferFree frees the buffer and any data associated with it. */
void XmdBufferFree (XmdBuffer *buffer);
#endif