libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
dl::utils::basic_pipebuf< CharT, Traits, Allocator > Class Template Reference
Inheritance diagram for dl::utils::basic_pipebuf< CharT, Traits, Allocator >:
Collaboration diagram for dl::utils::basic_pipebuf< CharT, Traits, Allocator >:

Public Member Functions

 basic_pipebuf (const basic_pipebuf &other)=default
 
 basic_pipebuf (basic_pipebuf &&other)=delete
 
 basic_pipebuf (size_t bufsize=1024)
 
bool is_open () const noexcept
 
basic_pipebuf< CharT, Traits, Allocator > * close () noexcept
 
int_type underflow () override
 
int_type overflow (int_type c=Traits::eof()) override
 
- Public Member Functions inherited from std::basic_streambuf
pptr (T... args)
 
epptr (T... args)
 
eback (T... args)
 
setp (T... args)
 
sputbackc (T... args)
 
getloc (T... args)
 
seekoff (T... args)
 
pubseekoff (T... args)
 
sungetc (T... args)
 
sync (T... args)
 
xsputn (T... args)
 
pbase (T... args)
 
sgetc (T... args)
 
pubimbue (T... args)
 
showmanyc (T... args)
 
egptr (T... args)
 
seekpos (T... args)
 
underflow (T... args)
 
setbuf (T... args)
 
gbump (T... args)
 
in_avail (T... args)
 
swap (T... args)
 
basic_streambuf (T... args)
 
pbackfail (T... args)
 
sputc (T... args)
 
xsgetn (T... args)
 
uflow (T... args)
 
overflow (T... args)
 
sputn (T... args)
 
sgetn (T... args)
 
sbumpc (T... args)
 
operator= (T... args)
 
pbump (T... args)
 
pubsetbuf (T... args)
 
pubsync (T... args)
 
imbue (T... args)
 
setg (T... args)
 
snextc (T... args)
 
gptr (T... args)
 
pubseekpos (T... args)
 
~basic_streambuf (T... args)
 

Detailed Description

template<class CharT, class Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT>>
class dl::utils::basic_pipebuf< CharT, Traits, Allocator >

Definition at line 11 of file pipe.hpp.

Constructor & Destructor Documentation

◆ basic_pipebuf()

template<class CharT , class Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT>>
dl::utils::basic_pipebuf< CharT, Traits, Allocator >::basic_pipebuf ( size_t  bufsize = 1024)
inline

Definition at line 25 of file pipe.hpp.

25 : readbuf(bufsize), writebuf(bufsize) {
26 // Read Pointers are all at the end of the buffer
27 this->setg(readbuf.data(), readbuf.data() + readbuf.size(), readbuf.data() + readbuf.size());
28 // Set write buffer to whole buffer
29 this->setp(writebuf.data(), writebuf.data() + writebuf.size());
30 }

◆ ~basic_pipebuf()

template<class CharT , class Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT>>
dl::utils::basic_pipebuf< CharT, Traits, Allocator >::~basic_pipebuf ( )
inline

Definition at line 31 of file pipe.hpp.

31 {
32 if (basic_pipebuf::is_open())
33 basic_pipebuf::overflow(Traits::eof());
34 }

Member Function Documentation

◆ close()

template<class CharT , class Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT>>
basic_pipebuf< CharT, Traits, Allocator > * dl::utils::basic_pipebuf< CharT, Traits, Allocator >::close ( )
inlinenoexcept

Definition at line 38 of file pipe.hpp.

38 {
39 if (!is_open())
40 return nullptr;
41 overflow(Traits::eof()); // Will close the writer
42 return this;
43 }

◆ is_open()

template<class CharT , class Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT>>
bool dl::utils::basic_pipebuf< CharT, Traits, Allocator >::is_open ( ) const
inlinenoexcept

Definition at line 36 of file pipe.hpp.

36{ return !writerClosed; }

◆ overflow()

template<class CharT , class Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT>>
int_type dl::utils::basic_pipebuf< CharT, Traits, Allocator >::overflow ( int_type  c = Traits::eof())
inlineoverride

Definition at line 62 of file pipe.hpp.

62 {
63 if (c == Traits::eof())
64 writerClosed = true;
65 barrier.arrive_and_wait();
66 // Reader will switch buffers and update *Closed flags
67 barrier.arrive_and_wait();
68 if (writerClosed)
69 return (c == Traits::eof()) ? 1 : Traits::eof();
70 // Reset Pointers
71 this->setp(writebuf.data(), writebuf.data() + writebuf.size());
72 *this->pptr() = c;
73 this->pbump(1);
74 return c;
75 }
T pbump(T... args)

◆ underflow()

template<class CharT , class Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT>>
int_type dl::utils::basic_pipebuf< CharT, Traits, Allocator >::underflow ( )
inlineoverride

Definition at line 45 of file pipe.hpp.

45 {
46 if (readerClosed)
47 return Traits::eof();
48 barrier.arrive_and_wait();
49 // Swap buffers
50 std::swap(readbuf, writebuf);
51 writerClosed = readerClosed = readerClosed || writerClosed;
52 numLastWritten = this->pptr() - this->pbase();
53 assert(numLastWritten <= readbuf.size());
54 barrier.arrive_and_wait();
55 if (readerClosed && numLastWritten == 0) // Reader was freshly closed and no new data was given
56 return Traits::eof();
57 // Reset Pointer
58 this->setg(readbuf.data(), readbuf.data(), readbuf.data() + numLastWritten);
59 return Traits::to_int_type(*this->gptr());
60 }
T swap(T... args)

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