BlitzMax Extended  0.8.17
Pushing Blitz to the Max.
blitz_array.h
Go to the documentation of this file.
1 
11 #ifndef BLITZ_ARRAY_H
12 #define BLITZ_ARRAY_H
13 
14 #include "_common.h"
15 
16 #include "blitz_class.h"
17 #include "blitz_object.h"
18 
19 BB_BEGIN_DECLS
20 
42 struct BBArray
43 {
50  int refs;
51 
53  const char* type;
54 
56  BBSize dims;
57 
63  BBSize size;
64 
70  BBSize scales[1];
71 };
72 
73 #define BBARRAY_HEADER_SIZE (sizeof (BBArray) - sizeof (BBSize))
74 
75 // Maximum value of an array's data
76 #define BBARRAY_MAX_DATASIZE (BBSIZE_MAX - sizeof (BBArray))
77 
78 // Absolute maximum length (value of scales[0]) of an array
79 // Depends on the data type the array stores
80 #define BBARRAY_MAX_LENGTH (BBARRAY_MAX_DATASIZE)
81 
97 #define BBARRAY_SIZE_CALC(size, num_dims) \
98  (BBARRAY_HEADER_SIZE + (num_dims) * sizeof (int) + (size))
99 
107 #define BBARRAY_SIZE(arr) BBARRAY_SIZE_CALC((arr)->size, (arr)->dims)
108 
117 #define BBARRAY_DATAPTR_CALC(arr, num_dims) \
118  ((void *) \
119  ((char *)(arr) + BBARRAY_HEADER_SIZE + (num_dims) * sizeof (int)) \
120  )
121 
132 #define BBARRAY_DATAPTR(arr) BBARRAY_DATAPTR_CALC((arr), (arr)->dims)
133 
154 #define BBARRAY_ALLOC(size, dims, flags) \
155  ({ \
156  (BBArray *) \
157  bbGCAllocObject( \
158  BBARRAY_SIZE_CALC((size), (dims)), \
159  &bbArrayClass, \
160  (flags) \
161  ); \
162  })
163 
176 #define BBARRAY_ISCOMPLEX(arr) \
177  ( \
178  (arr)->type[0] == ':' || \
179  (arr)->type[0] == '$' || \
180  (arr)->type[0] == '[' \
181  )
182 
183 
193 extern BBClass bbArrayClass;
194 
202 extern BBArray bbEmptyArray;
203 
210 #define BBNULLARRAY (&bbEmptyArray)
211 
217 {
219  int refs;
220 
221  const char *type;
222  BBSize dims;
223  BBSize size;
224  BBSize scales[1];
225 
228 };
229 
235 {
237  int refs;
238 
239  const char *type;
240  BBSize dims;
241  BBSize size;
242  BBSize scales[1];
243 
246 };
247 
253 {
255  int refs;
256 
257  const char *type;
258  BBSize dims;
259  BBSize size;
260  BBSize scales[1];
261 
264 };
265 
271 {
273  int refs;
274 
275  const char *type;
276  BBSize dims;
277  BBSize size;
278  BBSize scales[1];
279 
282 };
283 
289 {
291  int refs;
292 
293  const char *type;
294  BBSize dims;
295  BBSize size;
296  BBSize scales[1];
297 
300 };
301 
307 {
309  int refs;
310 
311  const char *type;
312  BBSize dims;
313  BBSize size;
314  BBSize scales[1];
315 
318 };
319 
325 {
327  int refs;
328 
329  const char *type;
330  BBSize dims;
331  BBSize size;
332  BBSize scales[1];
333 
336 };
337 
343 {
345  int refs;
346 
347  const char *type;
348  BBSize dims;
349  BBSize size;
350  BBSize scales[1];
351 
354 };
355 
361 {
363  int refs;
364 
365  const char *type;
366  BBSize dims;
367  BBSize size;
368  BBSize scales[1];
369 
372 };
373 
374 
389 BBArray* bb_array_alloc(const char *type, BBSize dims, const BBSize *lens);
390 
409 BBArray* bb_array_alloc1d(const char *type, BBSize len);
410 
430 void bb_array_init(BBArray *arr);
431 
432 
433 
442 BBArray* bbArrayNew(const char *type, BBInt dims, ...);
443 
458 BBArray* bbArrayNew1D(const char *type, BBInt length);
459 
471 BBArray* bbArrayNewEx(const char *type, BBInt dims, BBInt *lens);
472 
481 BBArray* bbArraySlice(const char *type, BBArray *arr, BBInt begin, BBInt end);
482 
487 BBArray* bbArrayFromData(const char *type, BBInt length, const void *data);
488 
495 BBArray* bbArrayCastFromObject(const BBObject *obj, const char *typetag);
496 
504 void bbArraySort(BBArray *arr, BBInt ascending);
505 
513 BBArray* bbArrayDimensions(const BBArray *arr);
514 
524 BBArray* bbArrayConcat(const char *type, BBArray *arr, BBArray *rhs);
525 
526 
527 // EXTENDED //
528 
529 BBArray* bbArrayFromCArray(const void *buf, BBInt size, BBTypeKey typekey, const BBIntArray *dims);
530 
537 BBIntArray* bbArrayFromInts(const BBInt *buf, BBInt size);
538 
539 BBFloatArray* bbArrayFromFloats(const BBFloat *buf, BBInt size);
540 
564 BBInt bbArrayCompare(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
565 
579 BBString* bbArrayToString(const BBArray *arr);
580 
584 void* bbArrayToCArray(const BBArray *arr);
585 
600 BBArray* bbArrayClone(const BBArray *arr);
601 
611 BBBool bbArrayEquals(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
612 
613 
614 
620 #define BBARRAY_NOTFOUND (-1)
621 
628 BBInt bbArrayFind(const BBArray *arr, const BBArray *sub, BBInt start_pos) __attribute__ ((pure));
629 
637 BBInt bbArrayFindInt(const BBArray *arr, BBInt num, BBInt start_pos) __attribute__ ((pure));
638 
644 BBInt bbArrayFindLong(const BBLongArray *arr, BBLong num, BBInt start_pos) __attribute__ ((pure));
645 
651 BBInt bbArrayFindFloat(const BBFloatArray *arr, BBFloat num, BBInt start_pos) __attribute__ ((pure));
652 
658 BBInt bbArrayFindDouble(const BBDoubleArray *arr, BBDouble num, BBInt start_pos) __attribute__ ((pure));
659 
665 BBInt bbArrayFindObject(const BBObjectArray *arr, const BBObject *obj, BBInt start_pos) __attribute__ ((pure));
666 
672 BBInt bbArrayFindString(const BBStringArray *arr, const BBString *str, BBInt start_pos) __attribute__ ((pure));
673 
674 
675 
683 BBBool bbArrayStartsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
684 
692 BBBool bbArrayEndsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
693 
694 
695 
703 BBBool bbArrayContains(const BBArray *arr, const BBArray *sub) __attribute__ ((pure));
704 
712 BBBool bbArrayContainsInt(const BBArray *arr, BBInt num) __attribute__ ((pure));
713 
721 BBBool bbArrayContainsLong(const BBLongArray *arr, BBLong num) __attribute__ ((pure));
722 
730 BBBool bbArrayContainsFloat(const BBFloatArray *arr, BBFloat num) __attribute__ ((pure));
731 
739 BBBool bbArrayContainsDouble(const BBDoubleArray *arr, BBDouble num) __attribute__ ((pure));
740 
748 BBBool bbArrayContainsObject(const BBObjectArray *arr, const BBObject *obj) __attribute__ ((pure));
749 
757 BBBool bbArrayContainsString(const BBStringArray *arr, const BBString *str) __attribute__ ((pure));
758 
759 
760 
766 BBArray* bbArrayReverse(const BBArray *arr);
767 
782 BBArray* bbArrayRotate(const BBArray *arr, BBInt count);
783 
784 BBIntArray* bbArrayFilterInt(BBIntArray *arr, BBBool (*filter)(BBInt));
785 
786 #ifndef BB_DISABLE_DEPRECATED
787 
788 # define BBARRAYSIZE(q,n) (20+(n)*sizeof(int)+(q))
789 # define BBARRAYDATA(p,n) ((void*)((char*)(p)+20+(n)*sizeof(int)))
790 
791 #endif // !BB_DISABLE_DEPRECATED
792 
793 BB_END_DECLS
794 
795 #endif // BLITZ_ARRAY_H