Ignore:
Timestamp:
Jun 8, 2008 6:24:34 PM (16 years ago)
Author:
gah
Message:

Massive changes: New directory/file layout

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpOutcome.cc

    r1017 r1018  
    11/*
     2 * ======================================================================
     3 *  Rappture::Outcome
     4 *
     5 *  AUTHOR:  Michael McLennan, Purdue University
     6 *  Copyright (c) 2004-2007  Purdue Research Foundation
    27 * ----------------------------------------------------------------------
    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  *
    138 *  See the file "license.terms" for information on usage and
    149 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
     
    1611 */
    1712#include "RpOutcome.h"
    18 
     13#include <stdarg.h>
    1914using namespace Rappture;
    2015
    21 Outcome::Outcome(const char *errmsg)
    22   : _status(0),
     16/**
     17 *  Create a negative outcome, with the given error message.
     18 */
     19Outcome::Outcome(const char *errmsg) :
     20    _status(0),
    2321    _remarkPtr(NULL),
    2422    _contextPtr(NULL)
     
    2927}
    3028
    31 Outcome::Outcome(const Outcome& oc)
    32   : _status(oc._status),
     29/// Copy constructor
     30Outcome::Outcome(const Outcome& oc) :
     31    _status(oc._status),
    3332    _remarkPtr(oc._remarkPtr),
    3433    _contextPtr(oc._contextPtr)
     
    3635}
    3736
     37/// Assignment operator
    3838Outcome&
    3939Outcome::operator=(const Outcome& oc)
     
    4545}
    4646
     47/// Destructor
     48Outcome::~Outcome()
     49{}
     50
     51/**
     52 *  Assign an error condition to the outcome.
     53 */
    4754Outcome&
    4855Outcome::error(const char* errmsg, int status)
     
    5562
    5663Outcome&
     64Outcome::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 */
     95Outcome&
    5796Outcome::clear()
    5897{
     
    63102}
    64103
     104/**
     105 *  Returns the status of this outcome as an integer.
     106 *  As in Unix systems, 0 = okay.
     107 */
    65108Outcome::operator int() const
    66109{
     
    68111}
    69112
     113/**
     114 *  For !error tests.
     115 */
    70116int
    71117Outcome::operator!() const
     
    74120}
    75121
     122/**
     123 *  Use this to concatenate many different outcomes.
     124 */
    76125Outcome&
    77126Outcome::operator&=(Outcome oc)
     
    85134}
    86135
     136/**
     137 *  Query the error remark from an outcome.
     138 */
    87139std::string
    88140Outcome::remark() const
     
    94146}
    95147
     148/**
     149 *  Add information to the context stack for an outcome.
     150 */
    96151Outcome&
    97152Outcome::addContext(const char *rem)
     
    105160}
    106161
     162/**
     163 *  Query the context stack from an outcome.
     164 */
    107165std::string
    108166Outcome::context() const
Note: See TracChangeset for help on using the changeset viewer.