DNA Calib 1.1
Project brief
Public Types | Public Member Functions | Private Attributes | List of all members
terse::CharOutputStreamBuf< TStream, BufferSize > Class Template Reference

#include <CharOutputStreamBuf.h>

Inheritance diagram for terse::CharOutputStreamBuf< TStream, BufferSize >:
Inheritance graph
Collaboration diagram for terse::CharOutputStreamBuf< TStream, BufferSize >:
Collaboration graph

Public Types

using PosType = std::streambuf::pos_type
 
using OffType = std::streambuf::off_type
 
using CharType = std::streambuf::char_type
 
using IntType = std::streambuf::int_type
 
using TraitsType = std::streambuf::traits_type
 

Public Member Functions

 CharOutputStreamBuf (TStream *stream_)
 
 ~CharOutputStreamBuf ()
 
std::streamsize xsputn (const CharType *source, std::streamsize size) override
 
IntType overflow (IntType value) override
 
IntType sync () override
 

Private Attributes

TStream * stream
 
std::array< char, BufferSize > buffer
 

Member Typedef Documentation

◆ CharType

template<class TStream , std::size_t BufferSize = 4096ul>
using terse::CharOutputStreamBuf< TStream, BufferSize >::CharType = std::streambuf::char_type

◆ IntType

template<class TStream , std::size_t BufferSize = 4096ul>
using terse::CharOutputStreamBuf< TStream, BufferSize >::IntType = std::streambuf::int_type

◆ OffType

template<class TStream , std::size_t BufferSize = 4096ul>
using terse::CharOutputStreamBuf< TStream, BufferSize >::OffType = std::streambuf::off_type

◆ PosType

template<class TStream , std::size_t BufferSize = 4096ul>
using terse::CharOutputStreamBuf< TStream, BufferSize >::PosType = std::streambuf::pos_type

◆ TraitsType

template<class TStream , std::size_t BufferSize = 4096ul>
using terse::CharOutputStreamBuf< TStream, BufferSize >::TraitsType = std::streambuf::traits_type

Constructor & Destructor Documentation

◆ CharOutputStreamBuf()

template<class TStream , std::size_t BufferSize = 4096ul>
terse::CharOutputStreamBuf< TStream, BufferSize >::CharOutputStreamBuf ( TStream *  stream_)
inlineexplicit
27 : stream{stream_}, buffer{} {
28 setp(buffer.data(), buffer.data() + buffer.size() - 1ul);
29 }
std::array< char, BufferSize > buffer
Definition: CharOutputStreamBuf.h:81
TStream * stream
Definition: CharOutputStreamBuf.h:80

References terse::CharOutputStreamBuf< TStream, BufferSize >::buffer.

◆ ~CharOutputStreamBuf()

template<class TStream , std::size_t BufferSize = 4096ul>
terse::CharOutputStreamBuf< TStream, BufferSize >::~CharOutputStreamBuf ( )
inline
31 {
32 sync();
33 }
IntType sync() override
Definition: CharOutputStreamBuf.h:68

References terse::CharOutputStreamBuf< TStream, BufferSize >::sync().

Member Function Documentation

◆ overflow()

template<class TStream , std::size_t BufferSize = 4096ul>
IntType terse::CharOutputStreamBuf< TStream, BufferSize >::overflow ( IntType  value)
inlineoverride
56 {
57 // Write a single character
58 if (value == TraitsType::eof()) {
59 return value;
60 }
61
62 const CharType data = static_cast<CharType>(value);
63 *pptr() = data;
64 pbump(1);
65 return (sync() ? TraitsType::eof() : value);
66 }
std::streambuf::char_type CharType
Definition: CharOutputStreamBuf.h:22

References terse::CharOutputStreamBuf< TStream, BufferSize >::sync().

◆ sync()

template<class TStream , std::size_t BufferSize = 4096ul>
IntType terse::CharOutputStreamBuf< TStream, BufferSize >::sync ( )
inlineoverride
68 {
69 const std::ptrdiff_t diff = pptr() - pbase();
70 if (diff > 0) {
71 const std::size_t bytesToWrite = static_cast<std::size_t>(diff);
72 const std::size_t bytesWritten = stream->write(buffer.data(), bytesToWrite);
73 pbump(static_cast<IntType>(-diff));
74 return (bytesToWrite == bytesWritten ? 0 : -1);
75 }
76 return 0;
77 }
std::streambuf::int_type IntType
Definition: CharOutputStreamBuf.h:23

References terse::CharOutputStreamBuf< TStream, BufferSize >::buffer, and terse::CharOutputStreamBuf< TStream, BufferSize >::stream.

Referenced by terse::CharOutputStreamBuf< TStream, BufferSize >::overflow(), terse::CharOutputStreamBuf< TStream, BufferSize >::xsputn(), and terse::CharOutputStreamBuf< TStream, BufferSize >::~CharOutputStreamBuf().

◆ xsputn()

template<class TStream , std::size_t BufferSize = 4096ul>
std::streamsize terse::CharOutputStreamBuf< TStream, BufferSize >::xsputn ( const CharType source,
std::streamsize  size 
)
inlineoverride
35 {
36 // Write a sequence of characters
37 if (size <= 0) {
38 return 0;
39 }
40
41 // If there's space, write data into buffer
42 const std::ptrdiff_t spaceLeft = epptr() - pptr();
43 if (size < spaceLeft) {
44 std::memcpy(pptr(), source, static_cast<std::size_t>(size));
45 pbump(static_cast<IntType>(size));
46 return size;
47 }
48
49 // No space in buffer, flush it first, and write directly into stream
50 if (sync()) {
51 return 0;
52 }
53 return static_cast<std::streamsize>(stream->write(source, static_cast<std::size_t>(size)));
54 }

References terse::CharOutputStreamBuf< TStream, BufferSize >::stream, and terse::CharOutputStreamBuf< TStream, BufferSize >::sync().

Member Data Documentation

◆ buffer

template<class TStream , std::size_t BufferSize = 4096ul>
std::array<char, BufferSize> terse::CharOutputStreamBuf< TStream, BufferSize >::buffer
private

◆ stream

template<class TStream , std::size_t BufferSize = 4096ul>
TStream* terse::CharOutputStreamBuf< TStream, BufferSize >::stream
private

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