1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Rappture::Outcome |
---|
4 | * |
---|
5 | * AUTHOR: Michael McLennan, Purdue University |
---|
6 | * Copyright (c) 2004-2007 Purdue Research Foundation |
---|
7 | * ---------------------------------------------------------------------- |
---|
8 | * See the file "license.terms" for information on usage and |
---|
9 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
10 | * ====================================================================== |
---|
11 | */ |
---|
12 | #ifndef RAPPTURE_OUTCOME_H |
---|
13 | #define RAPPTURE_OUTCOME_H |
---|
14 | |
---|
15 | #include <string> |
---|
16 | #include <RpPtr.h> |
---|
17 | |
---|
18 | namespace Rappture { |
---|
19 | |
---|
20 | /** |
---|
21 | * This object represents the result of any Rappture call. It acts |
---|
22 | * like a boolean, so it can be tested for success/failure. But |
---|
23 | * it can also contain information about failure, including a trace |
---|
24 | * back of messages indicating the cause. |
---|
25 | */ |
---|
26 | class Outcome { |
---|
27 | public: |
---|
28 | Outcome(const char* errmsg=NULL); |
---|
29 | Outcome(const Outcome& status); |
---|
30 | Outcome& operator=(const Outcome& status); |
---|
31 | virtual ~Outcome(); |
---|
32 | |
---|
33 | Outcome& AddError(const char* format, ...); |
---|
34 | virtual Outcome& error(const char* errmsg, int status=1); |
---|
35 | virtual Outcome& clear(); |
---|
36 | |
---|
37 | virtual operator int() const; |
---|
38 | virtual int operator!() const; |
---|
39 | virtual Outcome& operator&=(Outcome status); // pass-by-value to avoid temp |
---|
40 | |
---|
41 | virtual std::string remark() const; |
---|
42 | virtual Outcome& addContext(const char *rem); |
---|
43 | virtual std::string context() const; |
---|
44 | |
---|
45 | private: |
---|
46 | /// overall pass/fail status |
---|
47 | int _status; |
---|
48 | |
---|
49 | /// error message |
---|
50 | Ptr<std::string>_remarkPtr; |
---|
51 | |
---|
52 | /// stack trace |
---|
53 | Ptr<std::string>_contextPtr; |
---|
54 | }; |
---|
55 | |
---|
56 | } // namespace Rappture |
---|
57 | |
---|
58 | #endif |
---|