1/*
2 * File:	Blob.h
3 *
4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
6 */
7#if !defined(_Blob_h_)
8#define _Blob_h_
9
10#include "stdafx.h"
11
12/*!
13 * \brief Manages a binary object of arbitrary length.
14 *
15 * The data block is allocated with malloc() instead of the new
16 * operator so that we can use realloc() to resize it.
17 */
18class Blob
19{
20public:
21	//! \brief Default constructor.
22	Blob();
23
24	//! \brief Constructor.
25	Blob(const uint8_t * data, unsigned length);
26
27	//! \brief Copy constructor.
28	Blob(const Blob & other);
29
30	//! \brief Destructor.
31	virtual ~Blob();
32
33	//! \name Operations
34	//@{
35	//! \brief Replaces the blob's data.
36	void setData(const uint8_t * data, unsigned length);
37
38	//! \brief Change the size of the blob's data.
39	void setLength(unsigned length);
40
41	//! \brief Adds data to the end of the blob.
42	void append(const uint8_t * newData, unsigned newDataLength);
43
44	//! \brief Disposes of the data.
45	void clear();
46
47	//! \brief Tell the blob that it no longer owns its data.
48	void relinquish();
49	//@}
50
51	//! \name Accessors
52	//@{
53	uint8_t * getData() { return m_data; }
54	const uint8_t * getData() const { return m_data; }
55	unsigned getLength() const { return m_length; }
56	//@}
57
58	//! \name Operators
59	//@{
60	operator uint8_t * () { return m_data; }
61	operator const uint8_t * () const { return m_data; }
62	//@}
63
64protected:
65	uint8_t * m_data;	//!< The binary data held by this object.
66	unsigned m_length;	//!< Number of bytes pointed to by #m_data.
67};
68
69#endif // _Blob_h_
70
71