LvArray
Classes | Namespaces | Macros | Enumerations | Functions
pythonHelpers.hpp File Reference
#include "pythonForwardDeclarations.hpp"
#include "../system.hpp"
#include "../Macros.hpp"
#include "../limits.hpp"
#include <vector>
#include <stdexcept>
Include dependency graph for pythonHelpers.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  LvArray::python::PyObjectRef< T >
 A class that manages an owned Python reference with RAII semantics. More...
 
class  LvArray::python::PythonError
 Base class for all C++ exceptions related to Python. More...
 

Namespaces

 LvArray
 The top level namespace.
 
 LvArray::python
 Contains all the Python code.
 

Macros

#define PYTHON_ERROR_IF(CONDITION, TYPE, MSG, RET)   static_assert( false, "You are attempting to use PYTHON_ERROR_IF but haven't yet included Python.hpp" )
 Raise a Python exception if CONDITION is met. More...
 

Enumerations

enum  LvArray::python::PyModify { READ_ONLY = 0, MODIFIABLE = 1, RESIZEABLE = 2 }
 An enumeration of the various access policies for Python objects.
 

Functions

void LvArray::python::internal::xincref (PyObject *const obj)
 A wrapper around Py_XINCREF. More...
 
void LvArray::python::internal::xdecref (PyObject *const obj)
 A wrapper around Py_XDECREF. More...
 
bool LvArray::python::internal::isInstanceOf (PyObject *const obj, PyTypeObject *type)
 Return true if obj is an instance of type. More...
 
template<typename T >
T * LvArray::python::convert (PyObject *const obj, PyTypeObject *const type)
 Return obj casted to T if obj is an instance of type or nullptr if it is not. More...
 
bool LvArray::python::addTypeToModule (PyObject *const module, PyTypeObject *const type, char const *const typeName)
 Add the Python type type to the module module. More...
 
PyObject * LvArray::python::create (std::string const &value)
 Return a Python string copy of value. More...
 
PyObject * LvArray::python::createPyListOfStrings (std::string const *const strptr, long long const size)
 Create and return a Python list of strings from an array of std::strings. The Python strings will be copies. More...
 
PyObject * LvArray::python::create (std::vector< std::string > const &vec)
 Create and return a Python list of strings from a std::vector of std::strings. The Python strings will be copies. More...
 

Macro Definition Documentation

◆ PYTHON_ERROR_IF

#define PYTHON_ERROR_IF (   CONDITION,
  TYPE,
  MSG,
  RET 
)    static_assert( false, "You are attempting to use PYTHON_ERROR_IF but haven't yet included Python.hpp" )

Raise a Python exception if CONDITION is met.

Parameters
CONDITIONThe condition to check.
TYPEThe Type of Python exception to raise.
MSGThe message to give the exception.
RETThe return value if there was an error.

Function Documentation

◆ isInstanceOf()

bool LvArray::python::internal::isInstanceOf ( PyObject *const  obj,
PyTypeObject *  type 
)

Return true if obj is an instance of type.

Parameters
objThe object.
typeThe type.
Returns
true if obj is an instance of type.

◆ xdecref()

void LvArray::python::internal::xdecref ( PyObject *const  obj)

A wrapper around Py_XDECREF.

Parameters
objThe object to decrease the reference count of, may be a nullptr.

◆ xincref()

void LvArray::python::internal::xincref ( PyObject *const  obj)

A wrapper around Py_XINCREF.

Parameters
objThe object to increase the reference count of, may be a nullptr.