1 // cl_make_heap_GV_number().
6 CL_PROVIDE(cl_GV_number)
9 #include "cl_GV_number.h"
15 #include "cl_offsetof.h"
18 static void cl_gvector_number_destructor (cl_heap* pointer)
20 #if (defined(__mips__) || defined(__mips64__)) && !defined(__GNUC__) // workaround SGI CC bug
21 (*(cl_heap_GV_number*)pointer).~cl_heap_GV();
23 (*(cl_heap_GV_number*)pointer).~cl_heap_GV_number();
27 cl_class cl_class_gvector_number = {
28 cl_gvector_number_destructor,
33 static inline cl_heap_GV_number * outcast (cl_GV_inner<cl_number>* vec)
35 return (cl_heap_GV_number *)((char *) vec - offsetof(cl_heap_GV_number,v));
37 static inline const cl_heap_GV_number * outcast (const cl_GV_inner<cl_number>* vec)
39 return (const cl_heap_GV_number *)((const char *) vec - offsetof(cl_heap_GV_number,v));
43 // Vectors of numbers.
45 struct cl_heap_GV_number_general : public cl_heap_GV_number {
47 // Standard allocation disabled.
48 void* operator new (size_t size) { unused size; cl_abort(); return (void*)1; }
49 // Standard deallocation disabled.
50 void operator delete (void* ptr) { unused ptr; cl_abort(); }
51 // No default constructor.
52 cl_heap_GV_number_general ();
55 static const cl_number general_element (const cl_GV_inner<cl_number>* vec, uintL index)
57 return ((const cl_heap_GV_number_general *) outcast(vec))->data[index];
60 static void general_set_element (cl_GV_inner<cl_number>* vec, uintL index, const cl_number& x)
62 ((cl_heap_GV_number_general *) outcast(vec))->data[index] = x;
65 static void general_do_delete (cl_GV_inner<cl_number>* vec)
67 var cl_heap_GV_number_general* hv = (cl_heap_GV_number_general *) outcast(vec);
68 var uintL len = hv->v.length();
69 for (var uintL i = 0; i < len; i++)
70 hv->data[i].~cl_number();
73 static void general_copy_elements (const cl_GV_inner<cl_number>* srcvec, uintL srcindex, cl_GV_inner<cl_number>* destvec, uintL destindex, uintL count)
76 var const cl_heap_GV_number_general* srcv =
77 (const cl_heap_GV_number_general *) outcast(srcvec);
78 var cl_heap_GV_number_general* destv =
79 (cl_heap_GV_number_general *) outcast(destvec);
80 var uintL srclen = srcv->v.length();
81 var uintL destlen = destv->v.length();
82 if (!(srcindex <= srcindex+count && srcindex+count <= srclen))
84 if (!(destindex <= destindex+count && destindex+count <= destlen))
87 destv->data[destindex++] = srcv->data[srcindex++];
88 } while (--count > 0);
92 static cl_GV_vectorops<cl_number> general_vectorops = {
99 cl_heap_GV_number* cl_make_heap_GV_number (uintL len)
101 var cl_heap_GV_number_general* hv = (cl_heap_GV_number_general*) cl_malloc_hook(offsetofa(cl_heap_GV_number_general,data)+sizeof(cl_number)*len);
103 hv->type = &cl_class_gvector_number;
104 new (&hv->v) cl_GV_inner<cl_number> (len,&general_vectorops);
105 for (var uintL i = 0; i < len; i++)
106 init1(cl_number, hv->data[i]) ();
111 const cl_GV_number cl_null_GV_number = cl_GV_number((uintL)0);
113 CL_PROVIDE_END(cl_GV_number)