7 #ifndef MDS_UTILS_PYTHON_FILEOBJ_HPP_INCLUDED 8 #define MDS_UTILS_PYTHON_FILEOBJ_HPP_INCLUDED 36 #include <boost/iostreams/stream_buffer.hpp> 37 #include <boost/shared_ptr.hpp> 64 boost::shared_ptr<boost::iostreams::stream_buffer<mds_utils::file_utils::cFile_Device> >
69 boost::shared_ptr<std::iostream> pios;
89 if (!PyFile_Check(
m_po))
throw std::runtime_error(
"Not a Python file object");
91 fdevice.set_FILEp(PyFile_AsFile(
m_po));
92 piosbuf.reset(
new boost::iostreams::stream_buffer<mds_utils::file_utils::cFile_Device>());
93 piosbuf->open(fdevice);
94 pios.reset(
new std::iostream(piosbuf.get()));
95 pios->exceptions(std::ios::badbit | std::ios::failbit);
99 operator std::iostream& () {
115 boost::shared_ptr<boost::iostreams::stream_buffer<mds_utils::file_utils::cFile_Source> >
120 boost::shared_ptr<std::istream> pis;
140 if (!PyFile_Check(
m_po))
throw std::runtime_error(
"Not a Python file object");
142 fsource.set_FILEp(PyFile_AsFile(
m_po));
143 pisbuf.reset(
new boost::iostreams::stream_buffer<mds_utils::file_utils::cFile_Source>());
144 pisbuf->open(fsource);
145 pis.reset(
new std::istream(pisbuf.get()));
146 pis->exceptions(std::ios::badbit | std::ios::failbit);
150 operator std::istream& () {
return *pis; }
164 boost::shared_ptr<boost::iostreams::stream_buffer<mds_utils::file_utils::cFile_Sink> >
169 boost::shared_ptr<std::ostream> pos;
189 if (!PyFile_Check(
m_po))
throw std::runtime_error(
"Not a Python file object");
191 fsink.set_FILEp(PyFile_AsFile(
m_po));
192 posbuf.reset(
new boost::iostreams::stream_buffer<mds_utils::file_utils::cFile_Sink>());
194 pos.reset(
new std::ostream(posbuf.get()));
195 pos->exceptions(std::ios::badbit | std::ios::failbit);
199 operator std::ostream& () {
return *pos; }
Source device for FILE* pointers.
Sink device for FILE* pointers.
FileObj()
Default constructor.
Contains some Boost.Iostreams devices to use a C FILE* as a C++ std::stream.
Class for easily managment of Python input file objects from C++ code.
iFileObj()
Default constructor.
Main namespace of all Michele De Stefano's C++ utilities.
Utilities and workarounds for all the extension codes.
Device for FILE* pointers.
PyObject * m_po
Underlying pointer to the wrapped Python object.
Contains a wrapper class for the PyObject* datatype.
Class for easily managment of Python file objects from C++ code.
iFileObj(PyObject *po)
Constructor from a Python object.
oFileObj(PyObject *po)
Constructor from a Python object.
Class for easily managment of Python output file objects from C++ code.
FileObj(PyObject *po)
Constructor from a Python object.
oFileObj()
Default constructor.
This is a simple wrapper around the PyObject* datatype.