File: GetLine.h

package info (click to toggle)
boxbackup 0.13~~git20221201.g166b3fa-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,172 kB
  • sloc: xml: 70,723; cpp: 55,456; ansic: 24,659; perl: 4,844; sh: 4,294; makefile: 588; python: 311
file content (67 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download | duplicates (4)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// --------------------------------------------------------------------------
//
// File
//		Name:    GetLine.h
//		Purpose: Common base class for line based file descriptor reading
//		Created: 2011/04/22
//
// --------------------------------------------------------------------------

#ifndef GETLINE__H
#define GETLINE__H

#include <string>

#ifdef BOX_RELEASE_BUILD
	#define GETLINE_BUFFER_SIZE		1024
#elif defined WIN32
	// need enough space for at least one unicode character 
	// in UTF-8 when calling console_read() from bbackupquery
	#define GETLINE_BUFFER_SIZE		5
#else
	#define GETLINE_BUFFER_SIZE		4
#endif

// Just a very large upper bound for line size to avoid
// people sending lots of data over sockets and causing memory problems.
#define GETLINE_MAX_LINE_SIZE			(1024*256)

// --------------------------------------------------------------------------
//
// Class
//		Name:    GetLine
//		Purpose: Common base class for line based file descriptor reading
//		Created: 2011/04/22
//
// --------------------------------------------------------------------------
class GetLine
{
protected:
	GetLine();

private:
	GetLine(const GetLine &rToCopy);

public:
	virtual bool IsEOF() {return mEOF;}
	int GetLineNumber() {return mLineNumber;}
	virtual ~GetLine() { }
	
protected:
	bool GetLineInternal(std::string &rOutput,
		bool Preprocess = false,
		int Timeout = IOStream::TimeOutInfinite);
	virtual int ReadMore(int Timeout = IOStream::TimeOutInfinite) = 0;
	virtual bool IsStreamDataLeft() = 0;

	char mBuffer[GETLINE_BUFFER_SIZE];
	int mLineNumber;
	int mBufferBegin;
	int mBytesInBuffer;
	bool mPendingEOF;
	std::string mPendingString;
	bool mEOF;
};

#endif // GETLINE__H