home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
programming
/
dreamscape
/
source
/
Dreamscape
/
Headers
/
low-level
/
h
/
x
< prev
Wrap
Text File
|
1996-09-27
|
5KB
|
142 lines
/* low-level.h.x
*
* Dreamscape - C++ class library for RISC OS
* Copyright (c) 1996 Mark Seaborn <mseaborn@argonet.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* See the Dreamscape documentation for more information.
*/
#ifndef dreamscape_x_H
#define dreamscape_x_H
#include <string.h>
#include <setjmp.h>
#ifdef __cplusplus
/*
* C++ version of pseudo-exception handling
*/
#include "stringt.h"
struct os_error;
class RISCOSError {
public:
RISCOSError(): errnum(0) { *errmess = 0; }
RISCOSError(const char *m): errnum(0)
{ strncpy(errmess, m, 250)[250] = 0; }
RISCOSError(const char *m, unsigned n): errnum(n)
{ strncpy(errmess, m, 250)[250] = 0; }
RISCOSError &operator=(const char *m)
{ strncpy(errmess, m, 250)[250] = 0; return *this; }
RISCOSError &operator+=(const char *m) { int l=strlen(errmess);
strncpy(errmess+l, m, 250-l)[250-l] = 0; return *this; }
String operator+(const char *m) const { return String(errmess) + m; }
RISCOSError &operator=(unsigned n) { errnum = n; return *this; }
operator char*() { return errmess; }
operator const char*() const { return errmess; }
operator os_error*() { return (os_error *) this; }
operator const os_error*() const { return (os_error *) this; }
unsigned errnum;
char errmess[252];
};
extern "C" {
void os_generate_error(const os_error *error);
const RISCOSError *x_buffer_error_(const RISCOSError *error);
const RISCOSError *x_buffer_error_msg_(const char *message);
const RISCOSError *x_catch_();
int *x_try_();
const char *x_msg_memory_();
const char *x_msg_internal_(const char *message);
const RISCOSError *x_last_error();
}
inline const RISCOSError *x_buffer_error(const RISCOSError *error)
{ return x_buffer_error_(error); }
inline const RISCOSError *x_buffer_error(const char *message)
{ return x_buffer_error_msg_(message); }
inline const RISCOSError *x_buffer_error(const os_error *error)
{ return x_buffer_error_((RISCOSError *) error); }
inline const RISCOSError *x_buffer_error_msg(const char *message)
{ return x_buffer_error_msg_(message); }
inline String x_msg_memory() { return String(x_msg_memory_()); }
inline String x_msg_internal(const char *message)
{ return String(x_msg_internal_(message)); }
#define x_declare(name)
#define x_try if(!setjmp(x_try_()))
#define x_catch(name) const RISCOSError *name = x_catch_(); if(name)
inline void x_throw()
{ os_generate_error((os_error *) x_last_error()); }
inline void x_throw(const RISCOSError *error)
{ os_generate_error((os_error *) error); }
inline void x_throw(const char *message)
{ os_generate_error((os_error *) x_buffer_error(message)); }
inline void x_throw(const os_error *error)
{ os_generate_error(error); }
inline void x_throw_error(const RISCOSError *error)
{ os_generate_error((os_error *) error); }
inline void x_throw_message(const char *message)
{ os_generate_error((os_error *) x_buffer_error(message)); }
extern void (*x_error_reporter)(const char *error);
inline void x_report_error(const char *error) { x_error_reporter(error); }
#else
/*
* C version of pseudo-exception handling
*/
typedef struct RISCOSError RISCOSError;
struct RISCOSError {
unsigned errnum;
char errmess[252];
};
void os_generate_error(const struct os_error *error);
const RISCOSError *x_buffer_error_(const RISCOSError *error);
const RISCOSError *x_buffer_error_msg_(const char *message);
const RISCOSError *x_catch_(void);
int *x_try_(void);
const char *x_msg_memory_(void);
const char *x_msg_internal_(const char *message);
#define x_msg_memory() x_msg_memory_()
#define x_msg_internal(message) x_msg_internal_(message)
const RISCOSError *x_last_error(void);
#define x_buffer_error(error) x_buffer_error_(error)
#define x_buffer_error_msg(message) x_buffer_error_msg_(message)
#define x_declare(name) const RISCOSError *name
#define x_try if(!setjmp(x_try_()))
#define x_catch(name) name = x_catch_(); if(name)
#define x_throw() os_generate_error(x_last_error())
#define x_throw_error(error) os_generate_error((struct os_error *) error)
#define x_throw_message(message) \
os_generate_error((struct os_error *) x_buffer_error_msg(message))
extern void (*x_error_reporter)(const char *error);
#define x_report_error(error) x_error_reporter(error)
#endif
#endif