Wrapper class for python modules.
More...
#include <dune/fufem/python/module.hh>
|
| void | assertPyObject (const std::string &origin) const |
| | Assert that internal PyObject* is not NULL and raise exception otherwise.
|
| |
|
| static void | assertModule (PyObject *p, const std::string &origin) |
| | Assert that internal PyObject* is not NULL and module and raise exception otherwise.
|
| |
Wrapper class for python modules.
This class derives from Python::Reference and encapsulates module related functions.
◆ Module() [1/3]
| Python::Module::Module |
( |
| ) |
|
|
inline |
◆ Module() [2/3]
| Python::Module::Module |
( |
PyObject * |
p | ) |
|
|
inline |
Construct Module from PyObject*.
Only to be used if you want to extend the interface using the python api.
This forwards to the corresponding constructor of Reference and then checks if the python object is a module. If this is not the case an exception is thrown. As a consequence the reference count of the PyObject will be correctly decreased by ~Reference even if the exception is thrown.
But be careful to always increment the count of a borrowed reference BEFORE calling this constructor. I.e. always use
Module(Imp::inc(p))
instead of
Imp::inc(Module(p))
The latter may throw an exception and then decrease the count before it is increased.
◆ Module() [3/3]
| Python::Module::Module |
( |
const Reference & |
other | ) |
|
|
inline |
Construct Module from Reference.
This checks if the python object is a module. If this is not the case an exception is thrown.
For implementors:
This will increment the count for the stored reference.
◆ ~Module()
| virtual Python::Module::~Module |
( |
| ) |
|
|
inlinevirtual |
◆ assertModule()
| static void Python::Module::assertModule |
( |
PyObject * |
p, |
|
|
const std::string & |
origin |
|
) |
| |
|
inlinestaticprotected |
Assert that internal PyObject* is not NULL and module and raise exception otherwise.
- Parameters
-
| p | The PyObject* pointer that should be checked |
| origin | A string describing the origin of the error |
◆ assertPyObject()
| void Python::Reference::assertPyObject |
( |
const std::string & |
origin | ) |
const |
|
inlineprotectedinherited |
Assert that internal PyObject* is not NULL and raise exception otherwise.
- Parameters
-
| origin | A string describing the origin of the error |
◆ evaluate()
Evaluate python expression given as string.
This evaluates a python expressions in the given string in the context of this module.
- Parameters
-
| expression | A string containing a python expression |
- Returns
- Result of expression evaluation
◆ get()
Query attribute of given name.
- Parameters
-
- Returns
- The attributes value as Reference
For implementors:
The count for the returned Reference is incremented.
◆ hasAttr()
| bool Python::Reference::hasAttr |
( |
const std::string & |
name | ) |
const |
|
inlineinherited |
Check if object has attribute of given name.
- Parameters
-
◆ import() [1/2]
Import another module into this one.
This import the module with given moduleName under its own name into this module.
- Parameters
-
| moduleName | Name of module to import |
- Returns
- Reference to imported module
◆ import() [2/2]
Import another module into this one.
This imports the given module under its own name into this module.
- Parameters
-
| module | The module to import |
- Returns
- Reference to imported module
◆ importAs() [1/2]
Import another module into this one.
This import the module with given moduleName under given importedName into this module.
- Parameters
-
| moduleName | Name of module to import |
| importedName | The module will be imported under this name |
- Returns
- Reference to imported module
◆ importAs() [2/2]
Import another module into this one.
This import the given module under given importedName into this module.
- Parameters
-
| module | The module to import |
| importedName | The module will be imported under this name |
- Returns
- Reference to imported module
◆ operator PyObject *()
| Python::Reference::operator PyObject * |
( |
| ) |
const |
|
inlineinherited |
Access to stored reference.
Return stored reference without changing its count. You can use this with all api methods that do not steal references.
- Returns
- A PyObject* representing a borrowed reference
◆ operator=()
Assignment.
This will checks if the python object is a module. If this is not the case an exception is thrown.
Reimplemented from Python::Reference.
◆ run()
| virtual void Python::Module::run |
( |
const std::string & |
code | ) |
|
|
inlinevirtual |
Run python code given as string.
The code is executed in the context of this module. Hence all names are resolved or created in this module.
- Parameters
-
| code | A string containing python code |
◆ runFile()
| void Python::Module::runFile |
( |
const std::string & |
fileName | ) |
|
|
inline |
Run python code in file given by name.
The code is executed in the context of this module. Hence all names are resolved or created in this module.
- Parameters
-
| fileName | A string containing the file name |
◆ runStream()
Obtain a stream to feed the code with multiple lines of python code.
The code is executed in the context of this module. Hence all names are resolved or created in this module.
- Returns
- A stream that will execute all fed code on destruction
◆ set()
template<class V >
| void Python::Reference::set |
( |
const std::string & |
name, |
|
|
const V & |
value |
|
) |
| |
|
inlineinherited |
Set attribute of given name.
- Parameters
-
| name | Name of attribute |
| value | New value of attribute |
For implementors:
This will not decrease the reference count for the Reference used as argument.
◆ str()
String representation of this object.
◆ toC() [1/3]
Convert to C object.
This does not change the reference count. This method uses the default constructor of T.
- Template Parameters
-
◆ toC() [2/3]
Convert to C object.
This does not change the reference count. This method uses a type dependent custom construct.
- Template Parameters
-
◆ toC() [3/3]
template<class T >
| void Python::Reference::toC |
( |
T & |
t | ) |
const |
|
inlineinherited |
Convert to C object.
This does not change the reference count.
- Template Parameters
-
- Parameters
-
◆ dict_
◆ p_
| PyObject* Python::Reference::p_ |
|
mutableprotectedinherited |
The documentation for this class was generated from the following file: