GNet::LineBuffer Class Reference

A class which does line buffering. More...

#include <glinebuffer.h>

List of all members.

Public Member Functions

 LineBuffer (const std::string &eol=std::string("\n"), bool do_throw_on_overflow=false)
 Constructor.
void add (const std::string &segment)
 Adds a data segment.
void add (const char *p, std::string::size_type n)
 Adds a data segment.
bool more () const
 Returns true if there are complete line(s) to be extracted.
const std::string & current () const
 Returns the current line, without extracting it.
void discard ()
 Discards the current line.
std::string line ()
 Extracts a line and returns it as a string.

Friends

class LineBufferIterator


Detailed Description

A class which does line buffering.

Raw data is added, and newline-delimited lines are extracted. Usage:

 {
   GNet::LineBuffer buffer ;
   buffer.add("abc") ;
   buffer.add("def\nABC\nDE") ;
   buffer.add("F\n") ;
   while( buffer.more() )
     cout << buffer.line() << endl ;
 }

Definition at line 52 of file glinebuffer.h.


Constructor & Destructor Documentation

GNet::LineBuffer::LineBuffer ( const std::string &  eol = std::string("\n"),
bool  do_throw_on_overflow = false 
) [explicit]

Constructor.

Definition at line 30 of file glinebuffer.cpp.

References G_ASSERT.


Member Function Documentation

void GNet::LineBuffer::add ( const std::string &  segment  ) 

Adds a data segment.

Definition at line 63 of file glinebuffer.cpp.

Referenced by GNet::ResolverImp::onData(), GNet::Client::onData(), and GNet::BufferedServerPeer::onData().

void GNet::LineBuffer::add ( const char *  p,
std::string::size_type  n 
)

Adds a data segment.

Definition at line 55 of file glinebuffer.cpp.

References G_ASSERT.

bool GNet::LineBuffer::more (  )  const

Returns true if there are complete line(s) to be extracted.

Definition at line 99 of file glinebuffer.cpp.

Referenced by GNet::Client::clearInput(), GNet::ResolverImp::onData(), and GNet::Client::onData().

const std::string & GNet::LineBuffer::current (  )  const

Returns the current line, without extracting it.

The line terminator is not included.

Precondition: more()

Definition at line 104 of file glinebuffer.cpp.

References G_ASSERT, m_current, and m_current_valid.

Referenced by line().

void GNet::LineBuffer::discard (  ) 

Discards the current line.

Precondition: more()

Definition at line 118 of file glinebuffer.cpp.

References G_ASSERT.

Referenced by GNet::Client::clearInput(), and line().

std::string GNet::LineBuffer::line (  ) 

Extracts a line and returns it as a string.

The line terminator is not included.

Definition at line 129 of file glinebuffer.cpp.

References current(), discard(), and s.

Referenced by GNet::ResolverImp::onData(), and GNet::Client::onData().


Friends And Related Function Documentation

friend class LineBufferIterator [friend]

Definition at line 86 of file glinebuffer.h.


The documentation for this class was generated from the following files:

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5