Updated changelog
[amule.git] / src / RLE.h
blob11ccc4eaf739fd78f635438d056c22a681919311
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #ifndef RLE_H
26 #define RLE_H
29 #include "Types.h"
31 /*!
32 * General purpose RLE implementation. Just encode or create
33 * differential data with previous
35 class RLE_Data
37 public:
38 RLE_Data(int len = 0, bool use_diff = true) { setup(len, use_diff); }
40 // those constructors are for stl containers
41 RLE_Data(const RLE_Data & obj) { setup(obj.m_len, obj.m_use_diff, obj.m_buff); }
42 RLE_Data &operator=(const RLE_Data &);
44 ~RLE_Data();
46 const uint8 *Encode(const ArrayOfUInts16 &data, int &outlen, bool &changed);
47 const uint8 *Encode(const ArrayOfUInts64 &data, int &outlen, bool &changed);
49 const uint8 *Decode(const uint8 *data, int len);
50 void Decode(const uint8 *data, int len, ArrayOfUInts64 &outdata);
52 void ResetEncoder();
54 // decoder will need access to data
55 const uint8 *Buffer() const { return m_buff; }
56 int Size() const { return m_len; }
58 private:
59 void setup(int len, bool use_diff, uint8 * content = 0);
61 // change size of internal buffers
62 // returns true if size was changed
63 bool Realloc(int size);
66 // Encode some raw data
68 // data: block to encode
69 // inlen: number of bytes to encode. May be zero, then data can also be 0.
70 // outlen: here the number of encoded bytes gets stored (0 if inlen is 0)
71 // changed: becomes true if the size has changed or a change in the data occured,
72 // so the differential data (before encoding) is not all zero
74 // return: new buffer with encoded data, must be deleted after use!
76 const uint8 *Encode(const uint8 *data, int inlen, int &outlen, bool &changed);
78 // Encode: source data (original or diff in diff mode)
79 // Decode: store decoded data
80 uint8 *m_buff;
81 // Unpacked size
82 int m_len;
83 // Use differential encoding
84 bool m_use_diff;
88 /*!
89 * Data difference is different for each EC client
91 class PartFileEncoderData {
92 protected:
93 // number of sources for each part for progress bar colouring
94 RLE_Data m_part_status;
95 // gap list
96 RLE_Data m_gap_status;
97 // blocks requested for download
98 RLE_Data m_req_status;
100 public:
102 // decoder side - can be used everywhere
103 void DecodeParts(const class CECTag * tag, ArrayOfUInts16 &outdata);
104 void DecodeGaps(const class CECTag * tag, ArrayOfUInts64 &outdata);
105 void DecodeReqs(const class CECTag * tag, ArrayOfUInts64 &outdata);
108 #endif
110 // File_checked_for_headers