Changeset 1018 for trunk/src/core/RpOutcome.cc
- Timestamp:
- Jun 8, 2008 6:24:34 PM (16 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpOutcome.cc
r1017 r1018 1 1 /* 2 * ====================================================================== 3 * Rappture::Outcome 4 * 5 * AUTHOR: Michael McLennan, Purdue University 6 * Copyright (c) 2004-2007 Purdue Research Foundation 2 7 * ---------------------------------------------------------------------- 3 * Rappture::Outcome4 * This object represents the result of any Rappture call. It acts5 * like a boolean, so it can be tested for success/failure. But6 * it can also contain information about failure, including a trace7 * back of messages indicating the cause.8 *9 * ======================================================================10 * AUTHOR: Michael McLennan, Purdue University11 * Copyright (c) 2004-2006 Purdue Research Foundation12 *13 8 * See the file "license.terms" for information on usage and 14 9 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. … … 16 11 */ 17 12 #include "RpOutcome.h" 18 13 #include <stdarg.h> 19 14 using namespace Rappture; 20 15 21 Outcome::Outcome(const char *errmsg) 22 : _status(0), 16 /** 17 * Create a negative outcome, with the given error message. 18 */ 19 Outcome::Outcome(const char *errmsg) : 20 _status(0), 23 21 _remarkPtr(NULL), 24 22 _contextPtr(NULL) … … 29 27 } 30 28 31 Outcome::Outcome(const Outcome& oc) 32 : _status(oc._status), 29 /// Copy constructor 30 Outcome::Outcome(const Outcome& oc) : 31 _status(oc._status), 33 32 _remarkPtr(oc._remarkPtr), 34 33 _contextPtr(oc._contextPtr) … … 36 35 } 37 36 37 /// Assignment operator 38 38 Outcome& 39 39 Outcome::operator=(const Outcome& oc) … … 45 45 } 46 46 47 /// Destructor 48 Outcome::~Outcome() 49 {} 50 51 /** 52 * Assign an error condition to the outcome. 53 */ 47 54 Outcome& 48 55 Outcome::error(const char* errmsg, int status) … … 55 62 56 63 Outcome& 64 Outcome::AddError(const char* format, ...) 65 { 66 char stackSpace[1024]; 67 va_list lst; 68 size_t n; 69 char *bufPtr; 70 71 va_start(lst, format); 72 bufPtr = stackSpace; 73 n = vsnprintf(bufPtr, 1024, format, lst); 74 if (n >= 1024) { 75 bufPtr = (char *)malloc(n); 76 vsnprintf(bufPtr, n, format, lst); 77 } 78 if (_remarkPtr.isNull()) { 79 _remarkPtr = Ptr<std::string>(new std::string(bufPtr)); 80 } else { 81 _remarkPtr->append("\n"); 82 _remarkPtr->append(bufPtr); 83 } 84 _contextPtr.clear(); 85 _status = 1; /* Set to error */ 86 if (bufPtr != stackSpace) { 87 free(bufPtr); 88 } 89 return *this; 90 } 91 92 /** 93 * Clear the status of this outcome. 94 */ 95 Outcome& 57 96 Outcome::clear() 58 97 { … … 63 102 } 64 103 104 /** 105 * Returns the status of this outcome as an integer. 106 * As in Unix systems, 0 = okay. 107 */ 65 108 Outcome::operator int() const 66 109 { … … 68 111 } 69 112 113 /** 114 * For !error tests. 115 */ 70 116 int 71 117 Outcome::operator!() const … … 74 120 } 75 121 122 /** 123 * Use this to concatenate many different outcomes. 124 */ 76 125 Outcome& 77 126 Outcome::operator&=(Outcome oc) … … 85 134 } 86 135 136 /** 137 * Query the error remark from an outcome. 138 */ 87 139 std::string 88 140 Outcome::remark() const … … 94 146 } 95 147 148 /** 149 * Add information to the context stack for an outcome. 150 */ 96 151 Outcome& 97 152 Outcome::addContext(const char *rem) … … 105 160 } 106 161 162 /** 163 * Query the context stack from an outcome. 164 */ 107 165 std::string 108 166 Outcome::context() const
Note: See TracChangeset
for help on using the changeset viewer.