source: trunk/src/core/RpOutcome.h @ 2726

Last change on this file since 2726 was 1366, checked in by gah, 16 years ago

Begin reorganizing Rappture C++ API, starting with the use of
Rappture::Outcome.

Instead of returning an Outcome and expecting every routine to
save it, pass it as a reference. Let's strip it down to what's
needed right now and add back functionality as required.

Right now too many return values are ignored in the rappture library.
We need to check all results and return the error messages via
the Outcome. At the topmost level where is touches the developer
API we can drop the error checking or turn it on via an environment
variable.

Example. Not enough checks are made for memory allocation failure.
If the application is running on an over-committed server memory
allocation errors will be silently passed on. It's okay to be
fault tolerant where possible, but if we fail to check in the internal
library functions, it's too late.

--gah

File size: 1.6 KB
Line 
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
18namespace 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 */
26class Outcome {
27public:
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 const char *remark() const;
42    virtual Outcome& addContext(const char *rem);
43    virtual const char *context() const;
44
45private:
46    /// overall pass/fail status
47    int _status;
48
49    /// error message
50    std::string _remark;
51
52    /// stack trace
53    std::string _context;
54};
55
56} // namespace Rappture
57
58#endif
Note: See TracBrowser for help on using the repository browser.