]> www.ginac.de Git - cln.git/blobdiff - include/cln/string.h
Replace CL_REQUIRE/CL_PROVIDE(cl_I_ring) with portable code.
[cln.git] / include / cln / string.h
index cfd8b497fe15e2d295811399d1ebb56a5a6b5232..f7da4a2c7b9d03d6d85704e09fe7ad7c642c6f98 100644 (file)
@@ -5,20 +5,22 @@
 
 #include "cln/object.h"
 #include "cln/io.h"
-#include "cln/abort.h"
+#include "cln/exception.h"
 #include <cstring>
 
 namespace cln {
 
+struct cl_string;
+
 // General, reference counted and garbage collected strings.
 struct cl_heap_string : public cl_heap {
 private:
        unsigned long length;   // length (in characters)
        char data[1];           // the characters, plus a '\0' at the end
        // Standard allocation disabled.
-       void* operator new (size_t size) { (void)size; cl_abort(); return (void*)1; }
+       void* operator new (size_t size) { (void)size; throw runtime_exception(); }
        // Standard deallocation disabled.
-       void operator delete (void* ptr) { (void)ptr; cl_abort(); }
+       void operator delete (void* ptr) { (void)ptr; throw runtime_exception(); }
        // No default constructor.
        cl_heap_string ();
 private:
@@ -50,7 +52,7 @@ public:
        // Return a specific character.
        char operator[] (unsigned long i) const
        {
-               if (!(i < length())) cl_abort(); // Range check.
+               if (!(i < length())) throw runtime_exception(); // Range check.
                return ((cl_heap_string*)pointer)->data[i];
        }
        // New ANSI C++ compilers also want the following.
@@ -122,10 +124,9 @@ inline cl_string::operator cl_heap_string* () const
 }
 inline cl_string::cl_string ()
 {
-       extern const cl_string cl_null_string;
-       pointer = (cl_heap_string*) cl_null_string;
+       static const cl_string cl_null_st(NULL, 0);
+       pointer = (cl_heap_string*) cl_null_st;
 }
-CL_REQUIRE(cl_st_null)
 
 // Hash code.
 extern unsigned long hashcode (const cl_string& str);