]> www.ginac.de Git - cln.git/blob - src/vector/cl_GV_number.cc
- configure.in, autoconf/aclocal.m4 (CL_GMP_H_VERSION, CL_GMP_CHECK):
[cln.git] / src / vector / cl_GV_number.cc
1 // cl_make_heap_GV_number().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 CL_PROVIDE(cl_GV_number)
7
8 // Specification.
9 #include "cl_GV_number.h"
10
11
12 // Implementation.
13
14 #include "cl_abort.h"
15 #include "cl_offsetof.h"
16
17
18 static void cl_gvector_number_destructor (cl_heap* pointer)
19 {
20 #if (defined(__mips__) || defined(__mips64__)) && !defined(__GNUC__) // workaround SGI CC bug
21         (*(cl_heap_GV_number*)pointer).~cl_heap_GV();
22 #else
23         (*(cl_heap_GV_number*)pointer).~cl_heap_GV_number();
24 #endif
25 }
26
27 cl_class cl_class_gvector_number = {
28         cl_gvector_number_destructor,
29         0
30 };
31
32
33 static inline cl_heap_GV_number * outcast (cl_GV_inner<cl_number>* vec)
34 {
35         return (cl_heap_GV_number *)((char *) vec - offsetof(cl_heap_GV_number,v));
36 }
37 static inline const cl_heap_GV_number * outcast (const cl_GV_inner<cl_number>* vec)
38 {
39         return (const cl_heap_GV_number *)((const char *) vec - offsetof(cl_heap_GV_number,v));
40 }
41
42
43 // Vectors of numbers.
44
45 struct cl_heap_GV_number_general : public cl_heap_GV_number {
46         cl_number data[1];
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 ();
53 };
54
55 static const cl_number general_element (const cl_GV_inner<cl_number>* vec, uintL index)
56 {
57         return ((const cl_heap_GV_number_general *) outcast(vec))->data[index];
58 }
59
60 static void general_set_element (cl_GV_inner<cl_number>* vec, uintL index, const cl_number& x)
61 {
62         ((cl_heap_GV_number_general *) outcast(vec))->data[index] = x;
63 }
64
65 static void general_do_delete (cl_GV_inner<cl_number>* vec)
66 {
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();
71 }
72
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)
74 {
75         if (count > 0) {
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))
83                         cl_abort();
84                 if (!(destindex <= destindex+count && destindex+count <= destlen))
85                         cl_abort();
86                 do {
87                         destv->data[destindex++] = srcv->data[srcindex++];
88                 } while (--count > 0);
89         }
90 }
91
92 static cl_GV_vectorops<cl_number> general_vectorops = {
93         general_element,
94         general_set_element,
95         general_do_delete,
96         general_copy_elements
97 };
98
99 cl_heap_GV_number* cl_make_heap_GV_number (uintL len)
100 {
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);
102         hv->refcount = 1;
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]) ();
107         return hv;
108 }
109
110 // An empty vector.
111 const cl_GV_number cl_null_GV_number = cl_GV_number((uintL)0);
112
113 CL_PROVIDE_END(cl_GV_number)