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
T pptr (T... args)
 
T epptr (T... args)
 
T eback (T... args)
 
T setp (T... args)
 
T sputbackc (T... args)
 
T getloc (T... args)
 
T seekoff (T... args)
 
T pubseekoff (T... args)
 
T sungetc (T... args)
 
T sync (T... args)
 
T xsputn (T... args)
 
T pbase (T... args)
 
T sgetc (T... args)
 
T pubimbue (T... args)
 
T showmanyc (T... args)
 
T egptr (T... args)
 
T seekpos (T... args)
 
T underflow (T... args)
 
T setbuf (T... args)
 
T gbump (T... args)
 
T in_avail (T... args)
 
T swap (T... args)
 
T basic_streambuf (T... args)
 
T pbackfail (T... args)
 
T sputc (T... args)
 
T xsgetn (T... args)
 
T uflow (T... args)
 
T overflow (T... args)
 
T sputn (T... args)
 
T sgetn (T... args)
 
T sbumpc (T... args)
 
T operator= (T... args)
 
T pbump (T... args)
 
T pubsetbuf (T... args)
 
T pubsync (T... args)
 
T imbue (T... args)
 
T setg (T... args)
 
T snextc (T... args)
 
T gptr (T... args)
 
T pubseekpos (T... args)
 
T ~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: