示例#1
0
const void*
StreamBuffer::peek(UInt32 n)
{
	assert(n <= m_size);

	// if requesting no data then return NULL so we don't try to access
	// an empty list.
	if (n == 0) {
		return NULL;
	}

	// reserve space in first chunk
	ChunkList::iterator head = m_chunks.begin();
	head->reserve(n + m_headUsed);

	// consolidate chunks into the first chunk until it has n bytes
	ChunkList::iterator scan = head;
	++scan;
	while (head->size() - m_headUsed < n && scan != m_chunks.end()) {
		head->insert(head->end(), scan->begin(), scan->end());
		scan = m_chunks.erase(scan);
	}

	return reinterpret_cast<const void*>(&(head->begin()[m_headUsed]));
}