1 /* 2 * Copyright 2006-2007, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 #ifndef LITTLE_ENDIAN_BUFFER_H 9 #define LITTLE_ENDIAN_BUFFER_H 10 11 12 #include <SupportDefs.h> 13 14 15 namespace BPrivate { 16 namespace Icon { 17 18 class LittleEndianBuffer { 19 public: 20 LittleEndianBuffer(); 21 LittleEndianBuffer(size_t size); 22 LittleEndianBuffer(uint8* buffer, 23 size_t size); 24 ~LittleEndianBuffer(); 25 26 bool Write(uint8 value); 27 bool Write(uint16 value); 28 bool Write(uint32 value); 29 bool Write(float value); 30 bool Write(double value); 31 32 bool Write(const LittleEndianBuffer& other); 33 bool Write(const uint8* buffer, size_t bytes); 34 35 bool Read(uint8& value); 36 bool Read(uint16& value); 37 bool Read(uint32& value); 38 bool Read(float& value); 39 bool Read(double& value); 40 bool Read(LittleEndianBuffer& other, size_t bytes); 41 42 void Skip(size_t bytes); 43 44 uint8* Buffer() const 45 { return fBuffer; } 46 size_t SizeUsed() const 47 { return fHandle - fBuffer; } 48 49 void Reset(); 50 51 private: 52 void _SetSize(size_t size); 53 54 uint8* fBuffer; 55 uint8* fHandle; 56 uint8* fBufferEnd; 57 size_t fSize; 58 bool fOwnsBuffer; 59 }; 60 61 } // namespace Icon 62 } // namespace BPrivate 63 64 #endif // LITTLE_ENDIAN_BUFFER_H 65