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 | |
---|
21 | #ifdef __cplusplus |
---|
22 | extern "C" { |
---|
23 | #endif // ifdef __cplusplus |
---|
24 | |
---|
25 | enum RP_COMPRESS_CONSTS { |
---|
26 | RPCOMPRESS_ZLIB = 0, |
---|
27 | RPCOMPRESS_GZIP = 16 |
---|
28 | }; |
---|
29 | |
---|
30 | namespace Rappture { |
---|
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 | |
---|
39 | class Buffer : public SimpleCharBuffer{ |
---|
40 | public: |
---|
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 | |
---|
55 | protected: |
---|
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 | SimpleCharBuffer& bin, |
---|
70 | SimpleCharBuffer& bout ); |
---|
71 | void do_decompress( Outcome& status, |
---|
72 | SimpleCharBuffer& bin, |
---|
73 | SimpleCharBuffer& bout ); |
---|
74 | void do_base64_enc( Outcome& status, |
---|
75 | const SimpleCharBuffer& bin, |
---|
76 | SimpleCharBuffer& bout ); |
---|
77 | void do_base64_dec( Outcome& status, |
---|
78 | const SimpleCharBuffer& bin, |
---|
79 | SimpleCharBuffer& bout ); |
---|
80 | }; |
---|
81 | |
---|
82 | } // namespace Rappture |
---|
83 | |
---|
84 | #ifdef __cplusplus |
---|
85 | } |
---|
86 | #endif // ifdef __cplusplus |
---|
87 | |
---|
88 | #endif // RAPPTURE_BUFFER_H |
---|