Public Member Functions | Protected Attributes | List of all members
scoped_ostream_redirect Class Reference

#include <iostream.h>

Inheritance diagram for scoped_ostream_redirect:
Inheritance graph
[legend]

Public Member Functions

scoped_ostream_redirectoperator= (const scoped_ostream_redirect &)=delete
 
scoped_ostream_redirectoperator= (scoped_ostream_redirect &&)=delete
 
 scoped_ostream_redirect (const scoped_ostream_redirect &)=delete
 
 scoped_ostream_redirect (scoped_ostream_redirect &&other)=default
 
 scoped_ostream_redirect (std::ostream &costream=std::cout, const object &pyostream=module_::import("sys").attr("stdout"))
 
 ~scoped_ostream_redirect ()
 

Protected Attributes

detail::pythonbuf buffer
 
std::ostream & costream
 
std::streambuf * old
 

Detailed Description

\rst This a move-only guard that redirects output.

.. code-block:: cpp

#include <pybind11/iostream.h>

...

{
    py::scoped_ostream_redirect output;
    std::cout << "Hello, World!"; // Python stdout
} // <-- return std::cout to normal

You can explicitly pass the c++ stream and the python object, for example to guard stderr instead.

.. code-block:: cpp

{
    py::scoped_ostream_redirect output{
        std::cerr, py::module::import("sys").attr("stderr")};
    std::cout << "Hello, World!";
}

\endrst

Definition at line 159 of file iostream.h.

Constructor & Destructor Documentation

◆ scoped_ostream_redirect() [1/3]

scoped_ostream_redirect::scoped_ostream_redirect ( std::ostream &  costream = std::cout,
const object pyostream = module_::import("sys").attr("stdout") 
)
inlineexplicit

Definition at line 166 of file iostream.h.

◆ ~scoped_ostream_redirect()

scoped_ostream_redirect::~scoped_ostream_redirect ( )
inline

Definition at line 173 of file iostream.h.

◆ scoped_ostream_redirect() [2/3]

scoped_ostream_redirect::scoped_ostream_redirect ( const scoped_ostream_redirect )
delete

◆ scoped_ostream_redirect() [3/3]

scoped_ostream_redirect::scoped_ostream_redirect ( scoped_ostream_redirect &&  other)
default

Member Function Documentation

◆ operator=() [1/2]

scoped_ostream_redirect& scoped_ostream_redirect::operator= ( const scoped_ostream_redirect )
delete

◆ operator=() [2/2]

scoped_ostream_redirect& scoped_ostream_redirect::operator= ( scoped_ostream_redirect &&  )
delete

Member Data Documentation

◆ buffer

detail::pythonbuf scoped_ostream_redirect::buffer
protected

Definition at line 163 of file iostream.h.

◆ costream

std::ostream& scoped_ostream_redirect::costream
protected

Definition at line 162 of file iostream.h.

◆ old

std::streambuf* scoped_ostream_redirect::old
protected

Definition at line 161 of file iostream.h.


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


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:10:07