Me@3: /* Me@3: * Copyright 2010 OpenSourceCodeStewardshipFoundation Me@3: * Me@3: * Licensed under BSD Me@3: */ Me@3: Me@3: Me@3: Me@3: #include Me@3: #include Me@3: Me@3: Me@3: Me@3: /*make a struct with the sizes and a pointer to the Me@3: * array, but hide a reverse pointer at the front of the array that Me@3: * points back to the vector struct -- that way, can pass around the Me@3: * array when doing work on elements, but when need to increase size, Me@3: * get pointer to vector struct and use that, which will change the Me@3: * ptr to the array in the vector struc, and return the new pointer.. Me@3: * so from the point of changing size on, have the correct array ptr, Me@3: * and also all other places that initiate a sequence later will get Me@3: * the array ptr from the vector struct at the sequence start.. Me@3: */ Me@3: bool8 Me@3: addToVect( Vector *vect, void *ptrToElem ) Me@3: { int32 numPtrsInVect, sizeOfVect; Me@3: Me@3: /* Me@3: numPtrsInVect = *(vect -1); //num ptrs is "hidden" in front Me@3: sizeOfVect = *(vect -2); Me@3: */ Me@3: numPtrsInVect = vect->numPtrsInArray; Me@3: sizeOfVect = vect->sizeOfArray; Me@3: Me@3: if( numPtrsInVect >= sizeOfVect ) return FALSE; Me@3: Me@3: vect->arrayOfPtrs[numPtrsInVect] = ptrToElem; Me@3: vect->numPtrsInArray++; Me@3: } Me@3: Me@3: void ** Me@3: increaseSizeOfVect( Vector *vect ) Me@3: { int32 oldSizeOfArray, newSizeOfArray, i; Me@3: void **newArray, **oldArray; Me@3: Me@3: oldSizeOfArray = vect->sizeOfArray; Me@3: newSizeOfArray = oldSizeOfArray * 2; Me@3: oldArray = vect->arrayOfPtrs; Me@3: newArray = malloc( (newSizeOfArray + 1) * sizeof(void *) ); Me@3: *newArray = vect; Me@3: newArray++; Me@3: for( i = 0; i < oldSizeOfArray; i++ ) Me@3: { Me@3: newArray[i] = oldArray[i]; Me@3: } Me@3: vect->arrayOfPtrs = newArray; Me@3: vect->sizeOfArray = newSizeOfArray; Me@3: Me@3: free( oldArray -1 ); Me@3: return newArray; Me@3: } Me@3: Me@3: /* Me@3: bool8 Me@3: forAllInVectDo( ptrToFnTakesVectElemAsVoid* ) Me@3: { Me@3: return success; Me@3: } Me@3: */