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 (std::size_t len); 31 // Create a vector of m-bit integers (>=0, <2^m). 32 cl_GV_I (std::size_t 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 (std::size_t len); 47 inline cl_GV_I::cl_GV_I (std::size_t 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 (std::size_t len, sintC m); 50 inline cl_GV_I::cl_GV_I (std::size_t 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 class cl_GV_I_init_helper 58 { 59 static int count; 60 public: 61 cl_GV_I_init_helper(); 62 ~cl_GV_I_init_helper(); 63 }; 64 static cl_GV_I_init_helper cl_GV_I_init_helper_instance; 65 66 // Copy a vector. 67 extern const cl_GV_I copy (const cl_GV_I&); 68 69 // Output. 70 inline void fprint (std::ostream& stream, const cl_GV_I& x) 71 { 72 extern cl_print_flags default_print_flags; 73 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); 74 extern void print_integer (std::ostream& stream, const cl_print_flags& flags, const cl_I& z); 75 print_vector(stream, default_print_flags, 76 (void (*) (std::ostream&, const cl_print_flags&, const cl_number&)) 77 (void (*) (std::ostream&, const cl_print_flags&, const cl_I&)) 78 &print_integer, 79 x); 80 } 81 CL_DEFINE_PRINT_OPERATOR(cl_GV_I) 82 83 // Debugging support. 84 #ifdef CL_DEBUG 85 extern int cl_GV_I_debug_module; 86 CL_FORCE_LINK(cl_GV_I_debug_dummy, cl_GV_I_debug_module) 87 #endif 88 89 } // namespace cln 90 91 #endif /* _CL_GV_INTEGER_H */ 92