JeVois  1.18
JeVois Smart Embedded Machine Vision Toolkit
Share this page:

#include <jevois/Core/PythonWrapper.H>

Helper class to run python code from C++.

This class loads python code and makes it accessible through pyinst(). It is designed to be composed with other classes that will actually execute some python code via pyinst().

The main convention here is that the python code will define a class with the exact same name as the python filename (without trailing .py extension). This is the class that will then become accessible via pyinst().

Note that constructors and pythonload() will not throw, but pyinst() will if an error occurred at construction.

Often this class is inherited from by a class that also inherits from Component, to create a Component derivative that can run python code. In such case, PythonWrapper will register that sibling association with Engine when the python code is loaded. It is critical that you inherit from Component (or a derivative) before you inherit from PythonWrapper, so that by the time the PythonWrapper destructor is called the Component base should not yet have been destroyed, and it will be unregistered from Engine.

Definition at line 41 of file PythonWrapper.H.

Inheritance diagram for jevois::PythonWrapper:

Public Member Functions

 PythonWrapper ()
 Default constructor. Will need to call pythonload() later. More...
virtual ~PythonWrapper ()
 Destructor. More...
 PythonWrapper (std::string const &path)
 Construct from path. More...
void pythonload (std::string const &path)
 Init from path if default constructor was used. More...
boost::python::object & pyinst ()
 Get the python class pyinst, or throw if construction error occurred (e.g., file not found) More...
boost::python::object & mainModule ()
 Get the main module. More...
boost::python::object & mainNamespace ()
 Get the main namespace. More...
const std::string & constructionError () const
 Get the construction error if any, or empty string. More...

Constructor & Destructor Documentation

◆ PythonWrapper() [1/2]

jevois::PythonWrapper::PythonWrapper ( )

Default constructor. Will need to call pythonload() later.

Definition at line 23 of file PythonWrapper.C.

◆ ~PythonWrapper()

jevois::PythonWrapper::~PythonWrapper ( )


Definition at line 104 of file PythonWrapper.C.

References jevois::Component::engine(), and jevois::Engine::unRegisterPythonComponent().

◆ PythonWrapper() [2/2]

jevois::PythonWrapper::PythonWrapper ( std::string const &  path)

Construct from path.

Definition at line 28 of file PythonWrapper.C.

Member Function Documentation

◆ constructionError()

const std::string & jevois::PythonWrapper::constructionError ( ) const

Get the construction error if any, or empty string.

Definition at line 100 of file PythonWrapper.C.

◆ mainModule()

boost::python::object & jevois::PythonWrapper::mainModule ( )

Get the main module.

Definition at line 92 of file PythonWrapper.C.

◆ mainNamespace()

boost::python::object & jevois::PythonWrapper::mainNamespace ( )

Get the main namespace.

Definition at line 96 of file PythonWrapper.C.

◆ pyinst()

◆ pythonload()

void jevois::PythonWrapper::pythonload ( std::string const &  path)

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