]> www.ginac.de Git - cln.git/blobdiff - include/cln/GV.h
cl_{GV,SV}: use std::size_t for size of vectors (instead of obscure uintC).
[cln.git] / include / cln / GV.h
index ed83e275dc77426aed8c275bee2c5a14f91a8ab8..338edfa27300bc4900c1e606d0609f0baf111280 100644 (file)
@@ -5,13 +5,14 @@
 
 #include "cln/object.h"
 #include "cln/V.h"
-#include "cln/abort.h"
+#include "cln/exception.h"
 #include <cstdlib>
+#include <cstddef>
 
 namespace cln {
 
 // A vector is a structure having the following interface:
-//     v.length()        returns the number of elements
+//     v.size()        returns the number of elements
 //     v[i]              returns the i-th element (0<=i<length), as a
 //                       pseudo-lvalue (you can assign to it, but not take its
 //                       address - exactly what you want for bit-vectors)
@@ -25,9 +26,9 @@ template <class T> struct cl_GV_vectorops;
 template <class T>
 class cl_GV_inner {
 protected:
-       uintL len; // number of elements
+       std::size_t len; // number of elements
 public:
-       uintL length () const; // number of elements
+       std::size_t size() const; // number of elements
        cl_GV_vectorops<T>* vectorops; // get/set element
        const cl_GV_index<T> operator[] (unsigned long index);
        const cl_GV_constindex<T> operator[] (unsigned long index) const;
@@ -39,7 +40,7 @@ public:
        const cl_GV_constindex<T> operator[] (int index) const;
 public: /* ugh */
        // Constructor.
-       cl_GV_inner (uintL l, cl_GV_vectorops<T>* ops) : len (l), vectorops (ops) {}
+       cl_GV_inner (std::size_t l, cl_GV_vectorops<T>* ops) : len (l), vectorops (ops) {}
 public:
        // Destructor.
        ~cl_GV_inner ();
@@ -63,10 +64,10 @@ class cl_GV_index {
        // through [].
 public:
        cl_GV_inner<T>* vec;
-       uintL index;
+       std::size_t index;
        operator T () const;
        // Constructor:
-       cl_GV_index (cl_GV_inner<T>* v, uintL i) : vec (v), index (i) {}
+       cl_GV_index (cl_GV_inner<T>* v, std::size_t i) : vec (v), index (i) {}
        // Assignment operator.
        void operator= (const T& x) const;
 #if (defined(__sparc__) || defined(__sparc64__) || defined(__mips__) || defined(__mips64__)) && !defined(__GNUC__) // maybe an SGI CC and Sun CC bug?
@@ -88,10 +89,10 @@ class cl_GV_constindex {
        // through []. It lacks the assignment operator.
 public:
        const cl_GV_inner<T>* vec;
-       uintL index;
+       std::size_t index;
        operator T () const;
        // Constructor:
-       cl_GV_constindex (const cl_GV_inner<T>* v, uintL i) : vec (v), index (i) {}
+       cl_GV_constindex (const cl_GV_inner<T>* v, std::size_t i) : vec (v), index (i) {}
 private:
 // No default constructor, assignment operator.
        cl_GV_constindex ();
@@ -100,16 +101,16 @@ private:
 
 template <class T>
 struct cl_GV_vectorops {
-       const T (*element) (const cl_GV_inner<T>* vec, uintL index);
-       void (*set_element) (cl_GV_inner<T>* vec, uintL index, const T& x);
+       const T (*element) (const cl_GV_inner<T>* vec, std::size_t index);
+       void (*set_element) (cl_GV_inner<T>* vec, std::size_t index, const T& x);
        void (*do_delete) (cl_GV_inner<T>* vec);
-       void (*copy_elements) (const cl_GV_inner<T>* srcvec, uintL srcindex, cl_GV_inner<T>* destvec, uintL destindex, uintL count);
+       void (*copy_elements) (const cl_GV_inner<T>* srcvec, std::size_t srcindex, cl_GV_inner<T>* destvec, std::size_t destindex, std::size_t count);
 };
 
 // All member functions are inline.
 
 template <class T>
-inline uintL cl_GV_inner<T>::length () const
+inline std::size_t cl_GV_inner<T>::size() const
 {
        return len;
 }
@@ -172,7 +173,7 @@ template <class T>
 inline cl_GV_index<T>::operator T () const
 {
        #ifndef CL_GV_NO_RANGECHECKS
-       if (!(index < vec->len)) cl_abort();
+       if (!(index < vec->len)) throw runtime_exception();
        #endif
        return vec->vectorops->element(vec,index);
 }
@@ -181,7 +182,7 @@ template <class T>
 inline void cl_GV_index<T>::operator= (const T& x) const
 {
        #ifndef CL_GV_NO_RANGECHECKS
-       if (!(index < vec->len)) cl_abort();
+       if (!(index < vec->len)) throw runtime_exception();
        #endif
        vec->vectorops->set_element(vec,index,x);
 }
@@ -190,7 +191,7 @@ template <class T>
 inline cl_GV_constindex<T>::operator T () const
 {
        #ifndef CL_GV_NO_RANGECHECKS
-       if (!(index < vec->len)) cl_abort();
+       if (!(index < vec->len)) throw runtime_exception();
        #endif
        return vec->vectorops->element(vec,index);
 }
@@ -219,9 +220,9 @@ template <class T, class BASE>
 struct cl_GV : public BASE {
 public:
        // Length.
-       uintL length () const
+       std::size_t size() const
        {
-               return ((const cl_heap_GV<T> *) this->pointer)->v.length();
+               return ((const cl_heap_GV<T> *) this->pointer)->v.size();
        }
        // Reference. Forbid modification of `const cl_GV&' arguments.
        const cl_GV_constindex<T> operator[] (unsigned long index) const
@@ -250,12 +251,12 @@ public:
        cl_GV& operator= (const cl_GV&);
        // Copy a piece of a vector into another vector.
        // (Both vectors must be of the same type. Overlapping not allowed.)
-       static void copy_elements (const cl_GV& src, uintL srcindex, cl_GV& dest, uintL destindex, uintL count)
+       static void copy_elements (const cl_GV& src, std::size_t srcindex, cl_GV& dest, std::size_t destindex, std::size_t count)
        {
                const cl_heap_GV<T> * hsrc = (const cl_heap_GV<T> *) src.pointer;
                cl_heap_GV<T> * hdest = (cl_heap_GV<T> *) dest.pointer;
                if (!(hsrc->v.vectorops == hdest->v.vectorops))
-                       cl_abort();
+                       throw runtime_exception();
                hsrc->v.vectorops->copy_elements(&hsrc->v,srcindex,&hdest->v,destindex,count);
        }
        // Private pointer manipulations.