- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Friends | List of all members
GNet::LineBuffer Class Reference

A class which does line buffering. More...

`#include <glinebuffer.h>`

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

## 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.

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.

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.

void GNet::LineBuffer::discard | ( |  | ) |

Discards the current line.

Precondition: more()

Definition at line 118 of file glinebuffer.cpp.

References G_ASSERT.

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.

bool GNet::LineBuffer::more | ( |  | ) | const

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

Definition at line 99 of file glinebuffer.cpp.

## 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:

- glinebuffer.h
- glinebuffer.cpp