membuf.h

来自「一个开源的嵌入式flash播放器的源代码」· C头文件 代码 · 共 65 行

H
65
字号
// membuf.h	-- Thatcher Ulrich 2005

// This source code has been donated to the Public Domain.  Do
// whatever you want with it.

// A simple memory buffer.  Similar to a string, but can hold null
// characters.


#ifndef MEMBUF_H
#define MEMBUF_H


#include "base/tu_config.h"
#include "base/utility.h"

class tu_string;


struct membuf
{
	membuf();
	membuf(const void* data, int size);
	membuf(const membuf& buf);
	membuf(const tu_string& str);
	~membuf();

	// Construct a read-only membuf that points at the given data,
	// instead of copying it.
	enum read_only_enum { READ_ONLY };
	membuf(read_only_enum e, const void* data, int size);

	int size() const { return m_size; }
	const void* data() const { return m_data; }
	void* data() { assert(!m_read_only); return m_data; }

	// Don't call these mutators on read-only membufs.
	
	// Return false if we couldn't resize (i.e. realloc failure).
	bool resize(int new_size);

	// Return false on realloc failure.
	bool append(const void* data, int size);
	bool append(const membuf& buf);
	// We do not append the terminating '\0'.
	bool append(const tu_string& str);

private:
	int m_size;
	int m_capacity;
	void* m_data;
	bool m_read_only;
};


#endif // MEMBUF_H


// Local Variables:
// mode: C++
// c-basic-offset: 8 
// tab-width: 8
// indent-tabs-mode: t
// End:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?