]> www.ginac.de Git - cln.git/blob - src/vector/cl_SV_ringelt.cc
cl_{GV,SV}: use std::size_t for size of vectors (instead of obscure uintC).
[cln.git] / src / vector / cl_SV_ringelt.cc
1 // cl_make_heap_SV_ringelt().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "cln/SV_ringelt.h"
8
9
10 // Implementation.
11
12 namespace cln {
13
14 static void cl_svector_ringelt_destructor (cl_heap* pointer)
15 {
16 #if (defined(__mips__) || defined(__mips64__)) && !defined(__GNUC__) // workaround SGI CC bug
17         (*(cl_heap_SV_ringelt*)pointer).~cl_heap_SV();
18 #else
19         (*(cl_heap_SV_ringelt*)pointer).~cl_heap_SV_ringelt();
20 #endif
21 }
22
23 // XXX: this ought to be static const, but it would be impossible to
24 // set the printing function (see cl_SV_ringelt_debug.cc)
25 cl_class& cl_class_svector_ringelt()
26 {
27         static cl_class instance = {
28                 cl_svector_ringelt_destructor,
29                 0
30         };
31         return instance;
32 }
33
34 cl_heap_SV_ringelt* cl_make_heap_SV_ringelt_uninit (std::size_t len)
35 {
36         cl_heap_SV_ringelt* hv = (cl_heap_SV_ringelt*) malloc_hook(sizeof(cl_heap_SV_ringelt)+sizeof(_cl_ring_element)*len);
37         hv->refcount = 1;
38         hv->type = &cl_class_svector_ringelt();
39         new (&hv->v) cl_SV_inner<_cl_ring_element> (len);
40         // Have to fill hv->v[i] (0 <= i < len) yourself.
41         return hv;
42 }
43
44 cl_heap_SV_ringelt* cl_make_heap_SV_ringelt (std::size_t len)
45 {
46         cl_heap_SV_ringelt* hv = (cl_heap_SV_ringelt*) malloc_hook(sizeof(cl_heap_SV_ringelt)+sizeof(_cl_ring_element)*len);
47         hv->refcount = 1;
48         hv->type = &cl_class_svector_ringelt();
49         new (&hv->v) cl_SV_inner<_cl_ring_element> (len);
50         for (std::size_t i = 0; i < len; i++)
51                 init1(_cl_ring_element, hv->v[i]) ();
52         return hv;
53 }
54
55 // An empty vector.
56 const cl_SV_ringelt cl_null_SV_ringelt = cl_null_SV_ringelt;
57
58 int cl_SV_ringelt_init_helper::count = 0;
59
60 cl_SV_ringelt_init_helper::cl_SV_ringelt_init_helper()
61 {
62         if (count++ == 0)
63                 new ((void *)&cl_null_SV_ringelt) cl_SV_ringelt((std::size_t)0);
64 }
65
66 cl_SV_ringelt_init_helper::~cl_SV_ringelt_init_helper()
67 {
68         if (--count == 0) {
69                 // Nothing to clean up here
70         }
71 }
72
73 }  // namespace cln
74