E-MailRelay
Public Member Functions | List of all members
GNet::LineStore Class Reference

A pair of character buffers, one kept by value and the other being an ephemeral extension. More...

#include <glinestore.h>

Public Member Functions

 LineStore ()
 Default constructor.
 
void append (const std::string &)
 Appends to the store (by copying). More...
 
void append (const char *, std::size_t)
 Appends to the store (by copying). More...
 
void extend (const char *, std::size_t)
 Sets the extension. More...
 
void discard (std::size_t n)
 Discards the first 'n' bytes and consolidates the residue. More...
 
void consolidate ()
 Consolidates the extension into the store. More...
 
void clear ()
 Clears all data. More...
 
std::size_t size () const
 Returns the overall size. More...
 
bool empty () const
 Returns true if size() is zero. More...
 
std::size_t find (char c, std::size_t startpos=0U) const
 Finds the given character. More...
 
std::size_t find (const std::string &s, std::size_t startpos=0U) const
 Finds the given sub-string. More...
 
std::size_t findSubStringAtEnd (const std::string &s, std::size_t startpos=0U) const
 Finds a non-empty leading substring 's' that appears at the end of the data. More...
 
const char * data (std::size_t pos, std::size_t size) const
 Returns a pointer for the data at the given position that is contiguous for the given size. More...
 
char at (std::size_t n) const
 Returns the n'th character. More...
 
std::string str () const
 Returns the complete string. More...
 
std::string head (std::size_t n) const
 Returns the leading sub-string of str() of up to 'n' characters. More...
 
 LineStore (const LineStore &)=delete
 
 LineStore (LineStore &&)=delete
 
void operator= (const LineStore &)=delete
 
void operator= (LineStore &&)=delete
 

Detailed Description

A pair of character buffers, one kept by value and the other being an ephemeral extension.

An iterator class can iterate over the combined data. Used in the implementation of GNet::LineBuffer as a zero-copy optimisation.

Definition at line 41 of file glinestore.h.

Member Function Documentation

◆ append() [1/2]

void GNet::LineStore::append ( const char *  data,
std::size_t  size 
)

Appends to the store (by copying).

Any existing extension is first consolidate()d.

Definition at line 209 of file glinestore.cpp.

◆ append() [2/2]

void GNet::LineStore::append ( const std::string &  s)

Appends to the store (by copying).

Any existing extension is first consolidate()d.

Definition at line 203 of file glinestore.cpp.

◆ at()

char GNet::LineStore::at ( std::size_t  n) const
inline

Returns the n'th character.

Definition at line 124 of file glinestore.h.

◆ clear()

void GNet::LineStore::clear ( )

Clears all data.

Definition at line 222 of file glinestore.cpp.

◆ consolidate()

void GNet::LineStore::consolidate ( )

Consolidates the extension into the store.

Definition at line 228 of file glinestore.cpp.

◆ data()

const char * GNet::LineStore::data ( std::size_t  pos,
std::size_t  size 
) const

Returns a pointer for the data at the given position that is contiguous for the given size.

Data is shuffled around as required, which means that previous pointers are invalidated.

Definition at line 374 of file glinestore.cpp.

◆ discard()

void GNet::LineStore::discard ( std::size_t  n)

Discards the first 'n' bytes and consolidates the residue.

Definition at line 235 of file glinestore.cpp.

◆ empty()

bool GNet::LineStore::empty ( ) const
inline

Returns true if size() is zero.

Definition at line 137 of file glinestore.h.

◆ extend()

void GNet::LineStore::extend ( const char *  data,
std::size_t  size 
)

Sets the extension.

Any existing extension is consolidated(). Use consolidate(), discard() or clear() before the extension pointer becomes invalid.

Definition at line 215 of file glinestore.cpp.

◆ find() [1/2]

std::size_t GNet::LineStore::find ( char  c,
std::size_t  startpos = 0U 
) const

Finds the given character.

Returns npos if not found.

Definition at line 280 of file glinestore.cpp.

◆ find() [2/2]

std::size_t GNet::LineStore::find ( const std::string &  s,
std::size_t  startpos = 0U 
) const

Finds the given sub-string.

Returns npos if not found.

Definition at line 303 of file glinestore.cpp.

◆ findSubStringAtEnd()

std::size_t GNet::LineStore::findSubStringAtEnd ( const std::string &  s,
std::size_t  startpos = 0U 
) const

Finds a non-empty leading substring 's' that appears at the end of the data.

Returns npos if not found.

Definition at line 342 of file glinestore.cpp.

◆ head()

std::string GNet::LineStore::head ( std::size_t  n) const

Returns the leading sub-string of str() of up to 'n' characters.

Definition at line 417 of file glinestore.cpp.

◆ size()

std::size_t GNet::LineStore::size ( ) const
inline

Returns the overall size.

Definition at line 131 of file glinestore.h.

◆ str()

std::string GNet::LineStore::str ( ) const

Returns the complete string.

Definition at line 409 of file glinestore.cpp.


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