diff options
author | Pixel <Pixel> | 2002-07-21 11:12:13 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-07-21 11:12:13 +0000 |
commit | 6528f07c516efe4d3b344f01740067878d5d9a43 (patch) | |
tree | f097e6797752dffe7b498a4f153e83bdeb59f024 /includes/Exceptions.h | |
parent | b54786a5120b48bd98fc4b199176d45bda3c2d67 (diff) |
Hello Baltisot
Diffstat (limited to 'includes/Exceptions.h')
-rw-r--r-- | includes/Exceptions.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/includes/Exceptions.h b/includes/Exceptions.h new file mode 100644 index 0000000..ef697e7 --- /dev/null +++ b/includes/Exceptions.h @@ -0,0 +1,137 @@ +#ifndef __EXCEPTIONS_H__ +#define __EXCEPTIONS_H__ +#ifdef __cplusplus + +#include <stdio.h> +#include <unistd.h> +#include <stddef.h> +#include <string.h> +#include <stdlib.h> + +#define INLINE __inline__ + +class Base { + public: + static char * strdup(const char * s); + static void * malloc(ssize_t s); + static void * realloc(void * p, size_t s); + static void * calloc(size_t n, size_t s); + void * operator new(size_t s); + void * operator new(size_t s, void * p); + void operator delete(void * p); + static void free(void *& p); + static void free(char *& p); + static int pipe(int * p, int flag = 0); + static pid_t fork(); +}; + +class String; + +class GeneralException : public Base { + public: + GeneralException(String); + GeneralException(const GeneralException &); + ~GeneralException(); + char * GetMsg(); + + protected: + GeneralException(); + char * msg; + static char t[BUFSIZ]; +}; + +char * xstrdup(const char *); +void * xmalloc(size_t) throw (GeneralException); +void xfree(void *&); +void xfree(char *&); +void * xrealloc(void *, size_t); +int xpipe(int *, int = 0) throw (GeneralException); +pid_t xfork() throw (GeneralException); + +INLINE char * Base::strdup(const char * s) { + return xstrdup(s); +} + +INLINE void * Base::malloc(ssize_t s) { + return xmalloc(s); +} + +INLINE void * Base::realloc(void * p, size_t s) { + return xrealloc(p, s); +} + +INLINE void * Base::calloc(size_t n, size_t s) { + return xmalloc(n * s); +} + +INLINE void * Base::operator new(size_t s) { + return xmalloc(s); +} + +INLINE void * Base::operator new(size_t s, void * p) { + return memset(p, 0, s); +} + +INLINE void Base::operator delete(void * p) { + xfree(p); +} + +INLINE void Base::free(void *& p) { + xfree(p); +} + +INLINE void Base::free(char *& p) { + xfree(p); +} + +INLINE int Base::pipe(int * p, int flag) { + return xpipe(p, flag); +} + +INLINE pid_t Base::fork() { + return xfork(); +} + +class MemoryException : public GeneralException { + public: + MemoryException(ssize_t); +}; + +class TaskNotFound : public GeneralException { + public: + TaskNotFound(); +}; + +enum op_t { + IO_WRITE = 1, + IO_READ +}; + +class IOGeneral : public GeneralException { + public: + IOGeneral(String); + protected: + IOGeneral(); +}; + +class IOException : public IOGeneral { + public: + IOException(String, op_t, ssize_t); +}; + +class IOAgain : public IOGeneral { + public: + IOAgain(); +}; + +class TaskSwitch : public GeneralException { + public: + TaskSwitch(); +}; + +#include <String.h> + +#else +#error This only works with a C++ compiler +#endif +#endif |