NEURON
nrnpy_utils.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "nrnwrap_Python.h"
4 #include "nrn_export.hpp"
5 #include "neuron/unique_cstr.hpp"
6 #include <cassert>
7 
8 
9 inline bool is_python_string(PyObject* python_string) {
10  return PyUnicode_Check(python_string) || PyBytes_Check(python_string);
11 }
12 
14  public:
15  [[nodiscard]] static neuron::unique_cstr as_ascii(PyObject* python_string);
16 
17  static void set_pyerr(PyObject* type, const char* message);
18  [[nodiscard]] static neuron::unique_cstr get_pyerr();
19 
20  private:
21  Py2NRNString() = delete;
22  Py2NRNString(const Py2NRNString&) = delete;
23  Py2NRNString& operator=(const Py2NRNString&) = delete;
24 };
25 
26 extern void nrnpy_sec_referr();
27 #define CHECK_SEC_INVALID(sec) \
28  { \
29  if (!sec->prop) { \
30  nrnpy_sec_referr(); \
31  return NULL; \
32  } \
33  }
34 
35 extern void nrnpy_prop_referr();
36 #define CHECK_PROP_INVALID(propid) \
37  { \
38  if (!propid) { \
39  nrnpy_prop_referr(); \
40  return NULL; \
41  } \
42  }
Py2NRNString()=delete
Py2NRNString(const Py2NRNString &)=delete
Py2NRNString & operator=(const Py2NRNString &)=delete
A RAII wrapper for C-style strings.
Definition: unique_cstr.hpp:18
#define NRN_EXPORT
Definition: nrn_export.hpp:6
short type
Definition: cabvars.h:10
_object PyObject
Definition: nrnpy.h:12
void nrnpy_sec_referr()
Definition: nrnpy_nrn.cpp:150
bool is_python_string(PyObject *python_string)
Definition: nrnpy_utils.h:9
void nrnpy_prop_referr()
Definition: nrnpy_nrn.cpp:154