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 
00445 BBArray* bbArrayCastFromObject(const BBObject *obj, const char *type_encoding);
00446 
00450 void bbArraySort(BBArray *arr, BBInt ascending);
00451 
00455 BBArray* bbArrayDimensions(const BBArray *arr);
00456 
00460 BBArray* bbArrayConcat(const char *type, const BBArray *arr, const BBArray *rhs);
00461 
00462 //  Additions by BME
00463 
00487 BBInt bbArrayCompare(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00488 
00502 BBString* bbArrayToString(const BBArray *arr);
00503 
00518 BBArray* bbArrayClone(const BBArray *arr);
00519 
00529 BBBool bbArrayEquals(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00530 
00531 
00532 
00538 #define BBARRAY_NOTFOUND    (-1)
00539 
00546 BBInt bbArrayFind(const BBArray *arr, const BBArray *sub, BBInt start_pos) __attribute__ ((pure));
00547 
00555 BBInt bbArrayFindInt(const BBArray *arr, BBInt num, BBInt start_pos) __attribute__ ((pure));
00556 
00562 BBInt bbArrayFindLong(const BBLongArray *arr, BBLong num, BBInt start_pos) __attribute__ ((pure));
00563 
00569 BBInt bbArrayFindFloat(const BBFloatArray *arr, BBFloat num, BBInt start_pos) __attribute__ ((pure));
00570 
00576 BBInt bbArrayFindDouble(const BBDoubleArray *arr, BBDouble num, BBInt start_pos) __attribute__ ((pure));
00577 
00583 BBInt bbArrayFindObject(const BBObjectArray *arr, const BBObject *obj, BBInt start_pos) __attribute__ ((pure));
00584 
00590 BBInt bbArrayFindString(const BBStringArray *arr, const BBString *str, BBInt start_pos) __attribute__ ((pure));
00591 
00592 
00593 
00597 BBBool bbArrayStartsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00598 
00602 BBBool bbArrayEndsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
00603 
00604 
00605 
00609 BBBool bbArrayContains(const BBArray *arr, const BBArray *sub) __attribute__ ((pure));
00610 
00614 BBBool bbArrayContainsInt(const BBArray *arr, BBInt num) __attribute__ ((pure));
00615 
00619 BBBool bbArrayContainsLong(const BBLongArray *arr, BBLong num) __attribute__ ((pure));
00620 
00624 BBBool bbArrayContainsFloat(const BBFloatArray *arr, BBFloat num) __attribute__ ((pure));
00625 
00629 BBBool bbArrayContainsDouble(const BBDoubleArray *arr, BBDouble num) __attribute__ ((pure));
00630 
00634 BBBool bbArrayContainsObject(const BBObjectArray *arr, const BBObject *obj) __attribute__ ((pure));
00635 
00639 BBBool bbArrayContainsString(const BBStringArray *arr, const BBString *str) __attribute__ ((pure));
00640 
00641 
00642 
00648 BBArray* bbArrayReverse(const BBArray *arr);
00649 
00658 BBArray* bbArrayRotate(const BBArray *arr, BBInt count);
00659 
00660 #ifndef BB_DISABLE_DEPRECATED
00661 #   define BBARRAYSIZE(q,n) (20+(n)*sizeof(int)+(q))
00662 #   define BBARRAYDATA(p,n) ((void*)((char*)(p)+20+(n)*sizeof(int)))
00663 #endif  // !BB_DISABLE_DEPRECATED
00664 
00665 BB_END_DECLS
00666 
00667 #endif  // BLITZ_ARRAY_H