BlitzMax Extended  0.8.18
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 
66  const char* type;
67 
69  BBSize dims;
70 
76  BBSize size;
77 
83  BBSize scales[1];
84 };
85 
86 #define BBARRAY_HEADER_SIZE (sizeof (BBArray) - sizeof (BBSize))
87 
88 // Maximum value of an array's data
89 #define BBARRAY_MAX_DATASIZE (BBSIZE_MAX - sizeof (BBArray))
90 
91 // Absolute maximum length (value of scales[0]) of an array
92 // Depends on the data type the array stores
93 #define BBARRAY_MAX_LENGTH (BBARRAY_MAX_DATASIZE)
94 
112 #define BBARRAY_SIZE_CALC(size, num_dims) \
113  (BBARRAY_HEADER_SIZE + (num_dims) * sizeof (int) + (size))
114 
122 #define BBARRAY_SIZE(arr) BBARRAY_SIZE_CALC((arr)->size, (arr)->dims)
123 
134 #define BBARRAY_DATAPTR_CALC(arr, num_dims) \
135  ((void *) \
136  ((char *)(arr) + BBARRAY_HEADER_SIZE + (num_dims) * sizeof (int)) \
137  )
138 
149 #define BBARRAY_DATAPTR(arr) BBARRAY_DATAPTR_CALC((arr), (arr)->dims)
150 
171 #define BBARRAY_ALLOC(size, dims, flags) \
172  ({ \
173  (BBArray *) \
174  bbGCAllocObject( \
175  BBARRAY_SIZE_CALC((size), (dims)), \
176  &bbArrayClass, \
177  (flags) \
178  ); \
179  })
180 
189 #define BBARRAY_TYPE_ISCOMPLEX(type) \
190  ( \
191  (type)[0] == ':' || \
192  (type)[0] == '$' || \
193  (type)[0] == '[' \
194  )
195 
206 #define BBARRAY_ISCOMPLEX(arr) BBARRAY_TYPE_ISCOMPLEX((arr)->type)
207 
208 
218 extern BBClass bbArrayClass;
219 
227 extern BBArray bbEmptyArray;
228 
235 #define BBNULLARRAY (&bbEmptyArray)
236 
242 {
244  int refs;
245 
246  const char *type;
247  BBSize dims;
248  BBSize size;
249  BBSize scales[1];
250 
253 };
254 
260 {
262  int refs;
263 
264  const char *type;
265  BBSize dims;
266  BBSize size;
267  BBSize scales[1];
268 
271 };
272 
278 {
280  int refs;
281 
282  const char *type;
283  BBSize dims;
284  BBSize size;
285  BBSize scales[1];
286 
289 };
290 
296 {
298  int refs;
299 
300  const char *type;
301  BBSize dims;
302  BBSize size;
303  BBSize scales[1];
304 
307 };
308 
314 {
316  int refs;
317 
318  const char *type;
319  BBSize dims;
320  BBSize size;
321  BBSize scales[1];
322 
325 };
326 
332 {
334  int refs;
335 
336  const char *type;
337  BBSize dims;
338  BBSize size;
339  BBSize scales[1];
340 
343 };
344 
350 {
352  int refs;
353 
354  const char *type;
355  BBSize dims;
356  BBSize size;
357  BBSize scales[1];
358 
361 };
362 
368 {
370  int refs;
371 
372  const char *type;
373  BBSize dims;
374  BBSize size;
375  BBSize scales[1];
376 
379 };
380 
386 {
388  int refs;
389 
390  const char *type;
391  BBSize dims;
392  BBSize size;
393  BBSize scales[1];
394 
397 };
398 
399 
414 BBArray* bb_array_alloc(const char *type, BBSize dims, const BBSize *lens);
415 
434 BBArray* bb_array_alloc1d(const char *type, BBSize len);
435 
455 void bb_array_init(BBArray *arr);
456 
457 
458 
467 BBArray* bbArrayNew(const char *type, BBInt dims, ...);
468 
483 BBArray* bbArrayNew1D(const char *type, BBInt length);
484 
496 BBArray* bbArrayNewEx(const char *type, BBInt dims, BBInt *lens);
497 
506 BBArray* bbArraySlice(const char *type, BBArray *arr, BBInt begin, BBInt end);
507 
512 BBArray* bbArrayFromData(const char *type, BBInt length, const void *data);
513 
520 BBArray* bbArrayCastFromObject(const BBObject *obj, const char *typetag);
521 
529 void bbArraySort(BBArray *arr, BBInt ascending);
530 
538 BBArray* bbArrayDimensions(const BBArray *arr);
539 
549 BBArray* bbArrayConcat(const char *type, BBArray *arr, BBArray *rhs);
550 
551 
552 // EXTENDED //
553 
554 BBArray* bbArrayFromCArray(const void *buf, BBInt size, BBTypeKey typekey, const BBIntArray *dims);
555 
562 BBIntArray* bbArrayFromInts(const BBInt *buf, BBInt size);
563 
564 BBFloatArray* bbArrayFromFloats(const BBFloat *buf, BBInt size);
565 
589 BBInt bbArrayCompare(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
590 
604 BBString* bbArrayToString(const BBArray *arr);
605 
609 void* bbArrayToCArray(const BBArray *arr);
610 
625 BBArray* bbArrayClone(const BBArray *arr);
626 
636 BBBool bbArrayEquals(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
637 
638 
639 
645 #define BBARRAY_NOTFOUND (-1)
646 
653 BBInt bbArrayFind(const BBArray *arr, const BBArray *sub, BBInt start_pos) __attribute__ ((pure));
654 
662 BBInt bbArrayFindInt(const BBArray *arr, BBInt num, BBInt start_pos) __attribute__ ((pure));
663 
669 BBInt bbArrayFindLong(const BBLongArray *arr, BBLong num, BBInt start_pos) __attribute__ ((pure));
670 
676 BBInt bbArrayFindFloat(const BBFloatArray *arr, BBFloat num, BBInt start_pos) __attribute__ ((pure));
677 
683 BBInt bbArrayFindDouble(const BBDoubleArray *arr, BBDouble num, BBInt start_pos) __attribute__ ((pure));
684 
690 BBInt bbArrayFindObject(const BBObjectArray *arr, const BBObject *obj, BBInt start_pos) __attribute__ ((pure));
691 
697 BBInt bbArrayFindString(const BBStringArray *arr, const BBString *str, BBInt start_pos) __attribute__ ((pure));
698 
699 
700 
708 BBBool bbArrayStartsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
709 
717 BBBool bbArrayEndsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
718 
719 
720 
728 BBBool bbArrayContains(const BBArray *arr, const BBArray *sub) __attribute__ ((pure));
729 
737 BBBool bbArrayContainsInt(const BBArray *arr, BBInt num) __attribute__ ((pure));
738 
746 BBBool bbArrayContainsLong(const BBLongArray *arr, BBLong num) __attribute__ ((pure));
747 
755 BBBool bbArrayContainsFloat(const BBFloatArray *arr, BBFloat num) __attribute__ ((pure));
756 
764 BBBool bbArrayContainsDouble(const BBDoubleArray *arr, BBDouble num) __attribute__ ((pure));
765 
773 BBBool bbArrayContainsObject(const BBObjectArray *arr, const BBObject *obj) __attribute__ ((pure));
774 
782 BBBool bbArrayContainsString(const BBStringArray *arr, const BBString *str) __attribute__ ((pure));
783 
784 
785 
791 BBArray* bbArrayReverse(const BBArray *arr);
792 
807 BBArray* bbArrayRotate(const BBArray *arr, BBInt count);
808 
809 BBIntArray* bbArrayFilterInt(BBIntArray *arr, BBBool (*filter)(BBInt));
810 
811 #ifndef BB_DISABLE_DEPRECATED
812 
813 # define BBARRAYSIZE(q,n) (20+(n)*sizeof(int)+(q))
814 # define BBARRAYDATA(p,n) ((void*)((char*)(p)+20+(n)*sizeof(int)))
815 
816 #endif // !BB_DISABLE_DEPRECATED
817 
818 BB_END_DECLS
819 
820 #endif // BLITZ_ARRAY_H