00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * A class for managing error numbers and strings. 00006 */ 00007 #ifndef __WVERROR_H 00008 #define __WVERROR_H 00009 00010 #include "wvstring.h" 00011 00023 class WvErrorBase 00024 { 00025 protected: 00026 int errnum; 00027 WvString errstring; 00028 00029 public: 00030 WvErrorBase() 00031 { noerr(); } 00032 virtual ~WvErrorBase(); 00033 00039 virtual bool isok() const 00040 { return errnum == 0; } 00041 00048 virtual int geterr() const 00049 { return errnum; } 00050 virtual WvString errstr() const; 00051 00056 static WvString strerror(int errnum); 00057 00068 virtual void seterr(int _errnum); 00069 void seterr(WvStringParm specialerr); 00070 void seterr(WVSTRING_FORMAT_DECL) 00071 { seterr(WvString(WVSTRING_FORMAT_CALL)); } 00072 void seterr_both(int _errnum, WvStringParm specialerr); 00073 void seterr(const WvErrorBase &err); 00074 00076 void noerr() 00077 { errnum = 0; errstring = WvString::null; } 00078 }; 00079 00080 00087 class WvError : public WvErrorBase 00088 { 00089 public: 00090 int get() const 00091 { return geterr(); } 00092 WvString str() const 00093 { return errstr(); } 00094 00095 void set(int _errnum) 00096 { seterr(_errnum); } 00097 void set(WvStringParm specialerr) 00098 { seterr(specialerr); } 00099 void set(WVSTRING_FORMAT_DECL) 00100 { seterr(WvString(WVSTRING_FORMAT_CALL)); } 00101 void set_both(int _errnum, WvStringParm specialerr) 00102 { seterr_both(_errnum, specialerr); } 00103 void set(const WvErrorBase &err) 00104 { seterr(err); } 00105 00106 void reset() 00107 { noerr(); } 00108 }; 00109 00110 00111 #endif // __WVERROR_H