source: trunk/src/core/RpBuffer.h @ 1038

Last change on this file since 1038 was 1038, checked in by dkearney, 15 years ago

adding the simple buffer object back to the repository because it was accidentally removed in rev 1018

File size: 2.4 KB
Line 
1/*
2 * ======================================================================
3 *  Rappture::Buffer
4 *
5 *  AUTHOR:  Derrick Kearney, Purdue University
6 *
7 *  Copyright (c) 2004-2008  Purdue Research Foundation
8 * ----------------------------------------------------------------------
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13
14#ifndef RAPPTURE_BUFFER_H
15#define RAPPTURE_BUFFER_H
16
17#include <RpOutcome.h>
18#include <RpSimpleBuffer.h>
19
20#ifdef __cplusplus
21    extern "C" {
22#endif // ifdef __cplusplus
23
24enum RP_COMPRESS_CONSTS {
25    RPCOMPRESS_ZLIB      = 0,
26    RPCOMPRESS_GZIP      = 16
27};
28
29namespace Rappture {
30
31
32/**
33 * Block of memory that dynamically resizes itself as needed.
34 * The buffer also allows caller to massage the data it holds
35 * with functionallity including gzip compression based on zlib
36 * and base64 encoding based on libb64.
37 */
38
39class Buffer : public SimpleBuffer{
40public:
41    Buffer();
42    Buffer(int nbytes);
43    Buffer(const char* bytes, int nbytes=-1);
44    Buffer(const Buffer& buffer);
45    Buffer& operator=(const Buffer& b);
46    Buffer  operator+(const Buffer& b) const;
47    Buffer& operator+=(const Buffer& b);
48    virtual ~Buffer();
49
50    Outcome load(const char* filePath);
51    Outcome dump(const char* filePath);
52    Outcome encode(unsigned int compress=1, unsigned int base64=1);
53    Outcome decode(unsigned int decompress=1, unsigned int base64=1);
54
55protected:
56
57    /// Compression level for the zlib functions
58    int _level;
59
60    /// compression type for the zlib functions.
61    int _compressionType;
62
63    /// number of window bits, adjusts speed of compression
64    int _windowBits;
65
66    enum { CHUNK = 4096 };
67
68    void do_compress(   Outcome& status,
69                        SimpleBuffer& bin,
70                        SimpleBuffer& bout  );
71    void do_decompress( Outcome& status,
72                        SimpleBuffer& bin,
73                        SimpleBuffer& bout  );
74    void do_base64_enc( Outcome& status,
75                        const SimpleBuffer& bin,
76                        SimpleBuffer& bout  );
77    void do_base64_dec( Outcome& status,
78                        const SimpleBuffer& bin,
79                        SimpleBuffer& bout  );
80};
81
82} // namespace Rappture
83 
84#ifdef __cplusplus
85    }
86#endif // ifdef __cplusplus
87
88#endif // RAPPTURE_BUFFER_H
Note: See TracBrowser for help on using the repository browser.