BitVector.hh 2.2 KB

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