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#include "IconBuild.h"
15
16
17_BEGIN_ICON_NAMESPACE
18
19
20class LittleEndianBuffer {
21 public:
22								LittleEndianBuffer();
23								LittleEndianBuffer(size_t size);
24								LittleEndianBuffer(uint8* buffer,
25												   size_t size);
26								~LittleEndianBuffer();
27
28			bool				Write(uint8 value);
29			bool				Write(uint16 value);
30			bool				Write(uint32 value);
31			bool				Write(float value);
32			bool				Write(double value);
33
34			bool				Write(const LittleEndianBuffer& other);
35			bool				Write(const uint8* buffer, size_t bytes);
36
37			bool				Read(uint8& value);
38			bool				Read(uint16& value);
39			bool				Read(uint32& value);
40			bool				Read(float& value);
41			bool				Read(double& value);
42			bool				Read(LittleEndianBuffer& other, size_t bytes);
43
44			void				Skip(size_t bytes);
45
46			uint8*				Buffer() const
47									{ return fBuffer; }
48			size_t				SizeUsed() const
49									{ return fHandle - fBuffer; }
50
51			void				Reset();
52
53 private:
54			void				_SetSize(size_t size);
55
56			uint8*				fBuffer;
57			uint8*				fHandle;
58			uint8*				fBufferEnd;
59			size_t				fSize;
60			bool				fOwnsBuffer;
61};
62
63
64_END_ICON_NAMESPACE
65
66
67#endif	// LITTLE_ENDIAN_BUFFER_H
68