Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xstream::base64::ostreambuf Class Reference

Base64 encode stream class. More...

#include <base64.h>

+ Inheritance diagram for xstream::base64::ostreambuf:

Public Member Functions

 ostreambuf (std::streambuf *sb, unsigned int width=76, char delimiter='\n')
 construct using a streambuf More...
 
 ~ostreambuf ()
 closes the base64 stream More...
 

Protected Member Functions

std::streamsize available () const
 remaining characters in the buffer More...
 
std::streamsize taken () const
 number of characters in the buffer More...
 

Private Member Functions

int sync ()
 flush as much data as possible (overloaded from streambuf) More...
 
int overflow (int c)
 write a character that surpasses buffer end (overloaded from streambuf) More...
 
void reset ()
 reset input buffer More...
 
int write (const char *buf, size_t len)
 Takes care of inserting delimiters every delim_w characters. More...
 

Private Attributes

std::streambuf * _sb
 
char delim
 
unsigned int delim_w
 
unsigned int col
 
char buf [3]
 

Detailed Description

Base64 encode stream class.

encodes data to base64 and writes it to another streambuf

Todo:
no xsputn support yet and flush doesn't flush partial data, for example suppose you wrote 2 bytes of a 3 byte chunk, it's possible to know the first 2 characters of the encoded data, but these are not flushed

Definition at line 31 of file base64.h.

Constructor & Destructor Documentation

xstream::base64::ostreambuf::ostreambuf ( std::streambuf *  sb,
unsigned int  width = 76,
char  delimiter = '\n' 
)

construct using a streambuf

Parameters
sbstreambuf where to write the encoded data
widthwidth in bytes of lines (=0 for unlimited lines)
delimiterchar to delimit the lines

the same parameters need to be used when decoding or it will throw an exception indicating invalid data width=76 and delim=newline are default because they are the values in the RFC

Definition at line 16 of file base64.cpp.

References LOG, and reset().

xstream::base64::ostreambuf::~ostreambuf ( )

closes the base64 stream

Definition at line 85 of file base64.cpp.

References _sb, xstream::ostreambuf::available(), buf, xstream::base64::encode(), LOG, and write().

Member Function Documentation

std::streamsize xstream::ostreambuf::available ( ) const
inlineprotectedinherited

remaining characters in the buffer

Definition at line 28 of file common.h.

Referenced by ~ostreambuf().

int xstream::base64::ostreambuf::overflow ( int  c)
private

write a character that surpasses buffer end (overloaded from streambuf)

Definition at line 71 of file base64.cpp.

References buf, c, xstream::base64::encode(), LOG, and write().

void xstream::base64::ostreambuf::reset ( )
private

reset input buffer

Definition at line 22 of file base64.cpp.

References buf, and LOG.

Referenced by ostreambuf(), and write().

int xstream::base64::ostreambuf::sync ( )
private

flush as much data as possible (overloaded from streambuf)

Definition at line 28 of file base64.cpp.

References _sb, and LOG.

std::streamsize xstream::ostreambuf::taken ( ) const
inlineprotectedinherited

number of characters in the buffer

Definition at line 36 of file common.h.

Referenced by xstream::digest::stream::xsputn().

int xstream::base64::ostreambuf::write ( const char *  buf,
size_t  len 
)
private

Takes care of inserting delimiters every delim_w characters.

Definition at line 48 of file base64.cpp.

References _sb, col, delim, delim_w, LOG, and reset().

Referenced by overflow(), and ~ostreambuf().

Member Data Documentation

std::streambuf* xstream::base64::ostreambuf::_sb
private

Definition at line 35 of file base64.h.

Referenced by sync(), write(), and ~ostreambuf().

char xstream::base64::ostreambuf::buf[3]
private

buffer to store non encoded data

Definition at line 40 of file base64.h.

Referenced by overflow(), reset(), and ~ostreambuf().

unsigned int xstream::base64::ostreambuf::col
private

Definition at line 38 of file base64.h.

Referenced by write().

char xstream::base64::ostreambuf::delim
private

Definition at line 36 of file base64.h.

Referenced by write().

unsigned int xstream::base64::ostreambuf::delim_w
private

Definition at line 37 of file base64.h.

Referenced by write().


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