xref: /haiku/src/libs/icon/flat_icon/LittleEndianBuffer.h (revision 25dc253d6ab28ce204fa4de2d3e7a27d167fc817)
1fb07ece0SStephan Aßmus /*
2325a6253SAxel 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 
11325a6253SAxel Dörfler 
12fb07ece0SStephan Aßmus #include <SupportDefs.h>
13fb07ece0SStephan Aßmus 
14*25dc253dSIngo Weinhold #include "IconBuild.h"
15325a6253SAxel Dörfler 
16*25dc253dSIngo Weinhold 
17*25dc253dSIngo Weinhold _BEGIN_ICON_NAMESPACE
18*25dc253dSIngo Weinhold 
19325a6253SAxel Dörfler 
20fb07ece0SStephan Aßmus class LittleEndianBuffer {
21fb07ece0SStephan Aßmus  public:
22fb07ece0SStephan Aßmus 								LittleEndianBuffer();
23fb07ece0SStephan Aßmus 								LittleEndianBuffer(size_t size);
24fb07ece0SStephan Aßmus 								LittleEndianBuffer(uint8* buffer,
25fb07ece0SStephan Aßmus 												   size_t size);
26fb07ece0SStephan Aßmus 								~LittleEndianBuffer();
27fb07ece0SStephan Aßmus 
28fb07ece0SStephan Aßmus 			bool				Write(uint8 value);
29fb07ece0SStephan Aßmus 			bool				Write(uint16 value);
30fb07ece0SStephan Aßmus 			bool				Write(uint32 value);
31fb07ece0SStephan Aßmus 			bool				Write(float value);
32fb07ece0SStephan Aßmus 			bool				Write(double value);
33fb07ece0SStephan Aßmus 
34fb07ece0SStephan Aßmus 			bool				Write(const LittleEndianBuffer& other);
35fb07ece0SStephan Aßmus 			bool				Write(const uint8* buffer, size_t bytes);
36fb07ece0SStephan Aßmus 
37fb07ece0SStephan Aßmus 			bool				Read(uint8& value);
38fb07ece0SStephan Aßmus 			bool				Read(uint16& value);
39fb07ece0SStephan Aßmus 			bool				Read(uint32& value);
40fb07ece0SStephan Aßmus 			bool				Read(float& value);
41fb07ece0SStephan Aßmus 			bool				Read(double& value);
42fb07ece0SStephan Aßmus 			bool				Read(LittleEndianBuffer& other, size_t bytes);
43fb07ece0SStephan Aßmus 
44fb07ece0SStephan Aßmus 			void				Skip(size_t bytes);
45fb07ece0SStephan Aßmus 
Buffer()46fb07ece0SStephan Aßmus 			uint8*				Buffer() const
47fb07ece0SStephan Aßmus 									{ return fBuffer; }
SizeUsed()48fb07ece0SStephan Aßmus 			size_t				SizeUsed() const
49fb07ece0SStephan Aßmus 									{ return fHandle - fBuffer; }
50fb07ece0SStephan Aßmus 
51fb07ece0SStephan Aßmus 			void				Reset();
52fb07ece0SStephan Aßmus 
53fb07ece0SStephan Aßmus  private:
54fb07ece0SStephan Aßmus 			void				_SetSize(size_t size);
55fb07ece0SStephan Aßmus 
56fb07ece0SStephan Aßmus 			uint8*				fBuffer;
57fb07ece0SStephan Aßmus 			uint8*				fHandle;
58fb07ece0SStephan Aßmus 			uint8*				fBufferEnd;
59fb07ece0SStephan Aßmus 			size_t				fSize;
60fb07ece0SStephan Aßmus 			bool				fOwnsBuffer;
61fb07ece0SStephan Aßmus };
62fb07ece0SStephan Aßmus 
63*25dc253dSIngo Weinhold 
64*25dc253dSIngo Weinhold _END_ICON_NAMESPACE
65*25dc253dSIngo Weinhold 
66325a6253SAxel Dörfler 
67fb07ece0SStephan Aßmus #endif	// LITTLE_ENDIAN_BUFFER_H
68