diff options
author | pixel <pixel> | 2003-10-05 19:14:04 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-10-05 19:14:04 +0000 |
commit | 0a1ad13e6d89ceeb90b89a22b5577559c7c97366 (patch) | |
tree | cee700fb5eb2af7dd31539cb474c7d812f184504 | |
parent | d80ce60cfd34ee994e67f9b1a419f44fb113fd00 (diff) |
Changes of the month
-rw-r--r-- | include/BString.h | 1 | ||||
-rw-r--r-- | include/Exceptions.h | 10 | ||||
-rw-r--r-- | lib/Exceptions.cc | 34 | ||||
-rw-r--r-- | lib/String.cc | 12 |
4 files changed, 52 insertions, 5 deletions
diff --git a/include/BString.h b/include/BString.h index 4540e70..c4703f0 100644 --- a/include/BString.h +++ b/include/BString.h @@ -60,6 +60,7 @@ class String : public Base { bool operator<(const String &) const; bool operator>(const String &) const; char operator[](size_t i) const; + char & operator[](size_t i); operator ugly_string() const; String & toupper(); String & tolower(); diff --git a/include/Exceptions.h b/include/Exceptions.h index 98f6c52..17fe093 100644 --- a/include/Exceptions.h +++ b/include/Exceptions.h @@ -5,6 +5,7 @@ #include <stddef.h> #include <string.h> #include <stdlib.h> +#include <vector> #include <generic.h> #if !defined pid_t && !defined _SYS_TYPES_H @@ -35,10 +36,14 @@ class Base { static void exit(int); static void printm(int level, const ugly_string &, ...); static void printm(int level, const char *, ...); + static void exception(const String &); + static void pushcontext(const String &); + static void popcontext(void); + static void flushcontext(void); + private: + static std::vector<String> context; }; -class String; - class GeneralException : public Base { public: GeneralException(String); @@ -61,6 +66,7 @@ void * xrealloc(void *, size_t); int xpipe(int *, int = 0) throw (GeneralException); pid_t xfork() throw (GeneralException); void xexit(int) throw (GeneralException); +void xexception(const String &) throw (GeneralException); class MemoryException : public GeneralException { public: diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc index fe3aecc..85b4429 100644 --- a/lib/Exceptions.cc +++ b/lib/Exceptions.cc @@ -5,9 +5,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#ifdef HAVE_GLIB -#include <glib.h> -#endif #ifdef DEBUG #include <iostream> #endif @@ -21,6 +18,8 @@ char GeneralException::t[BUFSIZ]; +std::vector<String> Base::context; + GeneralException::GeneralException(String emsg) : msg(emsg.strdup()) { #ifdef DEBUG printm(M_BARE, String(_("Generating a General Exception error: '")) + msg + "'.\n"); @@ -179,6 +178,10 @@ void xexit(int status) throw (GeneralException) { throw Exit(status); } +void xexception(const String & err) throw (GeneralException) { + throw GeneralException(err); +} + char * Base::strdup(const char * s) { return xstrdup(s); } @@ -239,3 +242,28 @@ pid_t Base::fork() { void Base::exit(int status) { xexit(status); } + +void Base::flushcontext() { + context.clear(); +} + +void Base::pushcontext(const String & c) { + context.push_back(c); +} + +void Base::popcontext() { + context.pop_back(); +} + +void Base::exception(const String & err) { + int c; + std::vector<String>::iterator i; + printm(M_ERROR, "Error detected, showing context.\n"); + for (i = context.begin(), c = 0; i != context.end(); i++, c++) { + printm(M_ERROR, " (%i) - " + *i + "\n", c); + } + + printm(M_ERROR, " Error description: " + err); + + xexception(err); +} diff --git a/lib/String.cc b/lib/String.cc index bd265a0..75d9d15 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -331,6 +331,18 @@ char String::operator[](size_t i) const { } } +char & String::operator[](size_t i) { + static char zero; + + zero = 0; + + if (i >= siz) { + return zero; + } else { + return str[i]; + } +} + ssize_t String::strchr(char c, size_t from) const { for (size_t i = from; i < siz; i++) { if (str[i] == c) return i; |