#ifndef __ARRAY_H__ #define __ARRAY_H__ #include "utility.h" /**********************************************************/ /* This object is an array with dynamic table size. */ /* methods: */ /* init(addr of the array, size per entry, size) */ /* The array's type depends on what user want to */ /* store. For example: if you want an array for int, */ /* you should decleare like "int* v", and call the */ /* init() like this "init(&v, sizeof(int), 5)", and */ /* it will initalize an array with 5 elements. */ /* */ /* free(addr of the array) */ /* Free the memory the array use. Yous should call */ /* it when you don't need the container. */ /* */ /* */ /* getSize(addr of the array) */ /* Return the number of elements. */ /* */ /* getEntrySize(addr of the array) */ /* Return the size per entry, it dependent on what */ /* type of data you store in the container. */ /* */ /* getEntry(addr of the array, index) */ /* Return a const pointer which point to the entry */ /* with the index you give. */ /* */ /* */ /* setSize(addr of the array, new_size) */ /* Resize the table to new_size. Note that it won't */ /* initalize the newly element if you increase size. */ /* */ /* setEntry(addr of the array, index, data) */ /* Let the element with index you give be data. */ /* */ /* */ /* addBack(addr of the array, data) */ /* Add an element which contain data at the back of */ /* the array. */ /* */ /* delBack(addr of the array) */ /* Remove the last element of the array. */ /* */ /* addFront(addr of the array, data) !! UNFINISHED !! */ /* Add an element which contain data at the front of */ /* the array. */ /* */ /* delFront(addr of the array) !! UNFINISHED !! */ /* Remove the first element of the array. */ /* */ /* */ /* cat(addr of the v1, addr of the v2) */ /* Concatenate the array2 to the back of array1. */ /* */ /* copy(addr of the v1, addr of the v2) */ /* Let the contain in the v1 be the one in the v2 */ /* */ /* replace(addr of the v1, a, b, addr of the v2, x, y) */ /* If b == 0, it will insert v2[x ... x+y-1] into */ /* the place between v[a] */ /* and v[a-1] */ /* If y >= 0, it will replace v1[a ... a+b-1] */ /* to v2[x ... x+y-1] */ /* If y < 0, it will replace v1[a ... a+b-1] */ /* to v2[x-y-1 ... x] with */ /* reverse order. */ /* */ /**********************************************************/ pvoid ctl_array_initX(ppvoid v, size_t size, uint count); pvoid ctl_array_freeX(ppvoid v); int ctl_array_getSizeX (ppvoid v); pvoid ctl_array_getEntryX (ppvoid v, uint index); int ctl_array_getEntrySizeX(ppvoid v); int ctl_array_setSizeX (ppvoid v, uint count); pvoid ctl_array_setEntryX(ppvoid v, uint index, pcvoid data); int ctl_array_addBackX (ppvoid v, pcvoid entry); int ctl_array_delBackX (ppvoid v); //int ctl_array_addFrontX(ppvoid v, pcvoid entry); //int ctl_array_delFrontX(ppvoid v); int ctl_array_catX (ppvoid v, ppcvoid v2); pvoid ctl_array_copyX (ppvoid v, ppcvoid v2); int ctl_array_replaceX(ppvoid v , uint i1, uint ct1, ppcvoid v2, uint j1, int ct2); #define ctl_array_init(X,Y,Z) ctl_array_initX(ppVoid(X),Y,Z) #define ctl_array_free(X) ctl_array_freeX(ppVoid(X)) #define ctl_array_getSize(X) ctl_array_getSizeX (ppVoid(X)) #define ctl_array_getEntry(X,Y) ctl_array_getEntryX (ppVoid(X),Y) #define ctl_array_getEntrySize(X) ctl_array_getEntrySizeX(ppVoid(X)) #define ctl_array_setSize(X,Y) ctl_array_setSizeX (ppVoid(X),Y) #define ctl_array_setEntry(X,Y,Z) ctl_array_setEntryX(ppVoid(X),Y,pcVoid(Z)) #define ctl_array_addBack(X,Y) ctl_array_addBackX(ppVoid(X),pcVoid(Y)) #define ctl_array_delBack(X) ctl_array_delBackX(ppVoid(X)) //#define ctl_array_addFront(X,Y) ctl_array_addBackX(ppVoid(X),pcVoid(Y)) //#define ctl_array_delFront(X) ctl_array_delBackX(ppVoid(X)) #define ctl_array_cat(X,Y) ctl_array_catX (ppVoid(X),ppcVoid(Y)) #define ctl_array_copy(X,Y) ctl_array_copyX(ppVoid(X),ppcVoid(Y)) #define ctl_array_replace(X,Y,Z,A,B,C) ctl_array_replaceX( ppVoid(X),Y,Z,\ ppcVoid(A),B,C) #endif /* __ARRAY_H_ */