]> www.ginac.de Git - cln.git/blob - src/base/ring/cl_no_ring.cc
Cater to the fact that g++ 4.3 will use a different naming for
[cln.git] / src / base / ring / cl_no_ring.cc
1 // Dummy ring.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 CL_PROVIDE(cl_no_ring)
7
8 // Specification.
9 #include "cln/ring.h"
10
11
12 // Implementation.
13
14 #include <sstream>
15 #include "cln/io.h"
16
17 namespace cln {
18
19 uninitialized_ring_exception::uninitialized_ring_exception ()
20         : runtime_exception("Uninitialized ring operation called.")
21 {}
22
23 static inline const std::string
24 uninitialized_error_msg (const _cl_ring_element& obj)
25 {
26         std::ostringstream buf;
27         fprint(buf, "Uninitialized ring element @0x");
28         fprinthexadecimal(buf, (unsigned long)(void*)&obj);
29         fprint(buf, ": 0x");
30         fprinthexadecimal(buf, (unsigned long)obj.rep.word);
31         return buf.str();
32 }
33
34 static inline const std::string
35 uninitialized_error_msg (const _cl_ring_element& obj_x, const _cl_ring_element& obj_y)
36 {
37         std::ostringstream buf;
38         fprint(buf, "Uninitialized ring elements @0x");
39         fprinthexadecimal(buf, (unsigned long)(void*)&obj_x);
40         fprint(buf, ": 0x");
41         fprinthexadecimal(buf, (unsigned long)obj_x.rep.word);
42         fprint(buf, ", @0x");
43         fprinthexadecimal(buf, (unsigned long)(void*)&obj_y);
44         fprint(buf, ": 0x");
45         fprinthexadecimal(buf, (unsigned long)obj_y.rep.word);
46         return buf.str();
47 }
48
49 uninitialized_exception::uninitialized_exception (const _cl_ring_element& obj)
50         : runtime_exception(uninitialized_error_msg(obj))
51 {}
52
53 uninitialized_exception::uninitialized_exception (const _cl_ring_element& obj_x, const _cl_ring_element& obj_y)
54         : runtime_exception(uninitialized_error_msg(obj_x, obj_y))
55 {}
56
57
58 static const _cl_ring_element dummy_op0 (cl_heap_ring* R)
59 {
60         unused R;
61         throw uninitialized_ring_exception();
62 }
63
64 static const _cl_ring_element dummy_op1 (cl_heap_ring* R, const _cl_ring_element& x)
65 {
66         unused R;
67         throw uninitialized_exception(x);
68 }
69
70 static const _cl_ring_element dummy_op2 (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
71 {
72         unused R;
73         throw uninitialized_exception(x, y);
74 }
75
76 static void dummy_fprint (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x)
77 {
78         unused R;
79         unused stream;
80         throw uninitialized_exception(x);
81 }
82 static bool dummy_equal (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
83 {
84         unused R;
85         throw uninitialized_exception(x, y);
86 }
87
88 #define dummy_zero dummy_op0
89 static bool dummy_zerop (cl_heap_ring* R, const _cl_ring_element& x)
90 {
91         unused R;
92         throw uninitialized_exception(x);
93 }
94 #define dummy_plus dummy_op2
95 #define dummy_minus dummy_op2
96 #define dummy_uminus dummy_op1
97
98 #define dummy_one dummy_op0
99 static const _cl_ring_element dummy_canonhom (cl_heap_ring* R, const cl_I& x)
100 {
101         unused R;
102         (void)&x; // unused x;
103         throw uninitialized_ring_exception();
104 }
105 #define dummy_mul dummy_op2
106 #define dummy_square dummy_op1
107 static const _cl_ring_element dummy_expt_pos (cl_heap_ring* R, const _cl_ring_element& x, const cl_I& y)
108 {
109         unused R;
110         (void)&y; // unused y;
111         throw uninitialized_exception(x);
112 }
113
114 static cl_ring_setops dummy_setops = {
115         dummy_fprint,
116         dummy_equal
117 };
118 static cl_ring_addops dummy_addops = {
119         dummy_zero,
120         dummy_zerop,
121         dummy_plus,
122         dummy_minus,
123         dummy_uminus
124 };
125 static cl_ring_mulops dummy_mulops = {
126         dummy_one,
127         dummy_canonhom,
128         dummy_mul,
129         dummy_square,
130         dummy_expt_pos
131 };
132
133 class cl_heap_no_ring : public cl_heap_ring {
134         SUBCLASS_cl_heap_ring()
135 public:
136         // Constructor.
137         cl_heap_no_ring ()
138                 : cl_heap_ring (&dummy_setops,&dummy_addops,&dummy_mulops)
139                 { type = &cl_class_no_ring; }
140         // Destructor.
141         ~cl_heap_no_ring () {}
142 };
143
144 static void cl_no_ring_destructor (cl_heap* pointer)
145 {
146         (*(cl_heap_no_ring*)pointer).~cl_heap_no_ring();
147 }
148
149 static void cl_no_ring_dprint (cl_heap* pointer)
150 {
151         unused pointer;
152         fprint(cl_debugout, "(cl_ring) cl_no_ring");
153 }
154
155 cl_class cl_class_no_ring = {
156         cl_no_ring_destructor,
157         0,
158         cl_no_ring_dprint
159 };
160
161 const cl_ring cl_no_ring = cl_ring (new cl_heap_no_ring());
162
163 }  // namespace cln
164
165 CL_PROVIDE_END(cl_no_ring)