C++ API¶
The C++ API of bob.io.base
allows users to leverage from automatic converters
for classes in bob.io.base
. To use the C API, clients should first,
include the header file <bob.io.base/api.h>
on their compilation units and
then, make sure to call once import_bob_io_base()
at their module
instantiation, as explained at the Python manual.
Here is a dummy C example showing how to include the header and where to call the import function:
#include <bob.io.base/api.h>
PyMODINIT_FUNC initclient(void) {
PyObject* m Py_InitModule("client", ClientMethods);
if (!m) return;
/* imports dependencies */
if (import_bob_blitz() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import extension");
return 0;
}
if (import_bob_io_base() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import extension");
return 0;
}
}
Generic Functions¶
-
int
PyBobIo_AsTypenum
(bob::core::array::ElementType et)¶ Converts the input Bob element type into a
NPY_<TYPE>
enumeration value. ReturnsNPY_NOTYPE
in case of problems, and sets aRuntimeError
.
-
PyObject *
PyBobIo_TypeInfoAsTuple
(const bob::core::array::typeinfo &ti)¶ Converts the
bob::core::array::typeinfo&
object into a new reference to atuple
with 3 elements:- [0]
- The data type as a
numpy.dtype
object - [1]
- The shape of the object, as a tuple of integers
- [2]
- The strides of the object, as a tuple of integers
Returns
0
in case of failure, or a new reference to the tuple described above in case of success.
-
int
PyBobIo_FilenameConverter
(PyObject *o, const char **b)¶ This function is meant to be used with
PyArg_ParseTupleAndKeywords()
family of functions in the Python C-API. It converts an arbitrary input object into aconst char*
If the input object is of typePyUnicodeObject
(which is the default in Python3.x) the unicode code is properly decoded usingPyUnicode_AsEncodedString()
withencoding
set toPy_FileSystemDefaultEncoding
anderrors
set to"strict"
.Objects which are not
PyUnicodeObject
are first coerced into a bytes/string before converting to theconst char*
object usingPyObject_Bytes()
(on Python3.x) andPyObject_Str()
(on Python 2.x).Returns 0 if an error is detected, 1 on success.
Note
Since version 2.2, this function converts into
const char*
directly. Before version 2.2, it was returning eitherPyBytesObject
(Python 3) orPyStringObject
(Python 2).
Bob File Support¶
-
type
PyBobIoFileObject
¶ The pythonic object representation for a
bob::io::base::File
object.typedef struct { PyObject_HEAD boost::shared_ptr<bob::io::base::File> f; } PyBobIoFileObject;
-
boost::shared_ptr<bob::io::base::File>
f
¶ A pointer to a file being read or written.
-
boost::shared_ptr<bob::io::base::File>
-
type
PyBobIoFileIteratorObject
¶ The pythonic object representation for an iterator over a
bob::io::base::File
object.typedef struct { PyObject_HEAD PyBobIoFileObject* pyfile; Py_ssize_t curpos; } PyBobIoFileIteratorObject;
-
PyBobIoFileObject *
pyfile
¶ A pointer to the pythonic representation of a file.
-
Py_ssize_t
curpos
¶ The current position at the file being pointed to.
-
PyBobIoFileObject *
Bob HDF5 Support¶
-
type
PyBobIoHDF5FileObject
¶ The pythonic object representation for a
bob::io::base::HDF5File
object.typedef struct { PyObject_HEAD boost::shared_ptr<bob::io::base::HDF5File> f; } PyBobIoHDF5FileObject;
-
boost::shared_ptr<bob::io::base::HDF5File>
f
¶ A pointer to a Bob object being used to read/write data into an HDF5 file.
-
boost::shared_ptr<bob::io::base::HDF5File>
-
int
PyBobIoHDF5File_Check
(PyObject *o)¶ Checks if the input object
o
is aPyBobIoHDF5FileObject
. Returns1
if it is, and0
otherwise.
-
int
PyBobIoHDF5File_Converter
(PyObject *o, PyBobIoHDF5FileObject **a)¶ This function is meant to be used with
PyArg_ParseTupleAndKeywords()
family of functions in the Python C-API. It checks the input object to be of typePyBobIoHDF5FileObject
and sets a new reference to it (in*a
) if it is the case. Returns0
in case of failure,1
in case of success.