File: Buffer.cpp

package info (click to toggle)
znc 0.045-3%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,120 kB
  • ctags: 2,324
  • sloc: cpp: 17,406; sh: 2,380; perl: 448; makefile: 134
file content (52 lines) | stat: -rw-r--r-- 925 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Buffer.h"

CBufLine::CBufLine(const CString& sPre, const CString& sPost) {
	m_sPre = sPre;
	m_sPost = sPost;
}

CBufLine::~CBufLine() {}

void CBufLine::GetLine(const CString& sTarget, CString& sRet) {
	sRet = m_sPre + sTarget + m_sPost;
}

CBuffer::CBuffer(unsigned int uLineCount) {
	m_uLineCount = uLineCount;
}

CBuffer::~CBuffer() {}

int CBuffer::AddLine(const CString& sPre, const CString& sPost) {
	if (!m_uLineCount) {
		return 0;
	}

	if (size() >= m_uLineCount) {
		erase(begin());
	}

	push_back(CBufLine(sPre, sPost));
	return size();
}

bool CBuffer::GetLine(const CString& sTarget, CString& sRet, unsigned int uIdx) {
	if (uIdx >= size()) {
		return false;
	}

	(*this)[uIdx].GetLine(sTarget, sRet);
	return true;
}

bool CBuffer::GetNextLine(const CString& sTarget, CString& sRet) {
	sRet = "";

	if (!size()) {
		return false;
	}

	begin()->GetLine(sTarget, sRet);
	erase(begin());
	return true;
}