blitz_array.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef BLITZ_ARRAY_H
  2. #define BLITZ_ARRAY_H
  3. #include "blitz_types.h"
  4. #ifdef __cplusplus
  5. extern "C"{
  6. #endif
  7. #define BBNULLARRAY (&bbEmptyArray)
  8. #define BBARRAYSIZE(q,n) (((offsetof(BBArray, scales) + n * sizeof(int)+0x0f) & ~0x0f)+(q))
  9. //#define BBARRAYDATA(p,n) ((void*)((char*)(p)+((offsetof(BBArray, scales) + n * sizeof(int)+0x0f) & ~0x0f)))
  10. #define BBARRAYDATA(p,n) ((void*)((char*)(p)+((BBArray*)(p))->data_start))
  11. #define BBARRAYDATAINDEX(p,n,i) bbArrayIndex(p,n,i)
  12. struct BBArray{
  13. //extends BBObject
  14. BBClass* clas;
  15. const char* type; //
  16. unsigned int dims; //
  17. unsigned int size; // total size minus this header
  18. unsigned short data_size; // size of data element
  19. unsigned short data_start; // start offset of data
  20. int scales[1]; // [dims]
  21. };
  22. struct BBClass_Array{
  23. //extends BBGCPool
  24. BBClass* super;
  25. void (*free)( BBObject *o );
  26. BBDebugScope*debug_scope;
  27. unsigned int instance_size;
  28. void (*ctor)( BBObject *o );
  29. void (*dtor)( BBObject *o );
  30. BBString* (*ToString)( BBObject *x );
  31. int (*Compare)( BBObject *x,BBObject *y );
  32. BBObject* (*SendMessage)( BBObject * o, BBObject *m,BBObject *s );
  33. BBINTERFACETABLE itable;
  34. void* extra;
  35. unsigned int obj_size;
  36. unsigned int instance_count;
  37. unsigned int fields_offset;
  38. void (*bbArraySort)( BBArray *arr,int ascending );
  39. BBArray* (*bbArrayDimensions)( BBArray *arr );
  40. };
  41. extern struct BBClass_Array bbArrayClass;
  42. extern BBArray bbEmptyArray;
  43. BBArray* bbArrayNew( const char *type,int dims,... );
  44. BBArray* bbArrayNew1D( const char *type,int length );
  45. BBArray* bbArrayNewEx( const char *type,int dims,int *lens ); //alternate version of New...
  46. BBArray* bbArraySlice( const char *type,BBArray *arr,int beg,int end );
  47. BBArray* bbArrayFromData( const char *type,int length,void *data );
  48. BBArray* bbArrayCastFromObject( BBObject *o,const char *type_encoding );
  49. void bbArraySort( BBArray *arr,int ascending );
  50. BBArray* bbArrayDimensions( BBArray *arr );
  51. BBArray* bbArrayConcat( const char *type,BBArray *x,BBArray *y );
  52. void* bbArrayIndex( BBArray *, int, int );
  53. typedef void (*BBArrayStructInit)(void * ref);
  54. BBArray* bbArrayNew1DStruct( const char *type,int length, unsigned short data_size, BBArrayStructInit init );
  55. BBArray* bbArrayNewStruct( const char *type,unsigned short data_size, BBArrayStructInit init, int dims, ... );
  56. BBArray* bbArrayFromDataStruct( const char *type,int length,void *data, unsigned short data_size );
  57. BBArray* bbArraySliceStruct( const char *type,BBArray *inarr,int beg,int end, unsigned short data_size, BBArrayStructInit structInit );
  58. BBArray* bbArrayFromDataSize( const char *type,int length,void *data, unsigned short data_size );
  59. BBArray* bbArrayNew1DNoInit( const char *type,int length );
  60. void bbArrayCopy(BBArray * srcArr, int srcPos, BBArray * dstArr, int dstPos, int length);
  61. int bbObjectIsEmptyArray(BBObject * o);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif