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