1 // cl_make_heap_GV_number().
6 CL_PROVIDE(cl_GV_number)
9 #include "cln/GV_number.h"
14 #include "cln/abort.h"
15 #include "cl_offsetof.h"
19 static void cl_gvector_number_destructor (cl_heap* pointer)
21 #if (defined(__mips__) || defined(__mips64__)) && !defined(__GNUC__) // workaround SGI CC bug
22 (*(cl_heap_GV_number*)pointer).~cl_heap_GV();
24 (*(cl_heap_GV_number*)pointer).~cl_heap_GV_number();
28 cl_class cl_class_gvector_number = {
29 cl_gvector_number_destructor,
34 static inline cl_heap_GV_number * outcast (cl_GV_inner<cl_number>* vec)
36 return (cl_heap_GV_number *)((char *) vec - offsetof(cl_heap_GV_number,v));
38 static inline const cl_heap_GV_number * outcast (const cl_GV_inner<cl_number>* vec)
40 return (const cl_heap_GV_number *)((const char *) vec - offsetof(cl_heap_GV_number,v));
44 // Vectors of numbers.
46 struct cl_heap_GV_number_general : public cl_heap_GV_number {
48 // Standard allocation disabled.
49 void* operator new (size_t size) { unused size; cl_abort(); return (void*)1; }
50 // Standard deallocation disabled.
51 void operator delete (void* ptr) { unused ptr; cl_abort(); }
52 // No default constructor.
53 cl_heap_GV_number_general ();
56 static const cl_number general_element (const cl_GV_inner<cl_number>* vec, uintL index)
58 return ((const cl_heap_GV_number_general *) outcast(vec))->data[index];
61 static void general_set_element (cl_GV_inner<cl_number>* vec, uintL index, const cl_number& x)
63 ((cl_heap_GV_number_general *) outcast(vec))->data[index] = x;
66 static void general_do_delete (cl_GV_inner<cl_number>* vec)
68 var cl_heap_GV_number_general* hv = (cl_heap_GV_number_general *) outcast(vec);
69 var uintL len = hv->v.length();
70 for (var uintL i = 0; i < len; i++)
71 hv->data[i].~cl_number();
74 static void general_copy_elements (const cl_GV_inner<cl_number>* srcvec, uintL srcindex, cl_GV_inner<cl_number>* destvec, uintL destindex, uintL count)
77 var const cl_heap_GV_number_general* srcv =
78 (const cl_heap_GV_number_general *) outcast(srcvec);
79 var cl_heap_GV_number_general* destv =
80 (cl_heap_GV_number_general *) outcast(destvec);
81 var uintL srclen = srcv->v.length();
82 var uintL destlen = destv->v.length();
83 if (!(srcindex <= srcindex+count && srcindex+count <= srclen))
85 if (!(destindex <= destindex+count && destindex+count <= destlen))
88 destv->data[destindex++] = srcv->data[srcindex++];
89 } while (--count > 0);
93 static cl_GV_vectorops<cl_number> general_vectorops = {
100 cl_heap_GV_number* cl_make_heap_GV_number (uintL len)
102 var cl_heap_GV_number_general* hv = (cl_heap_GV_number_general*) malloc_hook(offsetofa(cl_heap_GV_number_general,data)+sizeof(cl_number)*len);
104 hv->type = &cl_class_gvector_number;
105 new (&hv->v) cl_GV_inner<cl_number> (len,&general_vectorops);
106 for (var uintL i = 0; i < len; i++)
107 init1(cl_number, hv->data[i]) ();
112 const cl_GV_number cl_null_GV_number = cl_GV_number((uintL)0);
116 CL_PROVIDE_END(cl_GV_number)