VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GNet::LineBuffer Class Reference

A class which does line buffering. More...

#include <glinebuffer.h>

Public Member Functions

 LineBuffer ()
 Default constructor for a line buffer that auto-detects either CR or CR-LF line endings based on the first line. More...
 
 LineBuffer (const std::string &eol, bool do_throw_on_overflow=false)
 Constructor. More...
 
void add (const std::string &segment)
 Adds a data segment.
 
void add (const char *p, std::string::size_type n)
 Adds a data segment.
 
const std::string & eol () const
 Returns the line-ending.
 
void expect (size_t n)
 The next 'n' bytes added and/or extracted are treated as a complete line. More...
 

Friends

class LineBufferIterator
 

Detailed Description

A class which does line buffering.

Raw data is added, and newline-delimited lines are extracted via an iterator.

Usage:

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

Definition at line 52 of file glinebuffer.h.

Constructor & Destructor Documentation

GNet::LineBuffer::LineBuffer ( )

Default constructor for a line buffer that auto-detects either CR or CR-LF line endings based on the first line.

Definition at line 30 of file glinebuffer.cpp.

GNet::LineBuffer::LineBuffer ( const std::string &  eol,
bool  do_throw_on_overflow = false 
)
explicit

Constructor.

The default is to not throw on overflow because the very large overflow limit is only intended to be protection against a rogue client or a denial-of-service attack.

Definition at line 39 of file glinebuffer.cpp.

Member Function Documentation

void GNet::LineBuffer::expect ( size_t  n)

The next 'n' bytes added and/or extracted are treated as a complete line.

This is useful for binary chunks of known size surrounded by text, as in http.

Definition at line 84 of file glinebuffer.cpp.


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