WvStreams
wverror.h
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_both(int _errnum, WVSTRING_FORMAT_DECL)
00074         { seterr_both(_errnum, WvString(WVSTRING_FORMAT_CALL)); }
00075     void seterr(const WvErrorBase &err);
00076     
00078     void noerr()
00079         { errnum = 0; errstring = WvString::null; }
00080 };
00081 
00082 
00089 class WvError : public WvErrorBase
00090 {
00091 public:
00092     int get() const
00093         { return geterr(); }
00094     WvString str() const
00095         { return errstr(); }
00096     
00097     void set(int _errnum)
00098         { seterr(_errnum); }
00099     void set(WvStringParm specialerr)
00100         { seterr(specialerr); }
00101     void set(WVSTRING_FORMAT_DECL)
00102         { seterr(WvString(WVSTRING_FORMAT_CALL)); }
00103     void set_both(int _errnum, WvStringParm specialerr)
00104         { seterr_both(_errnum, specialerr); }
00105     void set(const WvErrorBase &err)
00106         { seterr(err); }
00107 
00108     void reset()
00109         { noerr(); }
00110 };
00111 
00112 
00113 #endif // __WVERROR_H