www.pudn.com > NETINFO.rar > CollectLine.h


#ifndef _COLLECTLINE_H_ 
#define _COLLECTLINE_H_ 
//this class is used to parse CRLF seperated data to individual lines 
//usage like this: 
//  if( object.PutData(data,length) ) 
//  { 
//		while(object.GetLine(line, lineLen, &writelen)) 
//		{ 
//			process a line...... 
//		} 
//      if( writelen >= lineLen ) 
//      { 
//          lineLen is too small to hold a line 
//      } 
//  } 
 
 
 
#define DEFAULT_COLLECT_LINE_BUFFER_SIZE 5000 
class CCollectLine 
{ 
public: 
	CCollectLine(int bufferSize = DEFAULT_COLLECT_LINE_BUFFER_SIZE); 
	~CCollectLine(); 
	BOOL PutData(const char* pData, int length); 
	//length is size of pData, *write include ending CRLF and NULL (3 chars) 
	BOOL GetLine(char* pData, int length, int* write, BOOL bWithCRLF = TRUE); 
	//get size of valid data in buffer 
	int GetCount()const {return m_count;}; 
	const char* GetRemainStart()const {return m_buffer+m_start;}; 
	void ResetContent(); 
private: 
	char* m_buffer; 
	int m_bufferSize; 
	int m_count, m_start; 
}; 
 
 
#endif