X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=include%2Fcln%2FSV.h;h=e4e785ee1e8c80d0023b9a1d77c492c93b856eff;hb=HEAD;hp=87845f18b0a8164fc938529c122782602f4cc466;hpb=34f61129e8e473aa3d8001c632ca1ebb39152057;p=cln.git diff --git a/include/cln/SV.h b/include/cln/SV.h index 87845f1..e4e785e 100644 --- a/include/cln/SV.h +++ b/include/cln/SV.h @@ -5,8 +5,9 @@ #include "cln/object.h" #include "cln/V.h" -#include "cln/abort.h" -#include +#include "cln/exception.h" +#include +#include namespace cln { @@ -40,24 +41,24 @@ template class cl_SV_inner; template class cl_SV_inner { protected: - uintL len; // number of elements + std::size_t len; // number of elements private: // T data[]; // the elements T * data() { return (T *) (this+1); } const T * data() const { return (const T *) (this+1); } public: - uintL length () const { return len; } // number of elements + std::size_t size() const { return len; } // number of elements const T & operator[] (unsigned long index) const { #ifndef CL_SV_NO_RANGECHECKS - if (!(index < length())) cl_abort(); + if (!(index < size())) throw runtime_exception(); #endif return data()[index]; } T & operator[] (unsigned long index) { #ifndef CL_SV_NO_RANGECHECKS - if (!(index < length())) cl_abort(); + if (!(index < size())) throw runtime_exception(); #endif return data()[index]; } @@ -74,9 +75,29 @@ public: { return operator[]((unsigned long)index); } T & operator[] (int index) { return operator[]((unsigned long)index); } + #if long_bitsize < pointer_bitsize + const T & operator[] (unsigned long long index) const + { + #ifndef CL_SV_NO_RANGECHECKS + if (!(index < size())) throw runtime_exception(); + #endif + return data()[index]; + } + T & operator[] (unsigned long long index) + { + #ifndef CL_SV_NO_RANGECHECKS + if (!(index < size())) throw runtime_exception(); + #endif + return data()[index]; + } + const T & operator[] (long long index) const + { return operator[]((unsigned long long)index); } + T & operator[] (long long index) + { return operator[]((unsigned long long)index); } + #endif public: /* ugh */ // Constructor. - cl_SV_inner (uintL l) : len (l) {} + cl_SV_inner (std::size_t l) : len (l) {} public: // Destructor. ~cl_SV_inner (); @@ -95,7 +116,7 @@ private: template inline cl_SV_inner::~cl_SV_inner () { - uintL i = len; + std::size_t i = len; while (i > 0) { i--; data()[i].~T(); @@ -115,9 +136,9 @@ template struct cl_SV : public BASE { public: // Length. - uintL length () const + std::size_t size() const { - return ((const cl_heap_SV *) this->pointer)->v.length(); + return ((const cl_heap_SV *) this->pointer)->v.size(); } // Reference. Forbid modification of `const cl_SV&' arguments. const T & operator[] (unsigned long index) const @@ -141,6 +162,20 @@ public: { return operator[]((unsigned long)index); } T & operator[] (int index) { return operator[]((unsigned long)index); } + #if long_bitsize < pointer_bitsize + const T & operator[] (unsigned long long index) const + { + return ((const cl_heap_SV *) this->pointer)->v[index]; + } + T & operator[] (unsigned long long index) + { + return ((cl_heap_SV *) this->pointer)->v[index]; + } + const T & operator[] (long long index) const + { return operator[]((unsigned long long)index); } + T & operator[] (long long index) + { return operator[]((unsigned long long)index); } + #endif // Constructors. cl_SV (const cl_SV&); // Assignment operators.