Changeset 583 for trunk


Ignore:
Timestamp:
Feb 22, 2007, 1:45:50 AM (18 years ago)
Author:
dkearney
Message:

updated RpBuffer? object, cleaning up much of the code.
added putData() calls to RpLibrary?, still need a getData call.
added new function to the scew extra functions to directly add a char* buffer to the xml
updated makefiles as needed

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.in

    r520 r583  
    6464
    6565RP_IO_DEPS      = RpLibrary.o RpLibraryCInterface.o RpLibraryFInterface.o \
    66                   scew_extras.o RpEntityRef.o
     66                  scew_extras.o RpEntityRef.o RpCompress.o Rp_DBuffer.o
    6767RP_UNITS_DEPS   = RpUnitsStd.o RpUnits.o RpUnitsCInterface.o RpUnitsFInterface.o
    6868RP_OTHER_DEPS   = RpFortranCommon.o RpBindingsDict.o
     
    7070                  RpChoice.o RpOption.o RpUnitsStd.o RpUnits.o #RpValue.o\
    7171                  # RpValueDouble.o RpValueString.o
     72RP2_OBJS        = ../src2/core/RpBuffer.o ../src2/core/Outcome.o ../src2/core/Ptr.o
     73RP2_LIBS        = -L/apps/rappture/20070219/lib -lz -lb64
    7274
    7375LDLIB_MACOSX = -dynamiclib -o $(LIB_DIR)/$@.dylib
     
    7880#### librappture shared object ###########################################
    7981
    80 librappture: $(RP_IO_DEPS) $(RP_UNITS_DEPS) $(RP_OTHER_DEPS)
    81         if test "`uname`" == "Darwin"; then \
    82                 $(CXX) $(DEGUG) $(LDLIB_MACOSX) $^ $(LIB_SCEW_FLAG) -lm; \
     82librappture: $(RP_IO_DEPS) $(RP_UNITS_DEPS) $(RP_OTHER_DEPS) $(RP2_OBJS)
     83        if test "`uname`" == "Darwin"; then \
     84                $(CXX) $(DEGUG) $(LDLIB_MACOSX) $^ $(LIB_SCEW_FLAG) $(RP2_LIBS) -lm; \
    8385                ar -r $@.a $^; \
    8486                ranlib -s $@.a; \
    8587        else \
    86                 $(CXX) $(DEGUG) $(LDLIB_LINUX) $^ $(LIB_SCEW_FLAG) -lm; \
     88                $(CXX) $(DEGUG) $(LDLIB_LINUX) $^ $(LIB_SCEW_FLAG) $(RP2_LIBS) -lm; \
    8789                /sbin/ldconfig -n $(LIB_DIR); \
    8890                ar -r $@.a $^; \
     
    181183RpValueString.o: $(CORE_SRC)/RpValueString.cc
    182184        $(CXX) $(CFLAGS) $(DEBUG) $(INCL_CORE) -o $@ -c $?
    183 
    184185
    185186
  • trunk/src/core/RpLibrary.cc

    r564 r583  
    55 * ======================================================================
    66 *  AUTHOR:  Derrick Kearney, Purdue University
    7  *  Copyright (c) 2004-2005  Purdue Research Foundation
     7 *  Copyright (c) 2004-2007  Purdue Research Foundation
    88 *
    99 *  See the file "license.terms" for information on usage and
     
    1414#include "RpLibrary.h"
    1515#include "RpEntityRef.h"
     16#include "RpBuffer.h"
    1617
    1718static RpEntityRef ERTranslator;
     
    13461347
    13471348RpLibrary&
    1348 RpLibrary::put (    std::string path, 
    1349                     std::string value, 
    1350                     std::string id, 
     1349RpLibrary::put (    std::string path,
     1350                    std::string value,
     1351                    std::string id,
    13511352                    int append,
    13521353                    int translateFlag)
     
    14711472    else {
    14721473        // path did not exist and was not created.
     1474    }
     1475
     1476    return *this;
     1477}
     1478
     1479
     1480/**********************************************************************/
     1481// METHOD: putData()
     1482/// Put a data from a buffer into the xml.
     1483/**
     1484 *  Append flag adds additional nodes, it does not merge same
     1485 *  named nodes together
     1486 */
     1487
     1488RpLibrary&
     1489RpLibrary::putData (std::string path,
     1490                    const char* bytes,
     1491                    int nbytes,
     1492                    int append  )
     1493{
     1494    scew_element* retNode = NULL;
     1495    const char* contents = NULL;
     1496    Rappture::Buffer buf;
     1497    unsigned int bytesWritten = 0;
     1498
     1499    if (!this->root) {
     1500        // library doesn't exist, do nothing;
     1501        return *this;
     1502    }
     1503
     1504    retNode = _find(path,CREATE_PATH);
     1505
     1506    if (retNode) {
     1507
     1508        if (append == RPLIB_APPEND) {
     1509            if ( (contents = scew_element_contents(retNode)) ) {
     1510                buf.append(contents);
     1511                // base64 decode and un-gzip the data
     1512                buf.decode();
     1513            }
     1514        }
     1515
     1516        buf.append(bytes,nbytes);
     1517        // gzip and base64 encode the data
     1518        buf.encode();
     1519
     1520        bytesWritten = (unsigned int) buf.size();
     1521        scew_element_set_contents_binary(retNode,buf.bytes(),&bytesWritten);
     1522    }
     1523
     1524    return *this;
     1525}
     1526
     1527
     1528/**********************************************************************/
     1529// METHOD: putData()
     1530/// Put data from a file into the xml.
     1531/**
     1532 *  Append flag adds additional nodes, it does not merge same
     1533 *  named nodes together
     1534 */
     1535
     1536RpLibrary&
     1537RpLibrary::putData (std::string path,
     1538                    std::string fileName,
     1539                    bool binary,
     1540                    int append  )
     1541{
     1542    scew_element* retNode = NULL;
     1543    const char* contents = NULL;
     1544    Rappture::Buffer buf;
     1545    Rappture::Buffer fileBuf;
     1546    unsigned int bytesWritten = 0;
     1547
     1548    if (!this->root) {
     1549        // library doesn't exist, do nothing;
     1550        return *this;
     1551    }
     1552
     1553    retNode = _find(path,CREATE_PATH);
     1554
     1555    if (retNode) {
     1556
     1557        if (append == RPLIB_APPEND) {
     1558            if ( (contents = scew_element_contents(retNode)) ) {
     1559                buf.append(contents);
     1560                if (binary == true) {
     1561                    // base64 decode and un-gzip the data
     1562                    buf.decode();
     1563                }
     1564            }
     1565        }
     1566
     1567        fileBuf.load(fileName.c_str());
     1568        buf += fileBuf;
     1569
     1570        if (binary == true) {
     1571            // gzip and base64 encode the data
     1572            buf.encode();
     1573        }
     1574
     1575        bytesWritten = (unsigned int) buf.size();
     1576        scew_element_set_contents_binary(retNode,buf.bytes(),&bytesWritten);
     1577
    14731578    }
    14741579
  • trunk/src/core/RpLibrary.h

    r554 r583  
    55 * ======================================================================
    66 *  AUTHOR:  Derrick Kearney, Purdue University
    7  *  Copyright (c) 2004-2005  Purdue Research Foundation
     7 *  Copyright (c) 2004-2007  Purdue Research Foundation
    88 *
    99 *  See the file "license.terms" for information on usage and
     
    8888        int         getInt    ( std::string path = "");
    8989        bool        getBool   ( std::string path = "");
     90        //  Rappture::Buffer&  getData   ( std::string path = "");
    9091
    9192        /*
     
    122123                            RpLibrary* value,
    123124                            std::string id = "",
     125                            int append = RPLIB_OVERWRITE    );
     126
     127        RpLibrary& putData( std::string path,
     128                            const char* bytes,
     129                            int nbytes,
     130                            int append = RPLIB_OVERWRITE    );
     131
     132        RpLibrary& putData( std::string path,
     133                            std::string fileName,
     134                            bool binary,
    124135                            int append = RPLIB_OVERWRITE    );
    125136
  • trunk/src/core/scew_extras.c

    r192 r583  
    1515#include "scew/xattribute.h"
    1616#include "scew/xerror.h"
     17#include "scew/str.h"
    1718
    1819#include <assert.h>
     
    118119    return new_elem;
    119120}
     121
     122
     123XML_Char const*
     124scew_element_set_contents_binary(   scew_element* element,
     125                                    XML_Char const* bytes,
     126                                    unsigned int* nbytes    )
     127{
     128    XML_Char* out = NULL;
     129
     130    assert(element != NULL);
     131    assert(bytes != NULL);
     132    assert(nbytes != NULL);
     133
     134    if (*nbytes == 0) {
     135        return element->contents;
     136    }
     137
     138    free(element->contents);
     139    out = (XML_Char*) calloc(*nbytes+1, sizeof(XML_Char));
     140    element->contents = (XML_Char*) scew_memcpy(out, (XML_Char*)bytes, *nbytes);
     141
     142    return element->contents;
     143}
  • trunk/src/core/scew_extras.h

    r511 r583  
    2929scew_element_copy (scew_element* element);
    3030
     31extern XML_Char const*
     32scew_element_set_contents_binary(   scew_element* element,
     33                                    XML_Char const* bytes,
     34                                    unsigned int* nbytes    );
     35
    3136#ifdef __cplusplus
    3237}
  • trunk/src2/core/Makefile.in

    r576 r583  
    1313
    1414CXX             = @CXX@
    15 # CXX             = g++
    1615
    1716CFLAGS=-g -Wall
     
    3837
    3938prefix = @prefix@
    40 # prefix = /apps/rappture/20070216
    4139exec_prefix = ${prefix}
    4240libdir = ${exec_prefix}/lib
     
    8078        ln -s $@ $(SHAREDLIBM)
    8179
    82 #test$(EXE): test.o $(LIBS)
    83 #       $(CXX) $(CFLAGS) -o $@ test.o $(LDFLAGS)
    84 
    8580test(EXE): test.o Ptr.o Outcome.o Lookup.o
    8681        $(CXX) $(CFLAGS) -o $@ test.o Ptr.o Outcome.o Lookup.o
     
    9085        $(CXX) $(CFLAGS) -o $@ RpBuffer_test.o $(LDFLAGS) -L ${libdir} -lz -lb64
    9186
    92 install: $(LIBS)
     87install: $(LIBS) $(SHAREDLIBV)
    9388        -@if [ ! -d $(exec_prefix) ]; then mkdir -p $(exec_prefix); fi
    9489        -@if [ ! -d $(includedir)  ]; then mkdir -p $(includedir); fi
     
    10499        chmod 644 $(includedir)/RpBuffer.h
    105100        cp $(LIBS) $(libdir)
     101        cp $(SHAREDLIBV) $(libdir)
    106102        cd $(libdir); chmod 755 $(LIBS)
    107103        -@(cd $(libdir); $(RANLIB) librappture2.a || true) >/dev/null 2>&1
  • trunk/src2/core/RpBuffer.cc

    r575 r583  
    9393SimpleBuffer::SimpleBuffer(const SimpleBuffer& b)
    9494{
    95     _buf = NULL;
    96     _pos =0;
    97     _size = b._size;
    98     _spaceAvl = b._spaceAvl;
    99     _shallow = false;
    100     _fileState = true;
    101 
    102     _buf = new char[b._spaceAvl];
    103     memcpy((void*) _buf, (void*) b._buf, (size_t) b._spaceAvl);
     95    bufferInit();
     96    append(b.bytes(),b.size());
    10497}
    10598
     
    114107    bufferFree();
    115108    bufferInit();
    116 
    117     _buf = new char[b._spaceAvl];
    118     memcpy((void*) _buf, (void*) b._buf, (size_t) b._spaceAvl);
    119 
    120     _pos = b._pos;
    121     _size = b._size;
    122     _spaceAvl = b._spaceAvl;
    123 
     109    append(b.bytes(),b.size());
     110    return *this;
     111}
     112
     113
     114/**
     115 * Operator +
     116 * @param SimpleBuffer object to add
     117 * @param SimpleBuffer object to add
     118 */
     119SimpleBuffer
     120SimpleBuffer::operator+(const SimpleBuffer& b) const
     121{
     122    SimpleBuffer newBuffer(*this);
     123    newBuffer.operator+=(b);
     124    return newBuffer;
     125}
     126
     127
     128/**
     129 * Operator +=
     130 * @param SimpleBuffer object to add
     131 */
     132SimpleBuffer&
     133SimpleBuffer::operator+=(const SimpleBuffer& b)
     134{
     135    append(b.bytes(),b.size());
    124136    return *this;
    125137}
     
    185197    char *newBuffer = NULL;
    186198
     199    // User specified NULL buffer to append
     200    if (bytes == NULL) {
     201        return 0;
     202    }
     203
    187204    if (nbytes == -1) {
    188205        // user signaled null terminated string
     
    195212    }
    196213
     214    // Empty internal buffer, make sure its properly initialized.
    197215    if (_buf == NULL) {
    198         _size = 0;
    199         _spaceAvl = 0;
     216        bufferInit();
    200217    }
    201218
     
    243260 */
    244261int
    245 SimpleBuffer::read(char* bytes, int nbytes)
     262SimpleBuffer::read(const char* bytes, int nbytes)
    246263{
    247264    int bytesRead = 0;
    248265
     266    // SimpleBuffer is empty.
    249267    if (_buf == NULL) {
    250268        return 0;
    251269    }
    252270
    253     // make sure we dont read off the end of our buffer
     271    // User specified NULL buffer.
     272    if (bytes == NULL) {
     273        return 0;
     274    }
     275
     276    // make sure we don't read off the end of our buffer
    254277    if ( (_pos + nbytes) >= _size) {
    255278        bytesRead = (_size - _pos);
     
    264287
    265288    if (bytesRead > 0) {
    266         memcpy((void*) bytes, (void*) _buf, (size_t) bytesRead);
     289        memcpy((void*) bytes, (void*) (_buf+_pos), (size_t) bytesRead);
    267290    }
    268291
     
    270293
    271294    return bytesRead;
     295}
     296
     297
     298/**
     299 * Set buffer position indicator to spot within the buffer
     300 * @param Offset from whence location in buffer.
     301 * @param Place from where offset is added or subtracted.
     302 * @return 0 on success, anything else is failure
     303 */
     304int
     305SimpleBuffer::seek(int offset, int whence)
     306{
     307    int retVal = 0;
     308
     309    if (_buf == NULL) {
     310        return -1 ;
     311    }
     312
     313    if (whence == SEEK_SET) {
     314        if (offset < 0) {
     315            /* dont go off the beginning of data */
     316            _pos = 0;
     317        }
     318        else if (offset >= _size) {
     319            /* dont go off the end of data */
     320            _pos = _size - 1;
     321        }
     322        else {
     323            _pos = _pos + offset;
     324        }
     325    }
     326    else if (whence == SEEK_CUR) {
     327        if ( (_pos + offset) < 0) {
     328            /* dont go off the beginning of data */
     329            _pos = 0;
     330        }
     331        else if ((_pos + offset) >= _size) {
     332            /* dont go off the end of data */
     333            _pos = _size - 1;
     334        }
     335        else {
     336            _pos = _pos + offset;
     337        }
     338    }
     339    else if (whence == SEEK_END) {
     340        if (offset <= (-1*_size)) {
     341            /* dont go off the beginning of data */
     342            _pos = 0;
     343        }
     344        else if (offset >= 0) {
     345            /* dont go off the end of data */
     346            _pos = _size - 1;
     347        }
     348        else {
     349            _pos = (_size - 1) + offset;
     350        }
     351    }
     352    else {
     353        retVal = -1;
     354    }
     355
     356    return retVal;
     357}
     358
     359
     360/**
     361 * Tell caller the offset of the position indicator from the start of buffer
     362 * @return Number of bytes the position indicator is from start of buffer
     363 */
     364int
     365SimpleBuffer::tell()
     366{
     367   return _pos;
     368}
     369
     370
     371/**
     372 * Read data from the buffer into a memory location provided by caller
     373 */
     374SimpleBuffer&
     375SimpleBuffer::rewind()
     376{
     377    _pos = 0;
     378    return *this;
    272379}
    273380
     
    305412{
    306413    return (_pos >= _size);
    307 }
    308 
    309 
    310 /**
    311  * Use this SimpleBuffer as a temporary pointer to another SimpleBuffer
    312  * This SimpleBuffer does not own the data that it points to, thus
    313  * when clear() or operator=() is called, the data is not deleted,
    314  * but the _buf value is changed. This could lead to a memory leak if
    315  * used improperly.
    316  * @param Pointer location memory to temporarily own.
    317  * @param number of bytes used in the buffer.
    318  * @param number of total bytes in the allocated buffer.
    319  * @return True or false boolean value.
    320  */
    321 SimpleBuffer&
    322 SimpleBuffer::shallowCopy(char* bytes, int nBytes, int spaceAvl)
    323 {
    324     bufferFree();
    325 
    326     _buf = bytes;
    327     _pos = 0;
    328     _size = nBytes;
    329     _spaceAvl = spaceAvl;
    330     _shallow = true;
    331     _fileState = true;
    332 
    333     return *this;
    334414}
    335415
     
    345425SimpleBuffer::move(SimpleBuffer& b)
    346426{
    347     b.bufferFree();
    348 
    349     b._buf = _buf;
    350     b._pos = 0;
    351     b._size = _size;
    352     b._spaceAvl = _spaceAvl;
    353     b._shallow = _shallow;
    354 
    355     bufferInit();
     427    bufferFree();
     428
     429    _buf = b._buf;
     430    _pos = b._pos;
     431    _size = b._size;
     432    _spaceAvl = b._spaceAvl;
     433    _fileState = b._fileState;
     434
     435    b.bufferInit();
    356436
    357437    return *this;
     
    371451    _size = 0;
    372452    _spaceAvl = 0;
    373     _shallow = false;
    374453    _fileState = true;
    375454}
     
    383462SimpleBuffer::bufferFree()
    384463{
    385     if (_shallow == false) {
    386         if (_buf != NULL) {
    387             delete [] _buf;
    388             _buf = NULL;
    389         }
     464    if (_buf != NULL) {
     465        delete [] _buf;
     466        _buf = NULL;
    390467    }
    391468    bufferInit();
     
    422499 */
    423500Buffer::Buffer(const Buffer& b)
    424   : _level(b._level),
     501  : SimpleBuffer(b),
     502    _level(b._level),
    425503    _compressionType(b._compressionType),
    426504    _windowBits(b._windowBits)
    427 {
    428     bufferInit();
    429 
    430     _buf = new char[b._spaceAvl];
    431     memcpy((void*) _buf, (void*) b._buf, (size_t) b._spaceAvl);
    432     _size = b._size;
    433     _spaceAvl = b._spaceAvl;
    434 }
     505{}
    435506
    436507/**
     
    441512Buffer::operator=(const Buffer& b)
    442513{
    443     bufferFree();
    444     bufferInit();
    445 
    446     _buf = new char[b._spaceAvl];
    447     memcpy((void*) _buf, (void*) b._buf, (size_t) b._spaceAvl);
    448     _pos = b._pos;
    449     _size = b._size;
    450     _spaceAvl = b._spaceAvl;
     514    SimpleBuffer::operator=(b);
    451515
    452516    _level = b._level;
    453517    _compressionType = b._compressionType;
    454518    _windowBits = b._windowBits;
    455     _fileState = b._fileState;
    456519
    457520    return *this;
     
    459522
    460523
     524Buffer
     525Buffer::operator+(const Buffer& b) const
     526{
     527    Buffer newBuffer(*this);
     528    newBuffer.operator+=(b);
     529    return newBuffer;
     530}
     531
     532
    461533Buffer&
    462 Buffer::operator=(const SimpleBuffer& b)
    463 {
    464     bufferFree();
    465     bufferInit();
    466 
    467     _buf = new char[b.size()];
    468     memcpy((void*) _buf, (void*) b.bytes(), (size_t) b.size());
    469     _pos = 0;
    470     _size = b.size();
    471     _spaceAvl = b.size();
    472 
    473     _level = 6;
    474     _compressionType = RPCOMPRESS_GZIP;
    475     _windowBits = 15;
    476     _fileState = true;
    477 
     534Buffer::operator+=(const Buffer& b)
     535{
     536    SimpleBuffer::operator+=(b);
    478537    return *this;
    479538}
     
    538597    }
    539598
    540     outFile.write(_buf,_size);
     599    outFile.write(bytes(),size());
    541600    outFile.close();
    542601
     
    555614    err.addContext("Rappture::Buffer::encode()");
    556615
    557     bin.shallowCopy(_buf, _size, _spaceAvl);
     616    rewind();
    558617
    559618    if (compress) {
    560         do_compress(err,bin,bout);
     619        do_compress(err,*this,bout);
    561620    }
    562621
    563622    if (base64) {
    564623        if (compress) {
    565             bout.move(bin);
    566         }
    567         do_base64_enc(err,bin,bout);
     624            bin.move(bout);
     625            do_base64_enc(err,bin,bout);
     626        }
     627        else {
     628            do_base64_enc(err,*this,bout);
     629        }
    568630    }
    569631
    570632    if (!err) {
    571633        // write the encoded data to the internal buffer
    572         bufferFree();
    573         operator=(bout);
     634        move(bout);
    574635    }
    575636
     
    585646    SimpleBuffer bout;
    586647
    587     bin.shallowCopy(_buf, _size, _spaceAvl);
     648    rewind();
    588649
    589650    if (base64) {
    590         do_base64_dec(err,bin,bout);
     651        do_base64_dec(err,*this,bout);
    591652    }
    592653
    593654    if (decompress) {
    594655        if (base64) {
    595             bout.move(bin);
    596         }
    597         do_decompress(err,bin,bout);
     656            bin.move(bout);
     657            do_decompress(err,bin,bout);
     658        }
     659        else {
     660            do_decompress(err,*this,bout);
     661        }
    598662    }
    599663
    600664    if (!err) {
    601665        // write the decoded data to the internal buffer
    602         bufferFree();
    603         operator=(bout);
     666        move(bout);
    604667    }
    605668
     
    609672
    610673void
    611 Buffer::do_compress(Outcome& status, SimpleBuffer& bin, SimpleBuffer& bout)
    612 {
    613     int ret, flush;
    614     unsigned have;
     674Buffer::do_compress(    Outcome& status,
     675                        SimpleBuffer& bin,
     676                        SimpleBuffer& bout  )
     677{
     678    int ret=0, flush=0;
     679    unsigned have=0;
    615680    z_stream strm;
    616681
     
    638703    do {
    639704        strm.avail_in = bin.read(in, CHUNK);
    640         if (bad() == true) {
     705        if (bin.bad() == true) {
    641706            (void)deflateEnd(&strm);
    642707            // return Z_ERRNO;
     
    646711        }
    647712        flush = bin.eof() ? Z_FINISH : Z_NO_FLUSH;
    648         strm.next_in = (unsigned char*) in;
     713        strm.next_in = (Bytef*) in;
    649714        /* run deflate() on input until output buffer not full, finish
    650715           compression if all of source has been read in */
    651716        do {
    652717            strm.avail_out = CHUNK;
    653             strm.next_out = (unsigned char*) out;
     718            strm.next_out = (Bytef*) out;
    654719            ret = deflate(&strm, flush);    /* no bad return value */
    655720            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
     
    681746
    682747void
    683 Buffer::do_decompress(Outcome& status, SimpleBuffer& bin, SimpleBuffer& bout)
     748Buffer::do_decompress(  Outcome& status,
     749                        SimpleBuffer& bin,
     750                        SimpleBuffer& bout  )
    684751{
    685752    int ret;
     
    709776    do {
    710777        strm.avail_in = bin.read(in, CHUNK);
    711         if (bad() == true) {
     778        if (bin.bad() == true) {
    712779            (void)inflateEnd(&strm);
    713780            // return Z_ERRNO;
     
    761828void
    762829Buffer::do_base64_enc(  Outcome& status,
    763                         SimpleBuffer& bin,
     830                        const SimpleBuffer& bin,
    764831                        SimpleBuffer& bout )
    765832{
     
    782849void
    783850Buffer::do_base64_dec(  Outcome& status,
    784                         SimpleBuffer& bin,
     851                        const SimpleBuffer& bin,
    785852                        SimpleBuffer& bout )
    786853{
  • trunk/src2/core/RpBuffer.h

    r575 r583  
    8686    SimpleBuffer(const SimpleBuffer& b);
    8787    SimpleBuffer& operator=(const SimpleBuffer& b);
     88    SimpleBuffer  operator+(const SimpleBuffer& b) const;
     89    SimpleBuffer& operator+=(const SimpleBuffer& b);
    8890    virtual ~SimpleBuffer();
    8991
     
    9395    SimpleBuffer& clear();
    9496    int append(const char* bytes, int nbytes=-1);
    95     int read(char* bytes, int nbytes);
     97    int read(const char* bytes, int nbytes);
     98    int seek(int offset, int whence);
     99    int tell();
     100    SimpleBuffer& rewind();
    96101
    97102    bool good() const;
     
    99104    bool eof() const;
    100105
    101     SimpleBuffer& shallowCopy(char* bytes, int nBytes, int spaceAvl);
    102106    SimpleBuffer& move(SimpleBuffer& b);
    103107
    104108protected:
     109
     110    void bufferInit();
     111    void bufferFree();
     112
     113private:
     114
    105115    /// Pointer to the memory that holds our buffer's data
    106116    char* _buf;
     
    115125    int _spaceAvl;
    116126
    117     /// Shallow copy flag.
    118     bool _shallow;
    119 
    120127    /// State of the last file like operation.
    121128    bool _fileState;
    122 
    123     void bufferInit();
    124     void bufferFree();
    125129};
    126130
     
    137141    Buffer(const char* bytes, int nbytes=-1);
    138142    Buffer(const Buffer& buffer);
    139     Buffer& operator=(const Buffer& buffer);
     143    Buffer& operator=(const Buffer& b);
     144    Buffer  operator+(const Buffer& b) const;
     145    Buffer& operator+=(const Buffer& b);
    140146    virtual ~Buffer();
    141147
     
    158164    enum { CHUNK = 4096 };
    159165
    160     Buffer& operator=(const SimpleBuffer& buffer);
    161     void do_compress(Outcome& status,SimpleBuffer& bin,SimpleBuffer& bout);
    162     void do_decompress(Outcome& status,SimpleBuffer& bin,SimpleBuffer& bout);
    163     void do_base64_enc(Outcome& status,SimpleBuffer& bin,SimpleBuffer& bout);
    164     void do_base64_dec(Outcome& status,SimpleBuffer& bin,SimpleBuffer& bout);
     166    void do_compress(   Outcome& status,
     167                        SimpleBuffer& bin,
     168                        SimpleBuffer& bout  );
     169    void do_decompress( Outcome& status,
     170                        SimpleBuffer& bin,
     171                        SimpleBuffer& bout  );
     172    void do_base64_enc( Outcome& status,
     173                        const SimpleBuffer& bin,
     174                        SimpleBuffer& bout  );
     175    void do_base64_dec( Outcome& status,
     176                        const SimpleBuffer& bin,
     177                        SimpleBuffer& bout  );
    165178};
    166179
  • trunk/src2/core/RpBuffer_test.cc

    r575 r583  
    449449        return (tests == passed);
    450450    }
     451
     452    passed++;
     453    /* =========================================================== */
     454
     455    return (tests == passed);
     456}
     457
     458int testFile()
     459{
     460    int passed = 0;
     461    int tests = 0;
     462
     463
     464    /* =========================================================== */
     465    tests++;
     466    const char* inFile = "out.dx";
     467    const char* outFile = "out.dx.gz";
     468    Rappture::Buffer buffer1;
     469    buffer1.load(inFile);
     470
     471    // compress, dont encode
     472    buffer1.encode(true,false);
     473    std::remove(outFile);
     474    buffer1.dump(outFile);
     475    buffer1.decode(true,false);
     476
     477    /*
     478    if (size1before != 26) {
     479        std::cout << "Error testClear1" << std::endl;
     480        std::cout << "incorrect buffer size" << std::endl;
     481        return (tests == passed);
     482    }
     483    if (size1after != 0) {
     484        std::cout << "Error testClear1" << std::endl;
     485        std::cout << "clear failed buffer size" << std::endl;
     486        return (tests == passed);
     487    }
     488    */
    451489
    452490    passed++;
     
    468506    passed += testLoad();
    469507    passed += testClear();
    470 
    471     if (passed != 8) {
     508    passed += testFile();
     509
     510    if (passed != 9) {
    472511        printf("failed: %d\n", passed);
    473512    }
Note: See TracChangeset for help on using the changeset viewer.