Updates to the betawidget library; being to document vector.[ch], fix a bug in vectorAdd, const correctness for the widget type system, remove a rouge newline in geom.h

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5315 4a71c877-e1ca-e34f-864e-861f7616d084
master
Freddie Witherden 2008-06-24 10:11:03 +00:00
parent 21a883121a
commit 2b0bd03914
5 changed files with 45 additions and 14 deletions

View File

@ -60,4 +60,3 @@ point pointAdd(point p, point q);
#endif /*GEOM_H_*/

View File

@ -3,7 +3,15 @@
#include "vector.h"
const int defaultSize = 4;
struct _vector
{
void **mem;
int size;
int head;
destroyCallback destroy;
};
static const int defaultSize = 4;
vector *vectorCreate(destroyCallback cb)
{
@ -53,6 +61,7 @@ void *vectorAdd(vector *v, void *object)
return NULL;
}
v->mem = newMem;
v->size *= 2;
}

View File

@ -4,27 +4,50 @@
typedef struct _vector vector;
typedef void (*destroyCallback) (void *object);
struct _vector
{
void **mem;
int size;
int head;
destroyCallback destroy;
};
/**
* Creates a new vector.
*
* @param destroyCb The callback function to call whenever an element is deleted
* or replaced.
* @return A pointer to the newly created vector on success; otherwise NULL.
*/
vector *vectorCreate(destroyCallback destroyCb);
/**
* Destroys the vector v. This is done by first calling the destroy callback
* function on each element in the vector then free'ing the vector itself.
*
* @param v The vector to destroy.
*/
void vectorDestroy(vector *v);
/**
* Adds object to the vector v.
*
* @param v The vector to add the object onto.
* @param object The object to add.
* @return A pointer to object.
*/
void *vectorAdd(vector *v, void *object);
/**
*
*/
void *vectorAt(vector *v, int index);
/**
*
*/
void *vectorSetAt(vector *v, int index, void *object);
/**
*
*/
void vectorRemoveAt(vector *v, int index);
/**
*
*/
int vectorSize(vector *v);
#endif /*VECTOR_H_*/

View File

@ -8,7 +8,7 @@ static widgetVtbl vtbl;
bool widgetIsA(widget *self, classInfo *instanceOf)
{
classInfo *widgetClass;
const classInfo *widgetClass;
// Transverse up the hierarchy
for (widgetClass = self->classInfo;

View File

@ -38,7 +38,7 @@ typedef enum _vAlign vAlign;
*/
struct _classInfo
{
struct _classInfo *parentType;
const struct _classInfo *parentType;
const char *ourType;
};
@ -269,7 +269,7 @@ struct _widget
/*
* The class (or subclass) that widget is (used for type checking)
*/
classInfo *classInfo;
const classInfo *classInfo;
/*
* Arbitary user-defined data