source: trunk/src2/core/RpOutcome.cc @ 446

Last change on this file since 446 was 446, checked in by mmc, 18 years ago

Fixed memory problems causing core dumps. The reserve() function doesn't
allocate any elements--just makes their later allocation more efficient.

File size: 2.3 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture::Outcome
4 *    This object represents the result of any Rappture call.  It acts
5 *    like a boolean, so it can be tested for success/failure.  But
6 *    it can also contain information about failure, including a trace
7 *    back of messages indicating the cause.
8 *
9 * ======================================================================
10 *  AUTHOR:  Michael McLennan, Purdue University
11 *  Copyright (c) 2004-2006  Purdue Research Foundation
12 *
13 *  See the file "license.terms" for information on usage and
14 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 * ======================================================================
16 */
17#include "RpOutcome.h"
18
19using namespace Rappture;
20
21Outcome::Outcome(const char *errmsg)
22  : _status(0),
23    _remarkPtr(NULL),
24    _contextPtr(NULL)
25{
26    if (errmsg) {
27        error(errmsg);
28    }
29}
30
31Outcome::Outcome(const Outcome& oc)
32  : _status(oc._status),
33    _remarkPtr(oc._remarkPtr),
34    _contextPtr(oc._contextPtr)
35{
36}
37
38Outcome&
39Outcome::operator=(const Outcome& oc)
40{
41    _status = oc._status;
42    _remarkPtr = oc._remarkPtr;
43    _contextPtr = oc._contextPtr;
44    return *this;
45}
46
47Outcome&
48Outcome::error(const char* errmsg, int status)
49{
50    _status = status;
51    _remarkPtr = Ptr<std::string>(new std::string(errmsg));
52    _contextPtr.clear();
53    return *this;
54}
55
56Outcome&
57Outcome::clear()
58{
59    _status = 0;
60    _remarkPtr.clear();
61    _contextPtr.clear();
62    return *this;
63}
64
65Outcome::operator int() const
66{
67    return _status;
68}
69
70int
71Outcome::operator!() const
72{
73    return (_status == 0);
74}
75
76Outcome&
77Outcome::operator&=(Outcome oc)
78{
79    _status &= oc._status;
80    if (!oc._contextPtr.isNull()) {
81        _remarkPtr = oc._remarkPtr;
82        _contextPtr = oc._contextPtr;
83    }
84    return *this;
85}
86
87std::string
88Outcome::remark() const
89{
90    if (!_remarkPtr.isNull()) {
91        return _remarkPtr->data();
92    }
93    return "";
94}
95
96Outcome&
97Outcome::addContext(const char *rem)
98{
99    if (_contextPtr.isNull()) {
100        _contextPtr = new std::string();
101    }
102    _contextPtr->append(rem);
103    _contextPtr->append("\n");
104    return *this;
105}
106
107std::string
108Outcome::context() const
109{
110    if (!_contextPtr.isNull()) {
111        return _contextPtr->data();
112    }
113    return "";
114}
Note: See TracBrowser for help on using the repository browser.