TwiceAsNice  2019-02-18
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | Related Functions | List of all members
Nice::basic_pstreambuf< CharT, Traits > Class Template Reference

Class template for stream buffer. More...

#include <PStream.h>

Inheritance diagram for Nice::basic_pstreambuf< CharT, Traits >:
Inheritance graph
Collaboration diagram for Nice::basic_pstreambuf< CharT, Traits >:
Collaboration graph

Public Types

typedef CharT char_type
 
typedef Traits traits_type
 
typedef traits_type::int_type int_type
 
typedef traits_type::off_type off_type
 
typedef traits_type::pos_type pos_type
 
typedef fd_type fd_t
 
typedef CharT char_type
 
typedef Traits traits_type
 
typedef traits_type::int_type int_type
 
typedef traits_type::off_type off_type
 
typedef traits_type::pos_type pos_type
 
typedef fd_type fd_t
 
- Public Types inherited from Nice::pstreams
typedef std::ios_base::openmode pmode
 Type used to specify how to connect to the process. More...
 
typedef std::vector< std::string > argv_type
 Type used to hold the arguments for a command. More...
 
typedef int fd_type
 Type used for file descriptors. More...
 
typedef std::ios_base::openmode pmode
 Type used to specify how to connect to the process. More...
 
typedef std::vector< std::string > argv_type
 Type used to hold the arguments for a command. More...
 
typedef int fd_type
 Type used for file descriptors. More...
 

Public Member Functions

 basic_pstreambuf ()
 Default constructor. More...
 
 basic_pstreambuf (const std::string &command, pmode mode)
 Constructor that initialises the buffer with command. More...
 
 basic_pstreambuf (const std::string &file, const argv_type &argv, pmode mode)
 Constructor that initialises the buffer with file and argv. More...
 
 ~basic_pstreambuf ()
 Destructor. More...
 
basic_pstreambufopen (const std::string &command, pmode mode)
 Initialise the stream buffer with command. More...
 
basic_pstreambufopen (const std::string &file, const argv_type &argv, pmode mode)
 Initialise the stream buffer with file and argv. More...
 
basic_pstreambufclose ()
 Close the stream buffer and wait for the process to exit. More...
 
basic_pstreambufkill (int signal=SIGTERM)
 Send a signal to the process. More...
 
void peof ()
 Close the pipe connected to the process' stdin. More...
 
bool read_err (bool readerr=true)
 Change active input source. More...
 
bool is_open () const
 Report whether the stream buffer has been initialised. More...
 
bool exited ()
 Report whether the process has exited. More...
 
int status () const
 Return the exit status of the process. More...
 
int error () const
 Return the error number for the most recent failed operation. More...
 
 basic_pstreambuf ()
 Default constructor. More...
 
 basic_pstreambuf (const std::string &command, pmode mode)
 Constructor that initialises the buffer with command. More...
 
 basic_pstreambuf (const std::string &file, const argv_type &argv, pmode mode)
 Constructor that initialises the buffer with file and argv. More...
 
 ~basic_pstreambuf ()
 Destructor. More...
 
basic_pstreambufopen (const std::string &command, pmode mode)
 Initialise the stream buffer with command. More...
 
basic_pstreambufopen (const std::string &file, const argv_type &argv, pmode mode)
 Initialise the stream buffer with file and argv. More...
 
basic_pstreambufclose ()
 Close the stream buffer and wait for the process to exit. More...
 
basic_pstreambufkill (int signal=SIGTERM)
 Send a signal to the process. More...
 
void peof ()
 Close the pipe connected to the process' stdin. More...
 
bool read_err (bool readerr=true)
 Change active input source. More...
 
bool is_open () const
 Report whether the stream buffer has been initialised. More...
 
bool exited ()
 Report whether the process has exited. More...
 
int status () const
 Return the exit status of the process. More...
 
int error () const
 Return the error number for the most recent failed operation. More...
 

Protected Types

enum  buf_read_src { rsrc_out = 0, rsrc_err = 1, rsrc_out = 0, rsrc_err = 1 }
 Enumerated type to indicate whether stdout or stderr is to be read. More...
 
enum  buf_read_src { rsrc_out = 0, rsrc_err = 1, rsrc_out = 0, rsrc_err = 1 }
 Enumerated type to indicate whether stdout or stderr is to be read. More...
 
- Protected Types inherited from Nice::pstreams
enum  { bufsz = 32 }
 
enum  { pbsz = 2 }
 
enum  { bufsz = 32 }
 
enum  { pbsz = 2 }
 

Protected Member Functions

int_type overflow (int_type c)
 Transfer characters to the pipe when character buffer overflows. More...
 
int_type underflow ()
 Transfer characters from the pipe when the character buffer is empty. More...
 
int_type pbackfail (int_type c=traits_type::eof())
 Make a character available to be returned by the next extraction. More...
 
int sync ()
 Write any buffered characters to the stream. More...
 
std::streamsize xsputn (const char_type *s, std::streamsize n)
 Insert multiple characters into the pipe. More...
 
std::streamsize write (const char_type *s, std::streamsize n)
 Insert a sequence of characters into the pipe. More...
 
std::streamsize read (char_type *s, std::streamsize n)
 Extract a sequence of characters from the pipe. More...
 
std::streamsize showmanyc ()
 Report how many characters can be read from active input without blocking. More...
 
pid_t fork (pmode mode)
 Initialise pipes and fork process. More...
 
int wait (bool nohang=false)
 Wait for the child process to exit. More...
 
fd_typewpipe ()
 Return the file descriptor for the output pipe. More...
 
fd_typerpipe ()
 Return the file descriptor for the active input pipe. More...
 
fd_typerpipe (buf_read_src which)
 Return the file descriptor for the specified input pipe. More...
 
void create_buffers (pmode mode)
 
void destroy_buffers (pmode mode)
 
bool empty_buffer ()
 Writes buffered characters to the process' stdin pipe. More...
 
bool fill_buffer ()
 
char_typerbuffer ()
 Return the active input buffer. More...
 
buf_read_src switch_read_buffer (buf_read_src)
 
int_type overflow (int_type c)
 Transfer characters to the pipe when character buffer overflows. More...
 
int_type underflow ()
 Transfer characters from the pipe when the character buffer is empty. More...
 
int_type pbackfail (int_type c=traits_type::eof())
 Make a character available to be returned by the next extraction. More...
 
int sync ()
 Write any buffered characters to the stream. More...
 
std::streamsize xsputn (const char_type *s, std::streamsize n)
 Insert multiple characters into the pipe. More...
 
std::streamsize write (const char_type *s, std::streamsize n)
 Insert a sequence of characters into the pipe. More...
 
std::streamsize read (char_type *s, std::streamsize n)
 Extract a sequence of characters from the pipe. More...
 
std::streamsize showmanyc ()
 Report how many characters can be read from active input without blocking. More...
 
pid_t fork (pmode mode)
 Initialise pipes and fork process. More...
 
int wait (bool nohang=false)
 Wait for the child process to exit. More...
 
fd_typewpipe ()
 Return the file descriptor for the output pipe. More...
 
fd_typerpipe ()
 Return the file descriptor for the active input pipe. More...
 
fd_typerpipe (buf_read_src which)
 Return the file descriptor for the specified input pipe. More...
 
void create_buffers (pmode mode)
 
void destroy_buffers (pmode mode)
 
bool empty_buffer ()
 Writes buffered characters to the process' stdin pipe. More...
 
bool fill_buffer ()
 
char_typerbuffer ()
 Return the active input buffer. More...
 
buf_read_src switch_read_buffer (buf_read_src)
 

Private Member Functions

 basic_pstreambuf (const basic_pstreambuf &)
 
basic_pstreambufoperator= (const basic_pstreambuf &)
 
void init_rbuffers ()
 Called on construction to initialise the arrays used for reading. More...
 
 basic_pstreambuf (const basic_pstreambuf &)
 
basic_pstreambufoperator= (const basic_pstreambuf &)
 
void init_rbuffers ()
 

Private Attributes

pid_t ppid_
 
fd_type wpipe_
 
fd_type rpipe_ [2]
 
char_typewbuffer_
 
char_typerbuffer_ [2]
 
char_typerbufstate_ [3]
 
buf_read_src rsrc_
 Index into rpipe_[] to indicate active source for read operations. More...
 
int status_
 
int error_
 

Related Functions

(Note that these are not member functions.)

void close_fd (pstreams::fd_type &fd)
 Helper function to close a file descriptor. More...
 
template<int N>
void close_fd_array (pstreams::fd_type(&fds) [N])
 Helper function to close an array of file descriptors. More...
 
void close_fd (pstreams::fd_type &fd)
 Helper function to close a file descriptor. More...
 
template<int N>
void close_fd_array (pstreams::fd_type(&fds) [N])
 Helper function to close an array of file descriptors. More...
 

Additional Inherited Members

- Static Public Attributes inherited from Nice::pstreams
static const pmode pstdin = std::ios_base::out
 Write to stdin. More...
 
static const pmode pstdout = std::ios_base::in
 Read from stdout. More...
 
static const pmode pstderr = std::ios_base::app
 Read from stderr. More...
 

Detailed Description

template<typename CharT, typename Traits = std::char_traits<CharT>>
class Nice::basic_pstreambuf< CharT, Traits >

Class template for stream buffer.

Provides underlying streambuf functionality for the PStreams classes.

Member Typedef Documentation

◆ char_type [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef CharT Nice::basic_pstreambuf< CharT, Traits >::char_type

◆ char_type [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef CharT Nice::basic_pstreambuf< CharT, Traits >::char_type

◆ fd_t [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef fd_type Nice::basic_pstreambuf< CharT, Traits >::fd_t

◆ fd_t [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef fd_type Nice::basic_pstreambuf< CharT, Traits >::fd_t

◆ int_type [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef traits_type::int_type Nice::basic_pstreambuf< CharT, Traits >::int_type

◆ int_type [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef traits_type::int_type Nice::basic_pstreambuf< CharT, Traits >::int_type

◆ off_type [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef traits_type::off_type Nice::basic_pstreambuf< CharT, Traits >::off_type

◆ off_type [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef traits_type::off_type Nice::basic_pstreambuf< CharT, Traits >::off_type

◆ pos_type [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef traits_type::pos_type Nice::basic_pstreambuf< CharT, Traits >::pos_type

◆ pos_type [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef traits_type::pos_type Nice::basic_pstreambuf< CharT, Traits >::pos_type

◆ traits_type [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef Traits Nice::basic_pstreambuf< CharT, Traits >::traits_type

◆ traits_type [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
typedef Traits Nice::basic_pstreambuf< CharT, Traits >::traits_type

Member Enumeration Documentation

◆ buf_read_src [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
enum Nice::basic_pstreambuf::buf_read_src
protected

Enumerated type to indicate whether stdout or stderr is to be read.

Enumerator
rsrc_out 
rsrc_err 
rsrc_out 
rsrc_err 

◆ buf_read_src [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
enum Nice::basic_pstreambuf::buf_read_src
protected

Enumerated type to indicate whether stdout or stderr is to be read.

Enumerator
rsrc_out 
rsrc_err 
rsrc_out 
rsrc_err 

Constructor & Destructor Documentation

◆ basic_pstreambuf() [1/8]

template<typename C , typename T >
Nice::basic_pstreambuf< C, T >::basic_pstreambuf ( )
inline

Default constructor.

Creates an uninitialised stream buffer.

◆ basic_pstreambuf() [2/8]

template<typename C , typename T >
Nice::basic_pstreambuf< C, T >::basic_pstreambuf ( const std::string &  command,
pmode  mode 
)
inline

Constructor that initialises the buffer with command.

Initialises the stream buffer by calling open() with the supplied arguments.

Parameters
commanda string containing a shell command.
modethe I/O mode to use when opening the pipe.
See also
open()

◆ basic_pstreambuf() [3/8]

template<typename C , typename T >
Nice::basic_pstreambuf< C, T >::basic_pstreambuf ( const std::string &  file,
const argv_type argv,
pmode  mode 
)
inline

Constructor that initialises the buffer with file and argv.

Initialises the stream buffer by calling open() with the supplied arguments.

Parameters
filea string containing the name of a program to execute.
argva vector of argument strings passsed to the new program.
modethe I/O mode to use when opening the pipe.
See also
open()

◆ ~basic_pstreambuf() [1/2]

template<typename C , typename T >
Nice::basic_pstreambuf< C, T >::~basic_pstreambuf ( )
inline

Destructor.

Closes the stream by calling close().

See also
close()

◆ basic_pstreambuf() [4/8]

template<typename CharT , typename Traits = std::char_traits<CharT>>
Nice::basic_pstreambuf< CharT, Traits >::basic_pstreambuf ( const basic_pstreambuf< CharT, Traits > &  )
private

◆ basic_pstreambuf() [5/8]

template<typename CharT , typename Traits = std::char_traits<CharT>>
Nice::basic_pstreambuf< CharT, Traits >::basic_pstreambuf ( )

Default constructor.

◆ basic_pstreambuf() [6/8]

template<typename CharT , typename Traits = std::char_traits<CharT>>
Nice::basic_pstreambuf< CharT, Traits >::basic_pstreambuf ( const std::string &  command,
pmode  mode 
)

Constructor that initialises the buffer with command.

◆ basic_pstreambuf() [7/8]

template<typename CharT , typename Traits = std::char_traits<CharT>>
Nice::basic_pstreambuf< CharT, Traits >::basic_pstreambuf ( const std::string &  file,
const argv_type argv,
pmode  mode 
)

Constructor that initialises the buffer with file and argv.

◆ ~basic_pstreambuf() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
Nice::basic_pstreambuf< CharT, Traits >::~basic_pstreambuf ( )

Destructor.

◆ basic_pstreambuf() [8/8]

template<typename CharT , typename Traits = std::char_traits<CharT>>
Nice::basic_pstreambuf< CharT, Traits >::basic_pstreambuf ( const basic_pstreambuf< CharT, Traits > &  )
private

Member Function Documentation

◆ close() [1/2]

template<typename C , typename T >
basic_pstreambuf< C, T > * Nice::basic_pstreambuf< C, T >::close ( void  )

Close the stream buffer and wait for the process to exit.

Closes all pipes and calls wait() to wait for the process to finish.

If an error occurs the error code will be set to one of the possible errors for waitpid(). See your system's documentation for these errors.

Returns
this on successful close or NULL if there is no process to close or if an error occurs.

◆ close() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_pstreambuf* Nice::basic_pstreambuf< CharT, Traits >::close ( )

Close the stream buffer and wait for the process to exit.

◆ create_buffers() [1/2]

template<typename C , typename T >
void Nice::basic_pstreambuf< C, T >::create_buffers ( pmode  mode)
protected

◆ create_buffers() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
void Nice::basic_pstreambuf< CharT, Traits >::create_buffers ( pmode  mode)
protected

◆ destroy_buffers() [1/2]

template<typename C , typename T >
void Nice::basic_pstreambuf< C, T >::destroy_buffers ( pmode  mode)
protected

◆ destroy_buffers() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
void Nice::basic_pstreambuf< CharT, Traits >::destroy_buffers ( pmode  mode)
protected

◆ empty_buffer() [1/2]

template<typename C , typename T >
bool Nice::basic_pstreambuf< C, T >::empty_buffer ( )
protected

Writes buffered characters to the process' stdin pipe.

Returns
true if the buffer was emptied, false otherwise.

◆ empty_buffer() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool Nice::basic_pstreambuf< CharT, Traits >::empty_buffer ( )
protected

Writes buffered characters to the process' stdin pipe.

◆ error() [1/2]

template<typename C , typename T >
int Nice::basic_pstreambuf< C, T >::error ( ) const
inline

Return the error number for the most recent failed operation.

Returns
The error code of the most recently failed operation, or zero.

◆ error() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
int Nice::basic_pstreambuf< CharT, Traits >::error ( ) const

Return the error number for the most recent failed operation.

◆ exited() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool Nice::basic_pstreambuf< CharT, Traits >::exited ( )

Report whether the process has exited.

◆ exited() [2/2]

template<typename C , typename T >
bool Nice::basic_pstreambuf< C, T >::exited ( )
inline

Report whether the process has exited.

Returns
True if the associated process has exited, false otherwise.
See also
basic_pstreambuf<C,T>::close()

◆ fill_buffer() [1/2]

template<typename C , typename T >
bool Nice::basic_pstreambuf< C, T >::fill_buffer ( )
protected
Returns
true if the buffer was filled, false otherwise.

◆ fill_buffer() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool Nice::basic_pstreambuf< CharT, Traits >::fill_buffer ( )
protected

◆ fork() [1/2]

template<typename C , typename T >
pid_t Nice::basic_pstreambuf< C, T >::fork ( pmode  mode)
protected

Initialise pipes and fork process.

Creates pipes as specified by mode and calls fork() to create a new process.

If the fork is successful the parent process stores the child's PID and the opened pipes and the child process replaces its standard streams with the opened pipes.

If an error occurs the error code will be set to one of the possile errors for pipe() or fork(). See your system's documentation for these error codes.

Parameters
modean OR of pmodes specifying which of the child's standard streams to connect to.
Returns
On success the PID of the child is returned in the parent's context and zero is returned in the child's context. On error -1 is returned and the error code is set appropriately.

◆ fork() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
pid_t Nice::basic_pstreambuf< CharT, Traits >::fork ( pmode  mode)
protected

Initialise pipes and fork process.

◆ init_rbuffers() [1/2]

template<typename C , typename T >
void Nice::basic_pstreambuf< C, T >::init_rbuffers ( )
inlineprivate

Called on construction to initialise the arrays used for reading.

◆ init_rbuffers() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
void Nice::basic_pstreambuf< CharT, Traits >::init_rbuffers ( )
private

◆ is_open() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool Nice::basic_pstreambuf< CharT, Traits >::is_open ( ) const

Report whether the stream buffer has been initialised.

◆ is_open() [2/2]

template<typename C , typename T >
bool Nice::basic_pstreambuf< C, T >::is_open ( ) const
inline

Report whether the stream buffer has been initialised.

Returns
true if a previous call to open() succeeded and wait() has not been called and determined that the process has exited, false otherwise.
Warning
This function can not be used to determine whether the command used to initialise the buffer was successfully executed or not. If the shell command failed this function will still return true. You can use exited() to see if it's still open.

◆ kill() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_pstreambuf* Nice::basic_pstreambuf< CharT, Traits >::kill ( int  signal = SIGTERM)

Send a signal to the process.

◆ kill() [2/2]

template<typename C , typename T >
basic_pstreambuf< C, T > * Nice::basic_pstreambuf< C, T >::kill ( int  signal = SIGTERM)
inline

Send a signal to the process.

Sends the specified signal to the process.

A signal can be used to terminate a child process that would not exit otherwise.

If an error occurs the error code will be set to one of the possible errors for kill(). See your system's documentation for these errors.

Parameters
signalA signal to send to the child process.
Returns
this or NULL if kill() fails.

◆ open() [1/4]

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_pstreambuf* Nice::basic_pstreambuf< CharT, Traits >::open ( const std::string &  command,
pmode  mode 
)

Initialise the stream buffer with command.

◆ open() [2/4]

template<typename C , typename T >
basic_pstreambuf< C, T > * Nice::basic_pstreambuf< C, T >::open ( const std::string &  command,
pmode  mode 
)

Initialise the stream buffer with command.

Starts a new process by passing command to the shell and opens pipes to the process with the specified mode.

Will duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character.

There is no way to tell whether the shell command succeeded, this function will always succeed unless resource limits (such as memory usage, or number of processes or open files) are exceeded. This means is_open() will return true even if command cannot be executed.

Parameters
commanda string containing a shell command.
modea bitwise OR of one or more of out, in, err.
Returns
NULL if the shell could not be started or the pipes could not be opened, this otherwise.
See also
execlp(3)

◆ open() [3/4]

template<typename C , typename T >
basic_pstreambuf< C, T > * Nice::basic_pstreambuf< C, T >::open ( const std::string &  file,
const argv_type argv,
pmode  mode 
)

Initialise the stream buffer with file and argv.

Starts a new process by executing file with the arguments in argv and opens pipes to the process with the specified mode.

By convention argv[0] should be the file name of the file being executed. Will duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character.

Iff file is successfully executed then is_open() will return true. Note that exited() will return true if file cannot be executed, since the child process will have exited.

Parameters
filea string containing the pathname of a program to execute.
argva vector of argument strings passed to the new program.
modea bitwise OR of one or more of out, in and err.
Returns
NULL if a pipe could not be opened or if the program could not be executed, this otherwise.
See also
execvp(3)

◆ open() [4/4]

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_pstreambuf* Nice::basic_pstreambuf< CharT, Traits >::open ( const std::string &  file,
const argv_type argv,
pmode  mode 
)

Initialise the stream buffer with file and argv.

◆ operator=() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_pstreambuf& Nice::basic_pstreambuf< CharT, Traits >::operator= ( const basic_pstreambuf< CharT, Traits > &  )
private

◆ operator=() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_pstreambuf& Nice::basic_pstreambuf< CharT, Traits >::operator= ( const basic_pstreambuf< CharT, Traits > &  )
private

◆ overflow() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
int_type Nice::basic_pstreambuf< CharT, Traits >::overflow ( int_type  c)
protected

Transfer characters to the pipe when character buffer overflows.

◆ overflow() [2/2]

template<typename C , typename T >
basic_pstreambuf< C, T >::int_type Nice::basic_pstreambuf< C, T >::overflow ( int_type  c)
protected

Transfer characters to the pipe when character buffer overflows.

Called when the internal character buffer is not present or is full, to transfer the buffer contents to the pipe.

Parameters
ca character to be written to the pipe.
Returns
traits_type::not_eof(c) if c is equal to traits_type::eof(). Otherwise returns c if c can be written to the pipe, or traits_type::eof() if not.

◆ pbackfail() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
int_type Nice::basic_pstreambuf< CharT, Traits >::pbackfail ( int_type  c = traits_type::eof())
protected

Make a character available to be returned by the next extraction.

◆ pbackfail() [2/2]

template<typename C , typename T >
basic_pstreambuf< C, T >::int_type Nice::basic_pstreambuf< C, T >::pbackfail ( int_type  c = traits_type::eof())
protected

Make a character available to be returned by the next extraction.

Attempts to make c available as the next character to be read by sgetc().

Parameters
ca character to make available for extraction.
Returns
c if the character can be made available, traits_type::eof() otherwise.

◆ peof() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
void Nice::basic_pstreambuf< CharT, Traits >::peof ( )

Close the pipe connected to the process' stdin.

◆ peof() [2/2]

template<typename C , typename T >
void Nice::basic_pstreambuf< C, T >::peof ( )
inline

Close the pipe connected to the process' stdin.

Closes the output pipe, causing the child process to receive the end-of-file indicator on subsequent reads from its stdin stream.

◆ rbuffer() [1/2]

template<typename C , typename T >
basic_pstreambuf< C, T >::char_type * Nice::basic_pstreambuf< C, T >::rbuffer ( )
inlineprotected

Return the active input buffer.

Returns
a pointer to the start of the active input buffer area.

◆ rbuffer() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
char_type* Nice::basic_pstreambuf< CharT, Traits >::rbuffer ( )
protected

Return the active input buffer.

◆ read() [1/2]

template<typename C , typename T >
std::streamsize Nice::basic_pstreambuf< C, T >::read ( char_type s,
std::streamsize  n 
)
inlineprotected

Extract a sequence of characters from the pipe.

Reads up to n characters from the pipe to the buffer s.

This currently only works for fixed width character encodings where each character uses sizeof(char_type) bytes.

Parameters
scharacter buffer.
nbuffer length.
Returns
the number of characters read.

◆ read() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
std::streamsize Nice::basic_pstreambuf< CharT, Traits >::read ( char_type s,
std::streamsize  n 
)
protected

Extract a sequence of characters from the pipe.

◆ read_err() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool Nice::basic_pstreambuf< CharT, Traits >::read_err ( bool  readerr = true)

Change active input source.

◆ read_err() [2/2]

template<typename C , typename T >
bool Nice::basic_pstreambuf< C, T >::read_err ( bool  readerr = true)
inline

Change active input source.

Toggle the stream used for reading.

If readerr is true then the process' stderr output will be used for subsequent extractions, if readerr is false the the process' stdout will be used.

Parameters
readerrtrue to read stderr, false to read stdout.
Returns
true if the requested stream is open and will be used for subsequent extractions, false otherwise.

◆ rpipe() [1/4]

template<typename CharT , typename Traits = std::char_traits<CharT>>
fd_type& Nice::basic_pstreambuf< CharT, Traits >::rpipe ( )
protected

Return the file descriptor for the active input pipe.

◆ rpipe() [2/4]

template<typename C , typename T >
basic_pstreambuf< C, T >::fd_type & Nice::basic_pstreambuf< C, T >::rpipe ( )
inlineprotected

Return the file descriptor for the active input pipe.

Returns
a reference to the active input file descriptor

◆ rpipe() [3/4]

template<typename CharT , typename Traits = std::char_traits<CharT>>
fd_type& Nice::basic_pstreambuf< CharT, Traits >::rpipe ( buf_read_src  which)
protected

Return the file descriptor for the specified input pipe.

◆ rpipe() [4/4]

template<typename C , typename T >
basic_pstreambuf< C, T >::fd_type & Nice::basic_pstreambuf< C, T >::rpipe ( buf_read_src  which)
inlineprotected

Return the file descriptor for the specified input pipe.

Returns
a reference to the specified input file descriptor

◆ showmanyc() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
std::streamsize Nice::basic_pstreambuf< CharT, Traits >::showmanyc ( )
protected

Report how many characters can be read from active input without blocking.

◆ showmanyc() [2/2]

template<typename C , typename T >
std::streamsize Nice::basic_pstreambuf< C, T >::showmanyc ( )
protected

Report how many characters can be read from active input without blocking.

◆ status() [1/2]

template<typename C , typename T >
int Nice::basic_pstreambuf< C, T >::status ( ) const
inline

Return the exit status of the process.

Returns
The exit status of the child process, or -1 if close() has not yet been called to wait for the child to exit.
See also
basic_pstreambuf<C,T>::close()

◆ status() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
int Nice::basic_pstreambuf< CharT, Traits >::status ( ) const

Return the exit status of the process.

◆ switch_read_buffer() [1/2]

template<typename C , typename T >
basic_pstreambuf< C, T >::buf_read_src Nice::basic_pstreambuf< C, T >::switch_read_buffer ( buf_read_src  src)
protected

◆ switch_read_buffer() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
buf_read_src Nice::basic_pstreambuf< CharT, Traits >::switch_read_buffer ( buf_read_src  )
protected

◆ sync() [1/2]

template<typename C , typename T >
int Nice::basic_pstreambuf< C, T >::sync ( )
protected

Write any buffered characters to the stream.

◆ sync() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
int Nice::basic_pstreambuf< CharT, Traits >::sync ( )
protected

Write any buffered characters to the stream.

◆ underflow() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
int_type Nice::basic_pstreambuf< CharT, Traits >::underflow ( )
protected

Transfer characters from the pipe when the character buffer is empty.

◆ underflow() [2/2]

template<typename C , typename T >
basic_pstreambuf< C, T >::int_type Nice::basic_pstreambuf< C, T >::underflow ( )
protected

Transfer characters from the pipe when the character buffer is empty.

Called when the internal character buffer is is empty, to re-fill it from the pipe.

Returns
The first available character in the buffer, or traits_type::eof() in case of failure.

◆ wait() [1/2]

template<typename C , typename T >
int Nice::basic_pstreambuf< C, T >::wait ( bool  nohang = false)
protected

Wait for the child process to exit.

Suspends execution and waits for the associated process to exit, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function.

If the process has already exited wait() returns immediately.

Parameters
nohangtrue to return immediately if the process has not exited.
Returns
1 if the process has exited. 0 if nohang is true and the process has not exited yet. -1 if no process has been started or if an error occurs, in which case the error can be found using error().

◆ wait() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
int Nice::basic_pstreambuf< CharT, Traits >::wait ( bool  nohang = false)
protected

Wait for the child process to exit.

◆ wpipe() [1/2]

template<typename C , typename T >
basic_pstreambuf< C, T >::fd_type & Nice::basic_pstreambuf< C, T >::wpipe ( )
inlineprotected

Return the file descriptor for the output pipe.

Returns
a reference to the output file descriptor

◆ wpipe() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
fd_type& Nice::basic_pstreambuf< CharT, Traits >::wpipe ( )
protected

Return the file descriptor for the output pipe.

◆ write() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
std::streamsize Nice::basic_pstreambuf< CharT, Traits >::write ( const char_type s,
std::streamsize  n 
)
protected

Insert a sequence of characters into the pipe.

◆ write() [2/2]

template<typename C , typename T >
std::streamsize Nice::basic_pstreambuf< C, T >::write ( const char_type s,
std::streamsize  n 
)
inlineprotected

Insert a sequence of characters into the pipe.

Writes up to n characters to the pipe from the buffer s.

This currently only works for fixed width character encodings where each character uses sizeof(char_type) bytes.

Parameters
scharacter buffer.
nbuffer length.
Returns
the number of characters written.

◆ xsputn() [1/2]

template<typename C , typename T >
std::streamsize Nice::basic_pstreambuf< C, T >::xsputn ( const char_type s,
std::streamsize  n 
)
protected

Insert multiple characters into the pipe.

Parameters
scharacter buffer.
nbuffer length.
Returns
the number of characters written.

◆ xsputn() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
std::streamsize Nice::basic_pstreambuf< CharT, Traits >::xsputn ( const char_type s,
std::streamsize  n 
)
protected

Insert multiple characters into the pipe.

Friends And Related Function Documentation

◆ close_fd() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
void close_fd ( pstreams::fd_type fd)
related

Helper function to close a file descriptor.

Inspects fd and calls close(3) if it has a non-negative value.

Parameters
fda file descriptor.

◆ close_fd() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
void close_fd ( pstreams::fd_type fd)
related

Helper function to close a file descriptor.

Inspects fd and calls close(3) if it has a non-negative value.

Parameters
fda file descriptor.

◆ close_fd_array() [1/2]

template<int N>
void close_fd_array ( pstreams::fd_type(&)  fds[N])
related

Helper function to close an array of file descriptors.

Calls close_fd() on each member of the array. The length of the array is determined automatically by template argument deduction to avoid errors.

Parameters
fdsan array of file descriptors.

◆ close_fd_array() [2/2]

template<int N>
void close_fd_array ( pstreams::fd_type(&)  fds[N])
related

Helper function to close an array of file descriptors.

Calls close_fd() on each member of the array. The length of the array is determined automatically by template argument deduction to avoid errors.

Parameters
fdsan array of file descriptors.

Member Data Documentation

◆ error_

template<typename CharT , typename Traits = std::char_traits<CharT>>
int Nice::basic_pstreambuf< CharT, Traits >::error_
private

◆ ppid_

template<typename CharT , typename Traits = std::char_traits<CharT>>
pid_t Nice::basic_pstreambuf< CharT, Traits >::ppid_
private

◆ rbuffer_

template<typename CharT , typename Traits = std::char_traits<CharT>>
char_type * Nice::basic_pstreambuf< CharT, Traits >::rbuffer_
private

◆ rbufstate_

template<typename CharT , typename Traits = std::char_traits<CharT>>
char_type * Nice::basic_pstreambuf< CharT, Traits >::rbufstate_
private

◆ rpipe_

template<typename CharT , typename Traits = std::char_traits<CharT>>
fd_type Nice::basic_pstreambuf< CharT, Traits >::rpipe_
private

◆ rsrc_

template<typename CharT , typename Traits = std::char_traits<CharT>>
buf_read_src Nice::basic_pstreambuf< CharT, Traits >::rsrc_
private

Index into rpipe_[] to indicate active source for read operations.

◆ status_

template<typename CharT , typename Traits = std::char_traits<CharT>>
int Nice::basic_pstreambuf< CharT, Traits >::status_
private

◆ wbuffer_

template<typename CharT , typename Traits = std::char_traits<CharT>>
char_type * Nice::basic_pstreambuf< CharT, Traits >::wbuffer_
private

◆ wpipe_

template<typename CharT , typename Traits = std::char_traits<CharT>>
fd_type Nice::basic_pstreambuf< CharT, Traits >::wpipe_
private

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