huffman/codec.h

changeset 76
6de6d9a64ebd
parent 8
8b697d30c49f
equal deleted inserted replaced
75:5f8a03274d75 76:6de6d9a64ebd
1 /*
2 * skulltag::Codec class interface - Base class for data encoding or decoding operations.
3 *
4 * Copyright 2009 Timothy Landers
5 * email: code.vortexcortex@gmail.com
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26 #ifndef _CODEC_VERSION
27 #define _CODEC_VERSION 1
28
29 /** Prevents naming convention problems via encapsulation. */
30 namespace skulltag {
31
32 /** Huffman tree node -- used to represent a Huffman tree. <br>
33 * Huffman trees are use by compression / decompression codecs. */
34 struct HuffmanNode {
35 int bitCount; /**< number of bits in the Huffman code. */
36 int code; /**< bit representation of a Huffman code. */
37 int value; /**< the value the Huffman code represents. */
38 HuffmanNode * branch; /**< the left and right child branches or NULL (0) if leaf. */
39 };
40
41 // Codec Class Interface
42
43 /** Base class for encoding and decoding data. */
44 class Codec {
45
46 public:
47
48 /** Decodes data read from an input buffer and stores the result in the output buffer.
49 * @return number of bytes stored in the output buffer or -1 if an error occurs while encoding. */
50 virtual int encode(
51 unsigned char const * const input, /**< in: pointer to the first byte to encode. */
52 unsigned char * const output, /**< out: pointer to an output buffer to store data. */
53 int const &inLength, /**< in: number of bytes of input buffer to encoded. */
54 int const &outLength /**< in: maximum length of data to output. */
55 ) const = 0;
56
57 /** Decodes data read from an input buffer and stores the result in the output buffer.
58 * @return number of bytes stored in the output buffer or -1 if an error occurs while decoding. */
59 virtual int decode(
60 unsigned char const * const input, /**< in: pointer to data that needs decoding. */
61 unsigned char * const output, /**< out: pointer to output buffer to store decoded data. */
62 int const &inLength, /**< in: number of bytes of input buffer to read. */
63 int const &outLength /**< in: maximum length of data to output. */
64 ) = 0;
65
66 }; // end class Codec
67
68 }; // end namespace Codec
69
70 #endif

mercurial