]> www.ginac.de Git - cln.git/blobdiff - include/cln/string.h
Replace CL_REQUIRE/CL_PROVIDE(cl_prin_globals) with portable code.
[cln.git] / include / cln / string.h
index b9f2de2a6fa5bf6a7998944af03929c49ba065cf..c316f04e8a758d1d839c634365c447ada0285a8a 100644 (file)
@@ -5,20 +5,22 @@
 
 #include "cln/object.h"
 #include "cln/io.h"
-#include "cln/abort.h"
-#include <string.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.
@@ -131,7 +133,7 @@ CL_REQUIRE(cl_st_null)
 extern unsigned long hashcode (const cl_string& str);
 
 // Output.
-extern void fprint (cl_ostream stream, const cl_string& str);
+extern void fprint (std::ostream& stream, const cl_string& str);
 CL_DEFINE_PRINT_OPERATOR(cl_string)
 
 // Input.
@@ -139,23 +141,23 @@ CL_DEFINE_PRINT_OPERATOR(cl_string)
 // Reads a line. Up to delim. The delimiter character is not placed in the
 // resulting string. The delimiter character is kept in the input stream.
 // If EOF is encountered, the stream's eofbit is set.
-extern const cl_string cl_fget (cl_istream stream, char delim = '\n');
+extern const cl_string cl_fget (std::istream& stream, char delim = '\n');
 
 // Reads a line. Up to delim. The delimiter character is not placed in the
 // resulting string. The delimiter character is extracted from the input stream.
 // If EOF is encountered, the stream's eofbit is set.
-extern const cl_string cl_fgetline (cl_istream stream, char delim = '\n');
+extern const cl_string cl_fgetline (std::istream& stream, char delim = '\n');
 
 // Like above, but only up to n-1 characters. If n-1 characters were read
 // before the delimiter character was seen, the stream's failbit is set.
-extern const cl_string cl_fget (cl_istream stream, int n, char delim = '\n');
-extern const cl_string cl_fgetline (cl_istream stream, int n, char delim = '\n');
+extern const cl_string cl_fget (std::istream& stream, int n, char delim = '\n');
+extern const cl_string cl_fgetline (std::istream& stream, int n, char delim = '\n');
 
 // Skips whitespace and then reads a non-whitespace string.
 // If stream.width() is greater than 0, at most stream.width()-1 non-whitespace
 // characters are read. When done, stream.width(0) is called.
 // If EOF is encountered, the stream's eofbit is set.
-extern cl_istream operator>> (cl_istream stream, cl_string& str);
+extern std::istream& operator>> (std::istream& stream, cl_string& str);
 
 // Runtime typing support.
 extern cl_class cl_class_string;
@@ -163,9 +165,7 @@ extern cl_class cl_class_string;
 // Debugging support.
 #ifdef CL_DEBUG
 extern int cl_string_debug_module;
-static void* const cl_string_debug_dummy[] = { &cl_string_debug_dummy,
-       &cl_string_debug_module
-};
+CL_FORCE_LINK(cl_string_debug_dummy, cl_string_debug_module)
 #endif
 
 }  // namespace cln