~qwertitis-deactivatedaccount/linuxdcpp/i18n

276 by Razzloss
Copied dcpp/ from 0705-branch
1
/*
2
 * Copyright (C) 2001-2008 Jacek Sieka, arnetheduck on gmail point com
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#if !defined(BIT_INPUT_STREAM_H)
20
#define BIT_INPUT_STREAM_H
21
22
#include "Exception.h"
23
24
namespace dcpp {
25
26
STANDARD_EXCEPTION(BitStreamException);
27
28
/**
29
 * A clumsy bit streamer, assumes that there's enough data to complete the operations.
30
 * No, doesn't operate on streams...=)
31
 */
32
class BitInputStream
33
{
34
public:
35
	BitInputStream(const uint8_t* aStream, size_t aStart, size_t aEnd) : bitPos(aStart*8), endPos(aEnd*8), is(aStream) { }
36
	~BitInputStream() { }
37
38
	bool get() throw(BitStreamException) {
39
		if(bitPos > endPos) {
300 by David Grundberg
Removed all strings from the Streams.h header included from linux/. PACKAGE definition now used consistantly. Various build script fixes.
40
			throw BitStreamException(_("Request to seek beyond the end of data"));
276 by Razzloss
Copied dcpp/ from 0705-branch
41
		}
42
		bool ret = (((uint8_t)is[bitPos>>3]) >> (bitPos&0x07)) & 0x01;
43
		bitPos++;
44
		return ret;
45
	}
46
47
	void skipToByte() {
48
		if(bitPos%8 != 0)
49
			bitPos = (bitPos & (~7)) + 8;
50
	}
51
52
	void skip(int n) {
53
		bitPos += n * 8;
54
		return ;
55
	}
56
private:
57
	BitInputStream(const BitInputStream&);
58
	BitInputStream& operator=(const BitInputStream&);
59
60
	size_t bitPos;
61
	size_t endPos;
62
	const uint8_t* is;
63
};
64
65
} // namespace dcpp
66
67
#endif // !defined(BIT_INPUT_STREAM_H)