BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
PyEmbeddedUtils.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Utils/PyEmbeddedUtils.h
6 //! @brief Defines PyEmbeddedUtils namespace
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_CORE_PYIO_PYEMBEDDEDUTILS_H
16 #define BORNAGAIN_CORE_PYIO_PYEMBEDDEDUTILS_H
17 
18 #ifdef BORNAGAIN_PYTHON
19 
20 #include "Base/Utils/PyObject.h"
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 class MultiLayer;
26 
27 namespace PyEmbeddedUtils
28 {
29 
30 //! Converts PyObject into string, if possible, or throws exception.
31 std::string toString(PyObject* obj);
32 
33 //! Converts PyObject into vector of strings, if possible, or throws exception.
34 std::vector<std::string> toVectorString(PyObject* obj);
35 
36 //! Converts char to string. In the case of nullptr will return an empty string.
37 std::string toString(char* c);
38 std::string toString(wchar_t* c);
39 
40 //! Imports BornAgain from given location. If path is empty, tries to rely on PYTHONPATH.
41 void import_bornagain(const std::string& path = "");
42 
43 //! Returns multi-line string representing PATH, PYTHONPATH, sys.path and other info.
44 std::string pythonRuntimeInfo();
45 
46 //! Returns string representing python stack trace.
47 std::string pythonStackTrace();
48 } // namespace PyEmbeddedUtils
49 
50 #endif // BORNAGAIN_PYTHON
51 
52 #endif // BORNAGAIN_CORE_PYIO_PYEMBEDDEDUTILS_H
PyObvject forward declaration.
_object PyObject
Definition: PyObject.h:20
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:42
std::string toString(PyObject *obj)
Converts PyObject into string, if possible, or throws exception.
std::vector< std::string > toVectorString(PyObject *obj)
Converts PyObject into vector of strings, if possible, or throws exception.
std::string pythonStackTrace()
Returns string representing python stack trace.
void import_bornagain(const std::string &path="")
Imports BornAgain from given location. If path is empty, tries to rely on PYTHONPATH.
std::string pythonRuntimeInfo()
Returns multi-line string representing PATH, PYTHONPATH, sys.path and other info.