Changeset 1018 for trunk/src/core


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

Massive changes: New directory/file layout

Location:
trunk/src/core
Files:
33 added
5 edited
27 copied
12 moved

Legend:

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

    r1017 r1018  
    55 *  AUTHOR:  Derrick Kearney, Purdue University
    66 *
    7  *  Copyright (c) 2004-2008  Purdue Research Foundation
     7 *  Copyright (c) 2004-2007  Purdue Research Foundation
    88 * ----------------------------------------------------------------------
    99 *  See the file "license.terms" for information on usage and
    1010 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
     11 * ======================================================================
     12 *
     13 *  This code is based on the Tcl_DString facility included in the
     14 *  Tcl source release, which includes the following copyright:
     15 *
     16 *  Copyright (c) 1987-1993 The Regents of the University of California.
     17 *  Copyright (c) 1994-1998 Sun Microsystems, Inc.
     18 *  Copyright (c) 2001 by Kevin B. Kenny.  All rights reserved.
     19 *
     20 *  This software is copyrighted by the Regents of the University of
     21 *  California, Sun Microsystems, Inc., Scriptics Corporation,
     22 *  and other parties.  The following terms apply to all files associated
     23 *  with the software unless explicitly disclaimed in individual files.
     24 *
     25 *  The authors hereby grant permission to use, copy, modify, distribute,
     26 *  and license this software and its documentation for any purpose, provided
     27 *  that existing copyright notices are retained in all copies and that this
     28 *  notice is included verbatim in any distributions. No written agreement,
     29 *  license, or royalty fee is required for any of the authorized uses.
     30 *  Modifications to this software may be copyrighted by their authors
     31 *  and need not follow the licensing terms described here, provided that
     32 *  the new terms are clearly indicated on the first page of each file where
     33 *  they apply.
     34 *
     35 *  IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
     36 *  FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     37 *  ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
     38 *  DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
     39 *  POSSIBILITY OF SUCH DAMAGE.
     40 *
     41 *  THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
     42 *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
     43 *  FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
     44 *  IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
     45 *  NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
     46 *  MODIFICATIONS.
     47 *
     48 *  GOVERNMENT USE: If you are acquiring this software on behalf of the
     49 *  U.S. government, the Government shall have only "Restricted Rights"
     50 *  in the software and related documentation as defined in the Federal·
     51 *  Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
     52 *  are acquiring the software on behalf of the Department of Defense, the
     53 *  software shall be classified as "Commercial Computer Software" and the
     54 *  Government shall have only "Restricted Rights" as defined in Clause
     55 *  252.227-7013 (c) (1) of DFARs.  Notwithstanding the foregoing, the
     56 *  authors grant the U.S. Government and others acting in its behalf
     57 *  permission to use and distribute the software in accordance with the
     58 *  terms specified in this license.·
     59 *
    1160 * ======================================================================
    1261 */
     
    2776
    2877/**
     78 * Construct an empty SimpleBuffer.
     79 */
     80SimpleBuffer::SimpleBuffer()
     81{
     82    bufferInit();
     83}
     84
     85
     86/**
     87 * Construct a SimpleBuffer loaded with initial data.
     88 *
     89 * @param bytes pointer to bytes being stored.
     90 * @param nbytes number of bytes being stored.
     91 */
     92SimpleBuffer::SimpleBuffer(const char* bytes, int nbytes)
     93{
     94    bufferInit();
     95    append(bytes,nbytes);
     96}
     97
     98
     99/**
     100 * Copy constructor
     101 * @param SimpleBuffer object to copy
     102 */
     103SimpleBuffer::SimpleBuffer(const SimpleBuffer& b)
     104{
     105    bufferInit();
     106    append(b.bytes(),b.size());
     107}
     108
     109
     110/**
     111 * Assignment operator
     112 * @param SimpleBuffer object to copy
     113 */
     114SimpleBuffer&
     115SimpleBuffer::operator=(const SimpleBuffer& b)
     116{
     117    bufferFree();
     118    bufferInit();
     119    append(b.bytes(),b.size());
     120    return *this;
     121}
     122
     123
     124/**
     125 * Operator +
     126 * @param SimpleBuffer object to add
     127 */
     128SimpleBuffer
     129SimpleBuffer::operator+(const SimpleBuffer& b) const
     130{
     131    SimpleBuffer newBuffer(*this);
     132    newBuffer.operator+=(b);
     133    return newBuffer;
     134}
     135
     136
     137/**
     138 * Operator +=
     139 * @param SimpleBuffer object to add
     140 */
     141SimpleBuffer&
     142SimpleBuffer::operator+=(const SimpleBuffer& b)
     143{
     144    append(b.bytes(),b.size());
     145    return *this;
     146}
     147
     148
     149/**
     150 * Destructor
     151 */
     152SimpleBuffer::~SimpleBuffer()
     153{
     154    bufferFree();
     155}
     156
     157
     158/**
     159 * Get the bytes currently stored in the buffer.  These bytes can
     160 * be stored, and used later to construct another Buffer to
     161 * decode the information.
     162 *
     163 * @return Pointer to the bytes in the buffer.
     164 */
     165const char*
     166SimpleBuffer::bytes() const
     167{
     168    return _buf;
     169}
     170
     171
     172/**
     173 * Get the number of bytes currently stored in the buffer.
     174 * @return Number of the bytes used in the buffer.
     175 */
     176unsigned int
     177SimpleBuffer::size() const
     178{
     179    return _size;
     180}
     181
     182
     183/**
     184 * Clear the buffer, making it empty.
     185 * @return Reference to this buffer.
     186 */
     187SimpleBuffer&
     188SimpleBuffer::clear()
     189{
     190    bufferFree();
     191    bufferInit();
     192
     193    return *this;
     194}
     195
     196
     197/**
     198 * Append bytes to the end of this buffer
     199 * @param Buffer object to copy
     200 * @return Reference to this buffer.
     201 */
     202int
     203SimpleBuffer::append(const char* bytes, int nbytes)
     204{
     205    unsigned int newSize = 0;
     206    char *newBuffer = NULL;
     207
     208    // User specified NULL buffer to append
     209    if ( (bytes == NULL) && (nbytes < 1) ) {
     210        return 0;
     211    }
     212
     213    if (nbytes == -1) {
     214        // user signaled null terminated string
     215        nbytes = strlen(bytes);
     216    }
     217
     218    if (nbytes <= 0) {
     219        // no data written, invalid option
     220        return nbytes;
     221    }
     222
     223    // Empty internal buffer, make sure its properly initialized.
     224    if (_buf == NULL) {
     225        bufferInit();
     226    }
     227
     228    newSize = (unsigned int)(_size + nbytes);
     229
     230    // ensure that our smallest buffer is 200 bytes
     231    if (newSize < (RP_BUFFER_MIN_SIZE/2)) {
     232        newSize = (RP_BUFFER_MIN_SIZE/2);
     233    }
     234
     235    /*
     236     * Allocate a larger buffer for the string if the current one isn't
     237     * large enough. Allocate extra space in the new buffer so that there
     238     * will be room to grow before we have to allocate again.
     239     */
     240
     241    if (newSize >= _spaceAvl) {
     242        _spaceAvl = newSize * 2;
     243        newBuffer = new char[_spaceAvl];
     244        if (newBuffer == NULL) {
     245            // return memory error
     246            return -1;
     247        }
     248        if (_buf != NULL) {
     249            memcpy((void*) newBuffer, (void*) _buf, (size_t) _size);
     250            delete [] _buf;
     251            _buf = NULL;
     252        }
     253        _buf = newBuffer;
     254    }
     255
     256    memcpy((void*) (_buf + _size), (void*) bytes, (size_t) nbytes);
     257
     258    _size = _size + (unsigned int) nbytes;
     259
     260    return nbytes;
     261}
     262
     263
     264/**
     265 * Read data from the buffer into a memory location provided by caller
     266 * @param Pointer locating where to place read bytes.
     267 * @param Size of the memory location.
     268 * @return Number of bytes written to memory location
     269 */
     270int
     271SimpleBuffer::read(const char* bytes, int nbytes)
     272{
     273    unsigned int bytesRead = 0;
     274
     275    // SimpleBuffer is empty.
     276    if (_buf == NULL) {
     277        return 0;
     278    }
     279
     280    // User specified NULL buffer.
     281    if (bytes == NULL) {
     282        return 0;
     283    }
     284
     285    // User specified negative buffer size
     286    if (nbytes <= 0) {
     287        return 0;
     288    }
     289
     290    // make sure we don't read off the end of our buffer
     291    if ( (_pos + nbytes) >= _size ) {
     292        bytesRead = (_size - _pos);
     293    }
     294    else {
     295        bytesRead = (unsigned int) nbytes;
     296    }
     297
     298    if (bytesRead <= 0) {
     299        return 0;
     300    }
     301
     302    if (bytesRead > 0) {
     303        memcpy((void*) bytes, (void*) (_buf+_pos), (size_t) bytesRead);
     304    }
     305
     306    _pos = (_pos + bytesRead);
     307
     308    return (int)bytesRead;
     309}
     310
     311
     312/**
     313 * Set buffer position indicator to spot within the buffer
     314 * @param Offset from whence location in buffer.
     315 * @param Place from where offset is added or subtracted.
     316 * @return 0 on success, anything else is failure
     317 */
     318int
     319SimpleBuffer::seek(int offset, int whence)
     320{
     321    int retVal = 0;
     322
     323    if (_buf == NULL) {
     324        return -1 ;
     325    }
     326
     327    if (whence == SEEK_SET) {
     328        if (offset < 0) {
     329            /* dont go off the beginning of data */
     330            _pos = 0;
     331        }
     332        else if (offset >= (int)_size) {
     333            /* dont go off the end of data */
     334            _pos = _size - 1;
     335        }
     336        else {
     337            _pos = (unsigned int)(_pos + offset);
     338        }
     339    }
     340    else if (whence == SEEK_CUR) {
     341        if ( (_pos + offset) < 0) {
     342            /* dont go off the beginning of data */
     343            _pos = 0;
     344        }
     345        else if ((_pos + offset) >= _size) {
     346            /* dont go off the end of data */
     347            _pos = _size - 1;
     348        }
     349        else {
     350            _pos = (unsigned int)(_pos + offset);
     351        }
     352    }
     353    else if (whence == SEEK_END) {
     354        if (offset <= (-1*((int)_size))) {
     355            /* dont go off the beginning of data */
     356            _pos = 0;
     357        }
     358        else if (offset >= 0) {
     359            /* dont go off the end of data */
     360            _pos = _size - 1;
     361        }
     362        else {
     363            _pos = (unsigned int)((_size - 1) + offset);
     364        }
     365    }
     366    else {
     367        retVal = -1;
     368    }
     369
     370    return retVal;
     371}
     372
     373
     374/**
     375 * Tell caller the offset of the position indicator from the start of buffer
     376 * @return Number of bytes the position indicator is from start of buffer
     377 */
     378int
     379SimpleBuffer::tell()
     380{
     381   return (int)_pos;
     382}
     383
     384
     385/**
     386 * Read data from the buffer into a memory location provided by caller
     387 */
     388SimpleBuffer&
     389SimpleBuffer::rewind()
     390{
     391    _pos = 0;
     392    return *this;
     393}
     394
     395
     396/**
     397 * Tell if the last file like operation (ie. read()) was successful
     398 * or if there was a failure like eof, or bad memory
     399 * @return True or false boolean value
     400 */
     401bool
     402SimpleBuffer::good() const
     403{
     404    return (_fileState);
     405}
     406
     407
     408/**
     409 * Tell if the last file like operation (ie. read()) failed
     410 * Opposite of good()
     411 * @return True or false boolean value
     412 */
     413bool
     414SimpleBuffer::bad() const
     415{
     416    return (!_fileState);
     417}
     418
     419
     420/**
     421 * Tell if the position flag is at the end of the buffer
     422 * @return True or false boolean value
     423 */
     424bool
     425SimpleBuffer::eof() const
     426{
     427    return (_pos >= _size);
     428}
     429
     430
     431/**
     432 * Move the data from this SimpleBuffer to the SimpleBuffer provided by
     433 * the caller. All data except the _pos is moved and this SimpleBuffer is
     434 * re-initialized with bufferInit().
     435 * @param SimpleBuffer to move the information to
     436 * @return reference to this SimpleBuffer object.
     437 */
     438SimpleBuffer&
     439SimpleBuffer::move(SimpleBuffer& b)
     440{
     441    bufferFree();
     442
     443    _buf = b._buf;
     444    _pos = b._pos;
     445    _size = b._size;
     446    _spaceAvl = b._spaceAvl;
     447    _fileState = b._fileState;
     448
     449    b.bufferInit();
     450
     451    return *this;
     452}
     453
     454
     455 /**
     456  *  Initializes a dynamic buffer, discarding any previous contents
     457  *  of the buffer. bufferFree() should have been called already
     458  *  if the dynamic buffer was previously in use.
     459  */
     460void
     461SimpleBuffer::bufferInit()
     462{
     463    _buf = NULL;
     464    _pos = 0;
     465    _size = 0;
     466    _spaceAvl = 0;
     467    _fileState = true;
     468}
     469
     470
     471/**
     472 *  Frees up any memory allocated for the dynamic buffer and
     473 *  reinitializes the buffer to an empty state.
     474 */
     475void
     476SimpleBuffer::bufferFree()
     477{
     478    if (_buf != NULL) {
     479        delete [] _buf;
     480        _buf = NULL;
     481    }
     482    bufferInit();
     483}
     484
     485
     486/**
    29487 * Construct an empty Buffer.
    30488 */
    31489Buffer::Buffer()
    32490  : SimpleBuffer(),
    33     _level(6),
    34     _compressionType(RPCOMPRESS_GZIP),
    35     _windowBits(15)
    36 {}
    37 
    38 
    39 /**
    40  * Construct an empty Buffer of specified size.
    41  */
    42 Buffer::Buffer(int nbytes)
    43   : SimpleBuffer(nbytes),
    44491    _level(6),
    45492    _compressionType(RPCOMPRESS_GZIP),
  • trunk/src/core/RpBuffer.h

    r1017 r1018  
    55 *  AUTHOR:  Derrick Kearney, Purdue University
    66 *
    7  *  Copyright (c) 2004-2008  Purdue Research Foundation
     7 *  Copyright (c) 2004-2007  Purdue Research Foundation
    88 * ----------------------------------------------------------------------
    99 *  See the file "license.terms" for information on usage and
    1010 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
     11 * ======================================================================
     12 *
     13 *  This code is based on the Tcl_DString facility included in the
     14 *  Tcl source release, which includes the following copyright:
     15 *
     16 *  Copyright (c) 1987-1993 The Regents of the University of California.
     17 *  Copyright (c) 1994-1998 Sun Microsystems, Inc.
     18 *  Copyright (c) 2001 by Kevin B. Kenny.  All rights reserved.
     19 *
     20 *  This software is copyrighted by the Regents of the University of
     21 *  California, Sun Microsystems, Inc., Scriptics Corporation,
     22 *  and other parties.  The following terms apply to all files associated
     23 *  with the software unless explicitly disclaimed in individual files.
     24 *
     25 *  The authors hereby grant permission to use, copy, modify, distribute,
     26 *  and license this software and its documentation for any purpose, provided
     27 *  that existing copyright notices are retained in all copies and that this
     28 *  notice is included verbatim in any distributions. No written agreement,
     29 *  license, or royalty fee is required for any of the authorized uses.
     30 *  Modifications to this software may be copyrighted by their authors
     31 *  and need not follow the licensing terms described here, provided that
     32 *  the new terms are clearly indicated on the first page of each file where
     33 *  they apply.
     34 *
     35 *  IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
     36 *  FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     37 *  ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
     38 *  DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
     39 *  POSSIBILITY OF SUCH DAMAGE.
     40 *
     41 *  THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
     42 *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
     43 *  FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
     44 *  IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
     45 *  NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
     46 *  MODIFICATIONS.
     47 *
     48 *  GOVERNMENT USE: If you are acquiring this software on behalf of the
     49 *  U.S. government, the Government shall have only "Restricted Rights"
     50 *  in the software and related documentation as defined in the Federal·
     51 *  Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
     52 *  are acquiring the software on behalf of the Department of Defense, the
     53 *  software shall be classified as "Commercial Computer Software" and the
     54 *  Government shall have only "Restricted Rights" as defined in Clause
     55 *  252.227-7013 (c) (1) of DFARs.  Notwithstanding the foregoing, the
     56 *  authors grant the U.S. Government and others acting in its behalf
     57 *  permission to use and distribute the software in accordance with the
     58 *  terms specified in this license.·
     59 *
    1160 * ======================================================================
    1261 */
     
    1564#define RAPPTURE_BUFFER_H
    1665
    17 #include "Outcome.h"
    18 #include "RpSimpleBuffer.h"
     66#define RP_BUFFER_MIN_SIZE    200
     67
     68#include "RpOutcome.h"
    1969
    2070#ifdef __cplusplus
     
    2979namespace Rappture {
    3080
     81class SimpleBuffer {
     82public:
     83    SimpleBuffer();
     84    SimpleBuffer(const char* bytes, int nbytes=-1);
     85    SimpleBuffer(const SimpleBuffer& b);
     86    SimpleBuffer& operator=(const SimpleBuffer& b);
     87    SimpleBuffer  operator+(const SimpleBuffer& b) const;
     88    SimpleBuffer& operator+=(const SimpleBuffer& b);
     89    virtual ~SimpleBuffer();
     90
     91    const char* bytes() const;
     92    unsigned int size() const;
     93
     94    SimpleBuffer& clear();
     95    int append(const char* bytes, int nbytes=-1);
     96    int read(const char* bytes, int nbytes);
     97    int seek(int offset, int whence);
     98    int tell();
     99    SimpleBuffer& rewind();
     100
     101    bool good() const;
     102    bool bad() const;
     103    bool eof() const;
     104
     105    SimpleBuffer& move(SimpleBuffer& b);
     106
     107protected:
     108
     109    void bufferInit();
     110    void bufferFree();
     111
     112private:
     113
     114    /// Pointer to the memory that holds our buffer's data
     115    char* _buf;
     116
     117    /// Position offset within the buffer's memory
     118    unsigned int _pos;
     119
     120    /// Size of the used memory in the buffer
     121    unsigned int _size;
     122
     123    /// Total space available in the buffer
     124    unsigned int _spaceAvl;
     125
     126    /// State of the last file like operation.
     127    bool _fileState;
     128};
    31129
    32130/**
     
    40138public:
    41139    Buffer();
    42     Buffer(int nbytes);
    43140    Buffer(const char* bytes, int nbytes=-1);
    44141    Buffer(const Buffer& buffer);
  • trunk/src/core/RpEncode.h

    r1017 r1018  
    1717// #include "rappture.h"
    1818#include "RpBuffer.h"
    19 #include "Outcome.h"
     19#include "RpOutcome.h"
    2020
    2121#define RPENC_Z      1
  • trunk/src/core/RpLibrary.cc

    r962 r1018  
    14491449
    14501450RpLibrary&
    1451 RpLibrary::childCount ( std::string path,
    1452                         int* childCount )
    1453 {
    1454     scew_element* parentNode;
    1455     int myChildCount = 0;
    1456 
     1451RpLibrary::childCount(std::string path, int* childCount)
     1452{
    14571453    if (this->root) {
    1458 
     1454        scew_element* parentNode;
     1455        int myChildCount = 0;
     1456
     1457        parentNode = NULL;
    14591458        if (path.empty()) {
    14601459            // an empty path uses the current RpLibrary as parent
     
    14691468            *childCount = myChildCount;
    14701469        }
    1471 
    1472     }
    1473 
     1470    }
    14741471    return *this;
    14751472}
  • trunk/src/core/RpLibrary.h

    r759 r1018  
    3131#include <list>
    3232#include "RpBuffer.h"
    33 #include "Outcome.h"
     33#include "RpOutcome.h"
    3434
    3535/* indentation size (in whitespaces) */
  • 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
  • trunk/src/core/RpOutcome.h

    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.
     
    1914
    2015#include <string>
    21 #include "RpPtr.h"
     16#include <RpPtr.h>
    2217
    2318namespace Rappture {
    2419
     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 */
    2526class Outcome {
    2627public:
     
    2829    Outcome(const Outcome& status);
    2930    Outcome& operator=(const Outcome& status);
     31    virtual ~Outcome();
    3032
    3133    virtual Outcome& error(const char* errmsg, int status=1);
     
    4143
    4244private:
    43     int _status;                   // overall pass/fail status
    44     Ptr<std::string>_remarkPtr;    // error message
    45     Ptr<std::string>_contextPtr;   // stack trace
     45    /// overall pass/fail status
     46    int _status;
     47
     48    /// error message
     49    Ptr<std::string>_remarkPtr;
     50
     51    /// stack trace
     52    Ptr<std::string>_contextPtr;
    4653};
    4754
  • trunk/src/core/RpOutcomeCInterface.cc

    r1017 r1018  
    1212 */
    1313
    14 #include "Outcome.h"
     14#include "RpOutcome.h"
    1515#include "RpOutcomeCInterface.h"
    1616#include "RpOutcomeCHelper.h"
     
    134134RapptureOutcomeCheck(RapptureOutcome* status)
    135135{
    136     return ((int)(*((Rappture::Outcome*)status)));
     136    return ((int)((Rappture::Outcome*)status->_status));
    137137}
    138138
  • trunk/src/core/RpPtr.h

    r1017 r1018  
    11/*
    2  * ----------------------------------------------------------------------
     2 * ======================================================================
    33 *  Rappture::Ptr<type>
    4  *    This is a smart pointer with reference counting.  Once one of
    5  *    these pointers is constructed with an object of the underlying
    6  *    type, that object becomes property of the pointer.  Other
    7  *    pointers can point to the same object.  When all such pointers
    8  *    have been destroyed, the underlying object goes away.
    94 *
    10  * ======================================================================
    115 *  AUTHOR:  Michael McLennan, Purdue University
    126 *  Copyright (c) 2004-2006  Purdue Research Foundation
    13  *
     7 * ----------------------------------------------------------------------
    148 *  See the file "license.terms" for information on usage and
    159 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1610 * ======================================================================
    1711 */
    18 #ifndef RAPPTURE_POINTER_H
    19 #define RAPPTURE_POINTER_H
     12#ifndef RAPPTURE_PTR_H
     13#define RAPPTURE_PTR_H
    2014
    2115#include <assert.h>
    2216
    23 #ifndef NULL
    24 #  define NULL 0
    25 #endif
    26 
    2717namespace Rappture {
    2818
    29 template <class Type>
     19/**
     20 *  This is the core of a smart pointer, built to keep a reference
     21 *  count and do most of the work, so the template class can be lean
     22 *  and mean.
     23 */
    3024class PtrCore {
    3125public:
    32     explicit PtrCore(Type* ptr=NULL);
     26    explicit PtrCore(void* ptr=NULL);
    3327    ~PtrCore();
    3428
     29    void* pointer() const;
     30    void attach();
     31    void* detach();
     32
     33private:
    3534    // copying the core is not allowed
    3635    PtrCore(const PtrCore& pc) { assert(0); }
    37     PtrCore& operator=(const PtrCore& pc) { assert(0); }
     36    PtrCore& operator=(const PtrCore& pc) { assert(0); return *this; }
    3837
    39     Type* pointer() const;
    40     void attach();
    41     void detach();
    42 
    43 private:
    44     Type *_ptr;
     38    void *_ptr;
    4539    int _refcount;
    4640};
    4741
    48 template <class Type>
    49 PtrCore<Type>::PtrCore(Type* ptr)
    50   : _ptr(ptr),
    51     _refcount(1)
    52 {
    53 }
    54 
    55 template <class Type>
    56 PtrCore<Type>::~PtrCore()
    57 {
    58     assert(_refcount <= 0);
    59 }
    60 
    61 template <class Type>
    62 Type*
    63 PtrCore<Type>::pointer() const
    64 {
    65     return _ptr;
    66 }
    67 
    68 template <class Type>
    69 void
    70 PtrCore<Type>::attach()
    71 {
    72     _refcount++;
    73 }
    74 
    75 template <class Type>
    76 void
    77 PtrCore<Type>::detach()
    78 {
    79     if (--_refcount <= 0 && _ptr != NULL) {
    80         delete _ptr;
    81         delete this;
    82     }
    83 }
    84 
    85 
     42/**
     43 *  This is a smart pointer with reference counting.  Once one of
     44 *  these pointers is constructed with an object of the underlying
     45 *  type, that object becomes property of the pointer.  Other
     46 *  pointers can point to the same object.  When all such pointers
     47 *  have been destroyed, the underlying object goes away.
     48 */
    8649template <class Type>
    8750class Ptr {
     
    10063
    10164private:
    102     PtrCore<Type> *_pc;
     65    PtrCore *_pc;
    10366};
    10467
     
    10871{
    10972    if (ptr) {
    110         _pc = new PtrCore<Type>(ptr);
     73        _pc = new PtrCore(ptr);
    11174    }
    11275}
     
    12588Ptr<Type>::~Ptr()
    12689{
    127     if (_pc) {
    128         _pc->detach();
    129     }
     90    clear();
    13091}
    13192
     
    13495Ptr<Type>::operator=(Type* ptr)
    13596{
    136     if (_pc) {
    137         _pc->detach();
    138     }
    139     _pc = new PtrCore<Type>(ptr);
     97    clear();
     98    _pc = new PtrCore(ptr);
     99    return *this;
    140100}
    141101
     
    147107        ptr._pc->attach();
    148108    }
    149     if (_pc) {
    150         _pc->detach();
    151     }
     109    clear();
    152110    _pc = ptr._pc;
    153111    return *this;
     
    169127{
    170128    if (_pc) {
    171         return _pc->pointer();
     129        return static_cast<Type*>(_pc->pointer());
    172130    }
    173131    return NULL;
     
    179137{
    180138    if (_pc) {
    181         return _pc->pointer();
     139        return (Type*)_pc->pointer();
    182140    }
    183141    return NULL;
     
    197155{
    198156    if (_pc) {
    199         _pc->detach();
     157        Type* ptr = (Type*)_pc->detach();
     158        if (ptr) {
     159            // If we get back a pointer, then it is fully detached.
     160            // Clean it up.
     161            delete ptr;
     162            delete _pc;
     163        }
    200164        _pc = NULL;
    201165    }
     
    204168} // namespace Rappture
    205169
    206 #endif
     170#endif // RAPPTURE_PTR_H
  • trunk/src/core/RpResult.cc

    r115 r1018  
    1717#include <stdlib.h>
    1818#include <time.h>
     19#include <RpLibrary.h>
     20#include <errno.h>
    1921
    2022void
    21 rpResult(PyObject* lib) {
     23rpResult(RpLibrary* lib)
     24{
    2225    char outputFile[100];
    23     char* xtext;
     26    std::string xtext;
    2427    FILE* fp;
    2528    time_t t;
    2629
    27     xtext = rpXml(lib);
     30    xtext = lib->xml();
    2831
    2932    // create output filename
     
    3639        return;
    3740    }
    38     int fsize = fwrite(xtext, strlen(xtext), sizeof(char), fp);
     41    int fsize = fwrite(xtext.c_str(), xtext.length(), sizeof(char), fp);
     42    if (fsize != (int)xtext.length()) {
     43        fprintf(stderr, "short write: can't save results (err=%d)\n", errno);
     44        fclose(fp);
     45        return;
     46    }
    3947    fclose(fp);
    40 
    4148    // tell Rappture the file name
    4249    printf("=RAPPTURE-RUN=>%s\n", outputFile);
  • trunk/src/core/RpUnitsCInterface.cc

    r1017 r1018  
    1414#include "RpUnits.h"
    1515#include "RpUnitsCInterface.h"
    16 
    17 #ifdef __cplusplus
    18 extern "C" {
    19 #endif
    2016
    2117const RpUnits*
     
    133129}
    134130
    135 #ifdef __cplusplus
    136 }
    137 #endif
  • trunk/src/core/RpUnitsFInterface.cc

    r1017 r1018  
    3333
    3434    if (basisName && *basisName) {
    35         long int basisNameKey = *basisName;
    36         basisStrName = ObjDictUnits.find(basisNameKey);
     35        basisStrName = ObjDictUnits.find(*basisName);
    3736
    3837        if (basisStrName != "") {
  • trunk/src/core/RpUnitsStd.cc

    r999 r1018  
    1010#include <math.h>
    1111
    12 #ifdef __cplusplus
    13 extern "C" {
    14 #endif
    15 
    1612double invert (double inVal)
    1713{
     
    2218 * METRIC CONVERSIONS
    2319 ****************************************/
    24 
    2520
    2621double deci2base (double deci)
     
    572567}
    573568
    574 #ifdef __cplusplus
    575 }
    576 #endif
  • trunk/src/core/scew_extras.c

    r583 r1018  
    1111 * ======================================================================
    1212 */
     13
    1314#include "scew/scew.h"
    1415#include "scew/xelement.h"
     
    1617#include "scew/xerror.h"
    1718#include "scew/str.h"
    18 
     19#include "scew_extras.h"
    1920#include <assert.h>
    20 
    21 #include "scew_extras.h"
    2221
    2322scew_element*
Note: See TracChangeset for help on using the changeset viewer.