File: dict.h

package info (click to toggle)
wreport 3.36-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,572 kB
  • sloc: cpp: 18,927; python: 583; sh: 78; makefile: 13
file content (36 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef WREPORT_PYTHON_DICT_H
#define WREPORT_PYTHON_DICT_H

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "core.h"
#include "values.h"

namespace wreport {
namespace python {

template<typename T>
inline void set_dict(PyObject* dict, const char* key, const T& val)
{
    auto pyval = to_python(val);
    if (PyDict_SetItemString(dict, key, pyval))
        throw PythonException();
}

inline void set_dict(PyObject* dict, const char* key, PyObject* val)
{
    if (PyDict_SetItemString(dict, key, val))
        throw PythonException();
}

inline void set_dict(PyObject* dict, const char* key, pyo_unique_ptr& val)
{
    if (PyDict_SetItemString(dict, key, val))
        throw PythonException();
}


}
}

#endif