live
BitVector.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2024 Live Networks, Inc. All rights reserved.
18// Bit Vector data structure
19// C++ header
20
21#ifndef _BIT_VECTOR_HH
22#define _BIT_VECTOR_HH
23
24#ifndef _BOOLEAN_HH
25#include "Boolean.hh"
26#endif
27
28class BitVector {
29public:
30 BitVector(unsigned char* baseBytePtr,
31 unsigned baseBitOffset,
32 unsigned totNumBits);
33
34 void setup(unsigned char* baseBytePtr,
35 unsigned baseBitOffset,
36 unsigned totNumBits);
37
38 void putBits(unsigned from, unsigned numBits); // "numBits" <= 32
39 void put1Bit(unsigned bit);
40
41 unsigned getBits(unsigned numBits); // "numBits" <= 32
42 unsigned get1Bit();
43 Boolean get1BitBoolean() { return get1Bit() != 0; }
44
45 void skipBits(unsigned numBits);
46
47 unsigned curBitIndex() const { return fCurBitIndex; }
48 unsigned totNumBits() const { return fTotNumBits; }
49 unsigned numBitsRemaining() const { return fTotNumBits - fCurBitIndex; }
50
51 unsigned get_expGolomb();
52 // Returns the value of the next bits, assuming that they were encoded using an exponential-Golomb code of order 0
53 int get_expGolombSigned(); // signed version of the above
54
55private:
56 unsigned char* fBaseBytePtr;
58 unsigned fTotNumBits;
59 unsigned fCurBitIndex;
60};
61
62// A general bit copy operation:
63void shiftBits(unsigned char* toBasePtr, unsigned toBitOffset,
64 unsigned char const* fromBasePtr, unsigned fromBitOffset,
65 unsigned numBits);
66
67#endif
void shiftBits(unsigned char *toBasePtr, unsigned toBitOffset, unsigned char const *fromBasePtr, unsigned fromBitOffset, unsigned numBits)
unsigned char Boolean
Definition: Boolean.hh:25
Boolean get1BitBoolean()
Definition: BitVector.hh:43
unsigned fCurBitIndex
Definition: BitVector.hh:59
unsigned get_expGolomb()
int get_expGolombSigned()
unsigned char * fBaseBytePtr
Definition: BitVector.hh:56
unsigned get1Bit()
BitVector(unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits)
unsigned fTotNumBits
Definition: BitVector.hh:58
void setup(unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits)
void skipBits(unsigned numBits)
unsigned numBitsRemaining() const
Definition: BitVector.hh:49
unsigned fBaseBitOffset
Definition: BitVector.hh:57
void putBits(unsigned from, unsigned numBits)
unsigned totNumBits() const
Definition: BitVector.hh:48
unsigned getBits(unsigned numBits)
unsigned curBitIndex() const
Definition: BitVector.hh:47
void put1Bit(unsigned bit)