WvStreams
wverror.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * A class for managing error numbers and strings.
6  */
7 #ifndef __WVERROR_H
8 #define __WVERROR_H
9 
10 #include "wvstring.h"
11 
24 {
25 protected:
26  int errnum;
27  WvString errstring;
28 
29 public:
30  WvErrorBase()
31  { noerr(); }
32  virtual ~WvErrorBase();
33 
39  virtual bool isok() const
40  { return errnum == 0; }
41 
48  virtual int geterr() const
49  { return errnum; }
50  virtual WvString errstr() const;
51 
56  static WvString strerror(int errnum);
57 
68  virtual void seterr(int _errnum);
69  void seterr(WvStringParm specialerr);
70  void seterr(WVSTRING_FORMAT_DECL)
71  { seterr(WvString(WVSTRING_FORMAT_CALL)); }
72  void seterr_both(int _errnum, WvStringParm specialerr);
73  void seterr_both(int _errnum, WVSTRING_FORMAT_DECL)
74  { seterr_both(_errnum, WvString(WVSTRING_FORMAT_CALL)); }
75  void seterr(const WvErrorBase &err);
76 
78  void noerr()
79  { errnum = 0; errstring = WvString::null; }
80 };
81 
82 
89 class WvError : public WvErrorBase
90 {
91 public:
92  int get() const
93  { return geterr(); }
94  WvString str() const
95  { return errstr(); }
96 
97  void set(int _errnum)
98  { seterr(_errnum); }
99  void set(WvStringParm specialerr)
100  { seterr(specialerr); }
101  void set(WVSTRING_FORMAT_DECL)
102  { seterr(WvString(WVSTRING_FORMAT_CALL)); }
103  void set_both(int _errnum, WvStringParm specialerr)
104  { seterr_both(_errnum, specialerr); }
105  void set(const WvErrorBase &err)
106  { seterr(err); }
107 
108  void reset()
109  { noerr(); }
110 };
111 
112 
113 #endif // __WVERROR_H