8000 Add fignum_exists() function · michLab/matplotlib-cpp@073dd98 · GitHub
[go: up one dir, main page]

Skip to content

Commit 073dd98

Browse files
alexdewarBenno Evers
authored andcommitted
Add fignum_exists() function
1 parent c92ad4c commit 073dd98

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

matplotlibcpp.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct _interpreter {
3636
PyObject *s_python_function_pause;
3737
PyObject *s_python_function_save;
3838
PyObject *s_python_function_figure;
39+
PyObject *s_python_function_fignum_exists;
3940
PyObject *s_python_function_plot;
4041
PyObject *s_python_function_quiver;
4142
PyObject *s_python_function_semilogx;
@@ -142,6 +143,7 @@ struct _interpreter {
142143
s_python_function_draw = PyObject_GetAttrString(pymod, "draw");
143144
s_python_function_pause = PyObject_GetAttrString(pymod, "pause");
144145
s_python_function_figure = PyObject_GetAttrString(pymod, "figure");
146+
s_python_function_fignum_exists = PyObject_GetAttrString(pymod, "fignum_exists");
145147
s_python_function_plot = PyObject_GetAttrString(pymod, "plot");
146148
s_python_function_quiver = PyObject_GetAttrString(pymod, "quiver");
147149
s_python_function_semilogx = PyObject_GetAttrString(pymod, "semilogx");
@@ -177,6 +179,7 @@ struct _interpreter {
177179
|| !s_python_function_draw
178180
|| !s_python_function_pause
179181
|| !s_python_function_figure
182+
|| !s_python_function_fignum_exists
180183
|| !s_python_function_plot
181184
|| !s_python_function_quiver
182185
|| !s_python_function_semilogx
@@ -211,6 +214,7 @@ struct _interpreter {
211214
|| !PyFunction_Check(s_python_function_draw)
212215
|| !PyFunction_Check(s_python_function_pause)
213216
|| !PyFunction_Check(s_python_function_figure)
217+
|| !PyFunction_Check(s_python_function_fignum_exists)
214218
|| !PyFunction_Check(s_python_function_plot)
215219
|| !PyFunction_Check(s_python_function_quiver)
216220
|| !PyFunction_Check(s_python_function_semilogx)
@@ -845,6 +849,23 @@ inline long figure(long number = -1)
845849
return figureNumber;
846850
}
847851

852+
inline bool fignum_exists(long number)
853+
{
854+
// Make sure interpreter is initialised
855+
detail::_interpreter::get();
856+
857+
PyObject *args = PyTuple_New(1);
858+
PyTuple_SetItem(args, 0, PyLong_FromLong(number));
859+
PyObject *res = PyObject_CallObject(detail::_interpreter::get().s_python_function_fignum_exists, args);
860+
if(!res) throw std::runtime_error("Call to fignum_exists() failed.");
861+
862+
bool ret = PyObject_IsTrue(res);
863+
Py_DECREF(res);
864+
Py_DECREF(args);
865+
866+
return ret;
867+
}
868+
848869
inline void figure_size(size_t w, size_t h)
849870
{
850871
const size_t dpi = 100;

0 commit comments

Comments
 (0)
0