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