]> www.ginac.de Git - cln.git/blobdiff - src/complex/ring/cl_C_ring.cc
Replace unused macro with cl_unused.
[cln.git] / src / complex / ring / cl_C_ring.cc
index 5a576ece813e2ac2e24be81b05d0c1b9ed4fb6f3..626cc5b3ad7c23613e55607d31c36bcfeed5dd94 100644 (file)
@@ -1,9 +1,7 @@
 // Ring of complex numbers.
 
 // General includes.
-#include "cl_sysdep.h"
-
-CL_PROVIDE(cl_C_ring)
+#include "base/cl_sysdep.h"
 
 // Specification.
 #include "cln/complex_ring.h"
@@ -13,19 +11,19 @@ CL_PROVIDE(cl_C_ring)
 
 #include "cln/complex.h"
 #include "cln/complex_io.h"
-#include "cl_C.h"
+#include "complex/cl_C.h"
 
 namespace cln {
 
 static void N_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
 {
-       unused R;
+       cl_unused R;
        fprint(stream,The(cl_N)(x));
 }
 
-static cl_boolean N_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
+static bool N_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
 {
-       unused R;
+       cl_unused R;
        return equal(The(cl_N)(x),The(cl_N)(y));
 }
 
@@ -34,9 +32,9 @@ static const _cl_ring_element N_zero (cl_heap_ring* R)
        return _cl_ring_element(R, (cl_N)0);
 }
 
-static cl_boolean N_zerop (cl_heap_ring* R, const _cl_ring_element& x)
+static bool N_zerop (cl_heap_ring* R, const _cl_ring_element& x)
 {
-       unused R;
+       cl_unused R;
        // Here we return true only if x is the *exact* zero. Because we
        // don't want the degree of polynomials to depend on rounding errors.
        // For all ring theoretic purposes, we treat 0.0, 0+0.0i etc. as if
@@ -84,12 +82,10 @@ static const _cl_ring_element N_expt_pos (cl_heap_ring* R, const _cl_ring_elemen
        return _cl_ring_element(R, expt(The(cl_N)(x),y));
 }
 
-static cl_boolean cl_N_p (const cl_number& x)
+static bool cl_N_p (const cl_number& x)
 {
-       return (cl_boolean)
-              (!x.pointer_p()
-               || (x.pointer_type()->flags & cl_class_flags_subclass_complex) != 0
-              );
+       return (!x.pointer_p()
+               || (x.pointer_type()->flags & cl_class_flags_subclass_complex) != 0);
 }
 
 static cl_ring_setops N_setops = {
@@ -142,23 +138,38 @@ static void cl_complex_ring_destructor (cl_heap* pointer)
 
 static void cl_complex_ring_dprint (cl_heap* pointer)
 {
-       unused pointer;
+       cl_unused pointer;
        fprint(cl_debugout, "(cl_complex_ring) cl_C_ring");
 }
 
-cl_class cl_class_complex_ring = {
-       cl_complex_ring_destructor,
-       cl_class_flags_number_ring,
-       cl_complex_ring_dprint
-};
+cl_class cl_class_complex_ring;
+static cl_heap_complex_ring* cl_heap_complex_ring_instance;
+const cl_complex_ring cl_C_ring = cl_C_ring;
 
 // Constructor.
 template <>
 inline cl_complex_ring::cl_specialized_number_ring ()
-       : cl_number_ring (new cl_heap_complex_ring()) {}
+       : cl_number_ring(cl_heap_complex_ring_instance) { }
+
+int cl_C_ring_init_helper::count = 0;
+
+cl_C_ring_init_helper::cl_C_ring_init_helper()
+{
+       if (count++ == 0) {
+               cl_class_complex_ring.destruct = cl_complex_ring_destructor;
+               cl_class_complex_ring.flags = cl_class_flags_number_ring;
+               cl_class_complex_ring.dprint = cl_complex_ring_dprint;
+               cl_heap_complex_ring_instance = new cl_heap_complex_ring();
+               new ((void *)&cl_C_ring) cl_complex_ring();
+       }
+}
 
-const cl_complex_ring cl_C_ring;
+cl_C_ring_init_helper::~cl_C_ring_init_helper()
+{
+       if (--count == 0) {
+               delete cl_heap_complex_ring_instance;
+       }
+}
 
 }  // namespace cln
 
-CL_PROVIDE_END(cl_C_ring)