BlitzMax Extended  0.8.11
Pushing Blitz to the Max.
blitz_array.h
Go to the documentation of this file.
00001 
00011 #ifndef BLITZ_ARRAY_H
00012 #define BLITZ_ARRAY_H
00013 
00014 #include "_common.h"
00015 
00016 #include "blitz_class.h"
00017 #include "blitz_object.h"
00018 
00019 BB_BEGIN_DECLS
00020 
00042 struct BBArray
00043 {
00049     BBClass*        clas;
00050     int             refs;
00051     
00053     const char*     type;
00054 
00056     BBSize          dims;
00057     
00063     BBSize          size;
00064 
00070     BBSize          scales[1];
00071 };
00072 
00073 #define BBARRAY_HEADER_SIZE         (sizeof (BBArray) - sizeof (int))
00074 
00075 //  Maximum value of an array's data
00076 #define BBARRAY_MAX_DATASIZE        (BBSIZE_MAX - sizeof (BBArray))
00077 
00078 //  Absolute maximum length (value of scales[0]) of an array
00079 //  Depends on the data type the array stores
00080 #define BBARRAY_MAX_LENGTH          (BBARRAY_MAX_DATASIZE)
00081 
00097 #define BBARRAY_SIZE_CALC(size, num_dims) \
00098     (BBARRAY_HEADER_SIZE + (num_dims) * sizeof (int) + (size))
00099 
00107 #define BBARRAY_SIZE(arr)           BBARRAY_SIZE_CALC ((arr)->size, (arr)->dims)
00108 
00117 #define BBARRAY_DATAPTR_CALC(arr, num_dims) \
00118 ((void *)                                                                       \
00119     ((char *)(arr) + BBARRAY_HEADER_SIZE + (num_dims) * sizeof (int))           \
00120 )
00121 
00132 #define BBARRAY_DATAPTR(arr)        BBARRAY_DATAPTR_CALC((arr), (arr)->dims)
00133 
00154 #define BBARRAY_ALLOC(size, dims, flags) \
00155     ({                                                                          \
00156         (BBArray *)                                                             \
00157         bbGCAllocObject(                                                        \
00158             BBARRAY_SIZE_CALC((size), (dims)),                                  \
00159             &bbArrayClass,                                                      \
00160             (flags)                                                             \
00161         );                                                                      \
00162     })
00163 
00167 extern BBClass bbArrayClass;
00168 
00172 extern BBArray bbEmptyArray;
00173 
00178 #define BBNULLARRAY             (&bbEmptyArray)
00179 
00180 typedef struct BBByteArray      BBByteArray;
00181 typedef struct BBShortArray     BBShortArray;
00182 typedef struct BBIntArray       BBIntArray;
00183 typedef struct BBLongArray      BBLongArray;
00184 typedef struct BBFloatArray     BBFloatArray;
00185 typedef struct BBDoubleArray    BBDoubleArray;
00186 typedef struct BBObjectArray    BBObjectArray;
00187 typedef struct BBStringArray    BBStringArray;
00188 typedef struct BBArrayArray     BBArrayArray;
00189 
00194 struct BBByteArray
00195 {
00196     BBClass         *clas;
00197     int             refs;
00198     
00199     const char      *type;
00200     BBSize          dims;
00201     BBSize          size;
00202     BBSize          scales[1];
00203     
00204     BBByte          data[];
00205 };
00206 
00211 struct BBShortArray
00212 {
00213     BBClass         *clas;
00214     int             refs;
00215     
00216     const char      *type;
00217     BBSize          dims;
00218     BBSize          size;
00219     BBSize          scales[1];
00220     
00221     BBShort         data[];
00222 };
00223 
00228 struct BBIntArray
00229 {
00230     BBClass         *clas;
00231     int             refs;
00232     
00233     const char      *type;
00234     BBSize          dims;
00235     BBSize          size;
00236     BBSize          scales[1];
00237     
00238     BBInt           data[];
00239 };
00240 
00245 struct BBLongArray
00246 {
00247     BBClass         *clas;
00248     int             refs;
00249     
00250     const char      *type;
00251     BBSize          dims;
00252     BBSize          size;
00253     BBSize          scales[1];
00254     
00255     BBLong          data[];
00256 };
00257 
00262 struct BBFloatArray
00263 {
00264     BBClass         *clas;
00265     int             refs;
00266     
00267     const char      *type;
00268     BBSize          dims;
00269     BBSize          size;
00270     BBSize          scales[1];
00271     
00272     BBFloat         data[];
00273 };
00274 
00279 struct BBDoubleArray
00280 {
00281     BBClass         *clas;
00282     int             refs;
00283     
00284     const char      *type;
00285     BBSize          dims;
00286     BBSize          size;
00287     BBSize          scales[1];
00288     
00289     BBDouble        data[];
00290 };
00291 
00296 struct BBObjectArray
00297 {
00298     BBClass         *clas;
00299     int             refs;
00300     
00301     const char      *type;
00302     BBSize          dims;
00303     BBSize          size;
00304     BBSize          scales[1];
00305     
00306     BBObject        *data[];
00307 };
00308 
00313 struct BBStringArray
00314 {
00315     BBClass         *clas;
00316     int             refs;
00317     
00318     const char      *type;
00319     BBSize          dims;
00320     BBSize          size;
00321     BBSize          scales[1];
00322     
00323     BBString        *data[];
00324 };
00325 
00330 struct BBArrayArray
00331 {
00332     BBClass         *clas;
00333     int             refs;
00334     
00335     const char      *type;
00336     BBSize          dims;
00337     BBSize          size;
00338     BBSize          scales[1];
00339     
00340     BBArray         *data[];
00341 };
00342 
00343 
00356 BBArray* bb_array_alloc(const char *type, BBSize dims, const BBSize *lens);
00357 
00374 BBArray* bb_array_alloc1d(const char *type, BBSize len);
00375 
00393 void bb_array_init(BBArray *arr);
00394 
00395 
00396 
00405 BBArray* bbArrayNew(const char *type, BBInt dims, ...);
00406 
00421 BBArray* bbArrayNew1D(const char *type, BBInt length);
00422 
00423 //  Creates a new array. Only used by brl.reflection as far as I can tell
00424 BBArray* bbArrayNewEx(const char *type, BBInt dims, BBInt *lens);
00425 
00434 BBArray* bbArraySlice(const char *type, const BBArray *arr, BBInt begin, BBInt end);
00435 
00440 BBArray* bbArrayFromData(const char *type, BBInt length, const void *data);
00441 
00446 BBArray* bbArrayCastFromObject(const BBObject *obj, const char *typetag);
00447 
00455 void bbArraySort(BBArray *arr, BBInt ascending);
00456 
00464 BBArray* bbArrayDimensions(const BBArray *arr);
00465 
00475 BBArray* bbArrayConcat(const char *type, const BBArray *arr, const BBArray *rhs);
00476 
00477 //  Additions by BME
00478 
00502 BBInt bbArrayCompare(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00503 
00517 BBString* bbArrayToString(const BBArray *arr);
00518 
00533 BBArray* bbArrayClone(const BBArray *arr);
00534 
00544 BBBool bbArrayEquals(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00545 
00546 
00547 
00553 #define BBARRAY_NOTFOUND    (-1)
00554 
00561 BBInt bbArrayFind(const BBArray *arr, const BBArray *sub, BBInt start_pos) __attribute__ ((pure));
00562 
00570 BBInt bbArrayFindInt(const BBArray *arr, BBInt num, BBInt start_pos) __attribute__ ((pure));
00571 
00577 BBInt bbArrayFindLong(const BBLongArray *arr, BBLong num, BBInt start_pos) __attribute__ ((pure));
00578 
00584 BBInt bbArrayFindFloat(const BBFloatArray *arr, BBFloat num, BBInt start_pos) __attribute__ ((pure));
00585 
00591 BBInt bbArrayFindDouble(const BBDoubleArray *arr, BBDouble num, BBInt start_pos) __attribute__ ((pure));
00592 
00598 BBInt bbArrayFindObject(const BBObjectArray *arr, const BBObject *obj, BBInt start_pos) __attribute__ ((pure));
00599 
00605 BBInt bbArrayFindString(const BBStringArray *arr, const BBString *str, BBInt start_pos) __attribute__ ((pure));
00606 
00607 
00608 
00616 BBBool bbArrayStartsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00617 
00625 BBBool bbArrayEndsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00626 
00627 
00628 
00636 BBBool bbArrayContains(const BBArray *arr, const BBArray *sub) __attribute__ ((pure));
00637 
00645 BBBool bbArrayContainsInt(const BBArray *arr, BBInt num) __attribute__ ((pure));
00646 
00654 BBBool bbArrayContainsLong(const BBLongArray *arr, BBLong num) __attribute__ ((pure));
00655 
00663 BBBool bbArrayContainsFloat(const BBFloatArray *arr, BBFloat num) __attribute__ ((pure));
00664 
00672 BBBool bbArrayContainsDouble(const BBDoubleArray *arr, BBDouble num) __attribute__ ((pure));
00673 
00681 BBBool bbArrayContainsObject(const BBObjectArray *arr, const BBObject *obj) __attribute__ ((pure));
00682 
00690 BBBool bbArrayContainsString(const BBStringArray *arr, const BBString *str) __attribute__ ((pure));
00691 
00692 
00693 
00699 BBArray* bbArrayReverse(const BBArray *arr);
00700 
00715 BBArray* bbArrayRotate(const BBArray *arr, BBInt count);
00716 
00717 #ifndef BB_DISABLE_DEPRECATED
00718 #   define BBARRAYSIZE(q,n) (20+(n)*sizeof(int)+(q))
00719 #   define BBARRAYDATA(p,n) ((void*)((char*)(p)+20+(n)*sizeof(int)))
00720 #endif  // !BB_DISABLE_DEPRECATED
00721 
00722 BB_END_DECLS
00723 
00724 #endif  // BLITZ_ARRAY_H