BlitzMax Extended  0.8.16
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 
173 extern BBClass bbArrayClass;
174 
182 extern BBArray bbEmptyArray;
183 
190 #define BBNULLARRAY (&bbEmptyArray)
191 
197 {
199  int refs;
200 
201  const char *type;
202  BBSize dims;
203  BBSize size;
204  BBSize scales[1];
205 
208 };
209 
215 {
217  int refs;
218 
219  const char *type;
220  BBSize dims;
221  BBSize size;
222  BBSize scales[1];
223 
226 };
227 
233 {
235  int refs;
236 
237  const char *type;
238  BBSize dims;
239  BBSize size;
240  BBSize scales[1];
241 
244 };
245 
251 {
253  int refs;
254 
255  const char *type;
256  BBSize dims;
257  BBSize size;
258  BBSize scales[1];
259 
262 };
263 
269 {
271  int refs;
272 
273  const char *type;
274  BBSize dims;
275  BBSize size;
276  BBSize scales[1];
277 
280 };
281 
287 {
289  int refs;
290 
291  const char *type;
292  BBSize dims;
293  BBSize size;
294  BBSize scales[1];
295 
298 };
299 
305 {
307  int refs;
308 
309  const char *type;
310  BBSize dims;
311  BBSize size;
312  BBSize scales[1];
313 
316 };
317 
323 {
325  int refs;
326 
327  const char *type;
328  BBSize dims;
329  BBSize size;
330  BBSize scales[1];
331 
334 };
335 
341 {
343  int refs;
344 
345  const char *type;
346  BBSize dims;
347  BBSize size;
348  BBSize scales[1];
349 
352 };
353 
354 
369 BBArray* bb_array_alloc(const char *type, BBSize dims, const BBSize *lens);
370 
389 BBArray* bb_array_alloc1d(const char *type, BBSize len);
390 
410 void bb_array_init(BBArray *arr);
411 
412 
413 
422 BBArray* bbArrayNew(const char *type, BBInt dims, ...);
423 
438 BBArray* bbArrayNew1D(const char *type, BBInt length);
439 
440 // Creates a new array. Only used by brl.reflection as far as I can tell
441 BBArray* bbArrayNewEx(const char *type, BBInt dims, BBInt *lens);
442 
451 BBArray* bbArraySlice(const char *type, const BBArray *arr, BBInt begin, BBInt end);
452 
457 BBArray* bbArrayFromData(const char *type, BBInt length, const void *data);
458 
465 BBArray* bbArrayCastFromObject(const BBObject *obj, const char *typetag);
466 
474 void bbArraySort(BBArray *arr, BBInt ascending);
475 
483 BBArray* bbArrayDimensions(const BBArray *arr);
484 
494 BBArray* bbArrayConcat(const char *type, const BBArray *arr, const BBArray *rhs);
495 
496 // Additions by BME
497 
521 BBInt bbArrayCompare(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
522 
536 BBString* bbArrayToString(const BBArray *arr);
537 
552 BBArray* bbArrayClone(const BBArray *arr);
553 
563 BBBool bbArrayEquals(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
564 
565 
566 
572 #define BBARRAY_NOTFOUND (-1)
573 
580 BBInt bbArrayFind(const BBArray *arr, const BBArray *sub, BBInt start_pos) __attribute__ ((pure));
581 
589 BBInt bbArrayFindInt(const BBArray *arr, BBInt num, BBInt start_pos) __attribute__ ((pure));
590 
596 BBInt bbArrayFindLong(const BBLongArray *arr, BBLong num, BBInt start_pos) __attribute__ ((pure));
597 
603 BBInt bbArrayFindFloat(const BBFloatArray *arr, BBFloat num, BBInt start_pos) __attribute__ ((pure));
604 
610 BBInt bbArrayFindDouble(const BBDoubleArray *arr, BBDouble num, BBInt start_pos) __attribute__ ((pure));
611 
617 BBInt bbArrayFindObject(const BBObjectArray *arr, const BBObject *obj, BBInt start_pos) __attribute__ ((pure));
618 
624 BBInt bbArrayFindString(const BBStringArray *arr, const BBString *str, BBInt start_pos) __attribute__ ((pure));
625 
626 
627 
635 BBBool bbArrayStartsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
636 
644 BBBool bbArrayEndsWith(const BBArray *arr, const BBArray *rhs) __attribute__ ((pure));
645 
646 
647 
655 BBBool bbArrayContains(const BBArray *arr, const BBArray *sub) __attribute__ ((pure));
656 
664 BBBool bbArrayContainsInt(const BBArray *arr, BBInt num) __attribute__ ((pure));
665 
673 BBBool bbArrayContainsLong(const BBLongArray *arr, BBLong num) __attribute__ ((pure));
674 
682 BBBool bbArrayContainsFloat(const BBFloatArray *arr, BBFloat num) __attribute__ ((pure));
683 
691 BBBool bbArrayContainsDouble(const BBDoubleArray *arr, BBDouble num) __attribute__ ((pure));
692 
700 BBBool bbArrayContainsObject(const BBObjectArray *arr, const BBObject *obj) __attribute__ ((pure));
701 
709 BBBool bbArrayContainsString(const BBStringArray *arr, const BBString *str) __attribute__ ((pure));
710 
711 
712 
718 BBArray* bbArrayReverse(const BBArray *arr);
719 
734 BBArray* bbArrayRotate(const BBArray *arr, BBInt count);
735 
736 #ifndef BB_DISABLE_DEPRECATED
737 
738 # define BBARRAYSIZE(q,n) (20+(n)*sizeof(int)+(q))
739 # define BBARRAYDATA(p,n) ((void*)((char*)(p)+20+(n)*sizeof(int)))
740 
741 #endif // !BB_DISABLE_DEPRECATED
742 
743 BB_END_DECLS
744 
745 #endif // BLITZ_ARRAY_H