Michele De Stefano's C++ Utilities
mds_utils::python::FileObj Class Reference

Class for easily managment of Python file objects from C++ code. More...

#include <mds_utils/python/fileobj.hpp>

Inheritance diagram for mds_utils::python::FileObj:
mds_utils::python::Obj

Public Member Functions

 FileObj ()
 Default constructor.
 
 FileObj (PyObject *po)
 Constructor from a Python object. More...
 
 operator std::iostream & ()
 Automatic type conversion towards an std::iostream&.
 
- Public Member Functions inherited from mds_utils::python::Obj
 Obj ()
 Default constructor.
 
 Obj (const Obj &rhs)
 The copy-constructor. More...
 
 Obj (Obj &&rhs)
 Move constructor. More...
 
 Obj (ProxyAttr &&rhs)
 Move constructor from ProxyAttr objects. More...
 
 Obj (PyObject *po)
 Construct from a Python object. More...
 
Objoperator= (const Obj &rhs)
 Standard assignment.
 
Objoperator= (Obj &&rhs)
 Move assignment.
 
virtual Objoperator= (PyObject *po)
 Assignment from a Python object. More...
 
template<class T >
Objoperator= (const T &val)
 Assignment from a value. More...
 
virtual ~Obj ()
 Destructor.
 
PyObject * getPyObject () const
 Returns the underlying PyObject. More...
 
 operator PyObject * () const
 Automatic type conversion towards a Python object. More...
 
virtual PyObject * transfer ()
 Returns the Python object with transferred ownership. More...
 
virtual void incref ()
 Increments the reference count using Py_XINCREF. More...
 
virtual void decref ()
 Decrements the reference count using Py_XDECREF.
 
void reset ()
 Resets the object to the state given by the default constructor.
 
void get_ownership ()
 Used in place of incref, when the wrapped PyObject* was increfed already.
 
bool has_attr (const std::string &name) const
 Tests if the object has a particular attribute.
 
ProxyAttr attr (const std::string &name)
 Retrieves an attribute. More...
 
bool is_callable () const
 Checks if the object is callable. More...
 
Obj operator() ()
 Calling operator. More...
 
Obj operator() (const Obj &args)
 Calling operator, with positional arguments. More...
 
Obj operator() (const Obj &args, const Obj &kw)
 Calling operator, with positional and keyword arguments. More...
 

Additional Inherited Members

- Protected Member Functions inherited from mds_utils::python::Obj
void check_callable ()
 Checks if the object is callable. More...
 
void check_call_result (PyObject *result)
 Checks if the result of the object call was successful. More...
 
- Protected Attributes inherited from mds_utils::python::Obj
size_t decref_on_destroy
 
PyObject * m_po
 Underlying pointer to the wrapped Python object.
 

Detailed Description

Class for easily managment of Python file objects from C++ code.

Warning
Once a file is managed through a FileObj, it generally must not be modified with functions that do not use the FileObj instance, unless you really know what you are doing. The FileObj instance must be destroyed before closing the file.
Author
Michele De Stefano
Date
22/04/2014

Definition at line 62 of file fileobj.hpp.

Constructor & Destructor Documentation

mds_utils::python::FileObj::FileObj ( PyObject *  po)
inline

Constructor from a Python object.

Parameters
poA Python file object.
Warning
It does not incref the po pointer. You have to do it manually, if needed, on the FileObj instance. In Python terminology, the reference to po is borrowed.
Author
Michele De Stefano
Date
22/04/2014

Definition at line 88 of file fileobj.hpp.

References mds_utils::python::Obj::m_po.


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