Subversion Repositories HomeAutomation

Rev

Rev 1326 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * BitBuffer.h
  3.  *
  4.  *  Created on: Jul 17, 2009
  5.  *      Author: Mattias Runge
  6.  */
  7.  
  8. #ifndef BITBUFFER_H_
  9. #define BITBUFFER_H_
  10.  
  11. #include <vector>
  12. #include <string>
  13. #include "types.h"
  14.  
  15. namespace atom {
  16. namespace message {
  17.  
  18. using namespace std;
  19.  
  20. class BitBuffer {
  21. public:
  22.     BitBuffer(byte_list bytes);
  23.     BitBuffer();
  24.     virtual ~BitBuffer();
  25.  
  26.     byte_list getAsBytes();
  27.     void setFromBytes(byte_list bytes);
  28.  
  29.     unsigned int getSize();
  30.     unsigned int getPointer();
  31.     void incrementPointer(unsigned int steps);
  32.     void clear();
  33.  
  34.     void read(unsigned int length, long & value);
  35.     void read(unsigned int length, unsigned long & value);
  36.     void read(unsigned int length, bool & value);
  37.  
  38.     void write(unsigned int length, long value);
  39.     void write(unsigned int length, unsigned long value);
  40.     void write(unsigned int length, bool value);
  41.  
  42. private:
  43.     bit_list myBits;
  44.     unsigned int myPointer;
  45.  
  46.     bool readBit();
  47.     void writeBit(bool value);
  48. };
  49.  
  50. }
  51. }
  52.  
  53. #endif /* BITBUFFER_H_ */
  54.