Changeset 1016 for trunk


Ignore:
Timestamp:
Jun 8, 2008 4:48:01 PM (13 years ago)
Author:
gah
Message:
 
Location:
trunk/src2/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src2/core/Outcome.cpp

    r592 r1016  
    1212#include "Outcome.h"
    1313
     14#include <stdarg.h>
     15
    1416using namespace Rappture;
    1517
     
    1719 *  Create a negative outcome, with the given error message.
    1820 */
    19 Outcome::Outcome(const char *errmsg)
    20   : _status(0),
     21Outcome::Outcome(const char *errmsg) :
     22    _status(0),
    2123    _remarkPtr(NULL),
    2224    _contextPtr(NULL)
     
    2830
    2931/// Copy constructor
    30 Outcome::Outcome(const Outcome& oc)
    31   : _status(oc._status),
     32Outcome::Outcome(const Outcome& oc) :
     33    _status(oc._status),
    3234    _remarkPtr(oc._remarkPtr),
    3335    _contextPtr(oc._contextPtr)
     
    5860    _remarkPtr = Ptr<std::string>(new std::string(errmsg));
    5961    _contextPtr.clear();
     62    return *this;
     63}
     64
     65Outcome&
     66Outcome::AddError(const char* format, ...)
     67{
     68    char stackSpace[1024];
     69    va_list lst;
     70    size_t n;
     71    char *bufPtr;
     72
     73    va_start(lst, format);
     74    bufPtr = stackSpace;
     75    n = vsnprintf(bufPtr, 1024, format, lst);
     76    if (n >= 1024) {
     77        bufPtr = (char *)malloc(n);
     78        vsnprintf(bufPtr, n, format, lst);
     79    }
     80    if (_remarkPtr.isNull()) {
     81        _remarkPtr = Ptr<std::string>(new std::string(bufPtr));
     82    } else {
     83        _remarkPtr->append("\n");
     84        _remarkPtr->append(bufPtr);
     85    }
     86    _contextPtr.clear();
     87    _status = 1;                /* Set to error */
     88    if (bufPtr != stackSpace) {
     89        free(bufPtr);
     90    }
    6091    return *this;
    6192}
  • trunk/src2/core/Outcome.h

    r592 r1016  
    3030    virtual ~Outcome();
    3131
     32    Outcome& AddError(const char* format, ...);
    3233    virtual Outcome& error(const char* errmsg, int status=1);
    3334    virtual Outcome& clear();
Note: See TracChangeset for help on using the changeset viewer.