00001 /********** 00002 This library is free software; you can redistribute it and/or modify it under 00003 the terms of the GNU Lesser General Public License as published by the 00004 Free Software Foundation; either version 2.1 of the License, or (at your 00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) 00006 00007 This library is distributed in the hope that it will be useful, but WITHOUT 00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00009 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00010 more details. 00011 00012 You should have received a copy of the GNU Lesser General Public License 00013 along with this library; if not, write to the Free Software Foundation, Inc., 00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 **********/ 00016 // "liveMedia" 00017 // Copyright (c) 1996-2008 Live Networks, Inc. All rights reserved. 00018 // Bit Vector data structure 00019 // C++ header 00020 00021 #ifndef _BIT_VECTOR_HH 00022 #define _BIT_VECTOR_HH 00023 00024 class BitVector { 00025 public: 00026 BitVector(unsigned char* baseBytePtr, 00027 unsigned baseBitOffset, 00028 unsigned totNumBits); 00029 00030 void setup(unsigned char* baseBytePtr, 00031 unsigned baseBitOffset, 00032 unsigned totNumBits); 00033 00034 void putBits(unsigned from, unsigned numBits); // "numBits" <= 32 00035 void put1Bit(unsigned bit); 00036 00037 unsigned getBits(unsigned numBits); // "numBits" <= 32 00038 unsigned get1Bit(); 00039 00040 void skipBits(unsigned numBits); 00041 00042 unsigned curBitIndex() const { return fCurBitIndex; } 00043 unsigned totNumBits() const { return fTotNumBits; } 00044 unsigned numBitsRemaining() const { return fTotNumBits - fCurBitIndex; } 00045 00046 private: 00047 unsigned char* fBaseBytePtr; 00048 unsigned fBaseBitOffset; 00049 unsigned fTotNumBits; 00050 unsigned fCurBitIndex; 00051 }; 00052 00053 // A general bit copy operation: 00054 void shiftBits(unsigned char* toBasePtr, unsigned toBitOffset, 00055 unsigned char const* fromBasePtr, unsigned fromBitOffset, 00056 unsigned numBits); 00057 00058 #endif
1.5.2