xref: /haiku/src/libs/icon/flat_icon/LittleEndianBuffer.h (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
1 /*
2  * Copyright 2006, 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 
9 #ifndef LITTLE_ENDIAN_BUFFER_H
10 #define LITTLE_ENDIAN_BUFFER_H
11 
12 #include <SupportDefs.h>
13 
14 class LittleEndianBuffer {
15  public:
16 								LittleEndianBuffer();
17 								LittleEndianBuffer(size_t size);
18 								LittleEndianBuffer(uint8* buffer,
19 												   size_t size);
20 								~LittleEndianBuffer();
21 
22 			bool				Write(uint8 value);
23 			bool				Write(uint16 value);
24 			bool				Write(uint32 value);
25 			bool				Write(float value);
26 			bool				Write(double value);
27 
28 			bool				Write(const LittleEndianBuffer& other);
29 			bool				Write(const uint8* buffer, size_t bytes);
30 
31 			bool				Read(uint8& value);
32 			bool				Read(uint16& value);
33 			bool				Read(uint32& value);
34 			bool				Read(float& value);
35 			bool				Read(double& value);
36 			bool				Read(LittleEndianBuffer& other, size_t bytes);
37 
38 			void				Skip(size_t bytes);
39 
40 			uint8*				Buffer() const
41 									{ return fBuffer; }
42 			size_t				SizeUsed() const
43 									{ return fHandle - fBuffer; }
44 
45 			void				Reset();
46 
47  private:
48 			void				_SetSize(size_t size);
49 
50 			uint8*				fBuffer;
51 			uint8*				fHandle;
52 			uint8*				fBufferEnd;
53 			size_t				fSize;
54 			bool				fOwnsBuffer;
55 };
56 
57 #endif // LITTLE_ENDIAN_BUFFER_H
58