]> www.ginac.de Git - cln.git/blob - include/cln/GV_integer.h
2006-05-30 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
[cln.git] / include / cln / GV_integer.h
1 // General vectors of integers.
2
3 #ifndef _CL_GV_INTEGER_H
4 #define _CL_GV_INTEGER_H
5
6 #include "cln/number.h"
7 #include "cln/GV_rational.h"
8 #include "cln/integer_class.h"
9 #include "cln/io.h"
10
11 namespace cln {
12
13 // A vector of integers is *not* just a normal vector of numbers (the vectorops
14 // support the maxbits() operation), but we treat can it like this nevertheless.
15
16 template <>
17 struct cl_heap_GV<cl_I> : cl_heap {
18         cl_GV_inner<cl_I> v;
19         // here room for the elements
20         sintC maxbits () const;
21 };
22 typedef cl_heap_GV<cl_I> cl_heap_GV_I;
23
24 struct cl_GV_I : public cl_GV<cl_I,cl_GV_RA> {
25 public:
26         // Constructors.
27         cl_GV_I ();
28         cl_GV_I (const cl_GV_I&);
29         // Create a vector of unconstrained integers.
30         explicit cl_GV_I (uintC len);
31         // Create a vector of m-bit integers (>=0, <2^m).
32         cl_GV_I (uintC len, sintC m);
33         // Assignment operators.
34         cl_GV_I& operator= (const cl_GV_I&);
35         // Number m of bits allowed per element (-1 if unconstrained).
36         sintC maxbits () const
37         {
38                 return ((const cl_heap_GV_I *) pointer)->maxbits();
39         }
40         // Private pointer manipulations.
41         cl_GV_I (cl_heap_GV_I* p) : cl_GV<cl_I,cl_GV_RA> (p) {}
42         cl_GV_I (cl_private_thing p) : cl_GV<cl_I,cl_GV_RA> (p) {}
43 };
44 inline cl_GV_I::cl_GV_I (const cl_GV_I& x) : cl_GV<cl_I,cl_GV_RA> (as_cl_private_thing(x)) {}
45 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_GV_I,cl_GV_I)
46 extern cl_heap_GV_I* cl_make_heap_GV_I (uintC len);
47 inline cl_GV_I::cl_GV_I (uintC len)
48         : cl_GV<cl_I,cl_GV_RA> (cl_make_heap_GV_I(len)) {}
49 extern cl_heap_GV_I* cl_make_heap_GV_I (uintC len, sintC m);
50 inline cl_GV_I::cl_GV_I (uintC len, sintC m)
51         : cl_GV<cl_I,cl_GV_RA> (cl_make_heap_GV_I(len,m)) {}
52
53 // Private pointer manipulations. Never throw away a `struct cl_heap_GV_I *'!
54 extern const cl_GV_I cl_null_GV_I;
55 inline cl_GV_I::cl_GV_I ()
56         : cl_GV<cl_I,cl_GV_RA> ((cl_heap_GV_I*) cl_null_GV_I) {}
57 CL_REQUIRE(cl_GV_I)
58
59 // Copy a vector.
60 extern const cl_GV_I copy (const cl_GV_I&);
61
62 // Output.
63 inline void fprint (std::ostream& stream, const cl_GV_I& x)
64 {
65         extern cl_print_flags default_print_flags;
66         extern void print_vector (std::ostream& stream, const cl_print_flags& flags, void (* fun) (std::ostream&, const cl_print_flags&, const cl_number&), const cl_GV_number& vector);
67         extern void print_integer (std::ostream& stream, const cl_print_flags& flags, const cl_I& z);
68         print_vector(stream, default_print_flags,
69                      (void (*) (std::ostream&, const cl_print_flags&, const cl_number&))
70                      (void (*) (std::ostream&, const cl_print_flags&, const cl_I&))
71                      &print_integer,
72                      x);
73 }
74 CL_DEFINE_PRINT_OPERATOR(cl_GV_I)
75
76 // Debugging support.
77 #ifdef CL_DEBUG
78 extern int cl_GV_I_debug_module;
79 CL_FORCE_LINK(cl_GV_I_debug_dummy, cl_GV_I_debug_module)
80 #endif
81
82 }  // namespace cln
83
84 #endif /* _CL_GV_INTEGER_H */