1 | #include "dispersion_visitor.hh" |
---|
2 | #include "parameters.hh" |
---|
3 | |
---|
4 | #ifndef __MODELS_STANDALONE__ |
---|
5 | extern "C" { |
---|
6 | #include <Python.h> |
---|
7 | } |
---|
8 | #endif |
---|
9 | |
---|
10 | void DispersionVisitor:: dispersion_to_dict(void* dispersion, void* dictionary) { |
---|
11 | #ifndef __MODELS_STANDALONE__ |
---|
12 | DispersionModel * disp = (DispersionModel*)dispersion; |
---|
13 | PyObject * dict = (PyObject*)dictionary; |
---|
14 | |
---|
15 | PyDict_SetItemString(dict, "type", Py_BuildValue("s", "flat")); |
---|
16 | PyDict_SetItemString(dict, "npts", Py_BuildValue("i", disp->npts)); |
---|
17 | PyDict_SetItemString(dict, "width", Py_BuildValue("d", disp->width)); |
---|
18 | #endif |
---|
19 | } |
---|
20 | |
---|
21 | void DispersionVisitor:: gaussian_to_dict(void* dispersion, void* dictionary) { |
---|
22 | #ifndef __MODELS_STANDALONE__ |
---|
23 | GaussianDispersion * disp = (GaussianDispersion*)dispersion; |
---|
24 | PyObject * dict = (PyObject*)dictionary; |
---|
25 | |
---|
26 | PyDict_SetItemString(dict, "type", Py_BuildValue("s", "gaussian")); |
---|
27 | PyDict_SetItemString(dict, "npts", Py_BuildValue("i", disp->npts)); |
---|
28 | PyDict_SetItemString(dict, "width", Py_BuildValue("d", disp->width)); |
---|
29 | PyDict_SetItemString(dict, "nsigmas", Py_BuildValue("d", disp->nsigmas)); |
---|
30 | #endif |
---|
31 | } |
---|
32 | |
---|
33 | void DispersionVisitor:: rectangle_to_dict(void* dispersion, void* dictionary) { |
---|
34 | #ifndef __MODELS_STANDALONE__ |
---|
35 | RectangleDispersion * disp = (RectangleDispersion*)dispersion; |
---|
36 | PyObject * dict = (PyObject*)dictionary; |
---|
37 | |
---|
38 | PyDict_SetItemString(dict, "type", Py_BuildValue("s", "rectangle")); |
---|
39 | PyDict_SetItemString(dict, "npts", Py_BuildValue("i", disp->npts)); |
---|
40 | PyDict_SetItemString(dict, "width", Py_BuildValue("d", disp->width)); |
---|
41 | PyDict_SetItemString(dict, "nsigmas", Py_BuildValue("d", disp->nsigmas)); |
---|
42 | #endif |
---|
43 | } |
---|
44 | |
---|
45 | void DispersionVisitor:: lognormal_to_dict(void* dispersion, void* dictionary) { |
---|
46 | #ifndef __MODELS_STANDALONE__ |
---|
47 | LogNormalDispersion * disp = (LogNormalDispersion*)dispersion; |
---|
48 | PyObject * dict = (PyObject*)dictionary; |
---|
49 | |
---|
50 | PyDict_SetItemString(dict, "type", Py_BuildValue("s", "lognormal")); |
---|
51 | PyDict_SetItemString(dict, "npts", Py_BuildValue("i", disp->npts)); |
---|
52 | PyDict_SetItemString(dict, "width", Py_BuildValue("d", disp->width)); |
---|
53 | PyDict_SetItemString(dict, "nsigmas", Py_BuildValue("d", disp->nsigmas)); |
---|
54 | #endif |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | void DispersionVisitor:: schulz_to_dict(void* dispersion, void* dictionary) { |
---|
59 | #ifndef __MODELS_STANDALONE__ |
---|
60 | SchulzDispersion * disp = (SchulzDispersion*)dispersion; |
---|
61 | PyObject * dict = (PyObject*)dictionary; |
---|
62 | |
---|
63 | PyDict_SetItemString(dict, "type", Py_BuildValue("s", "schulz")); |
---|
64 | PyDict_SetItemString(dict, "npts", Py_BuildValue("i", disp->npts)); |
---|
65 | PyDict_SetItemString(dict, "width", Py_BuildValue("d", disp->width)); |
---|
66 | PyDict_SetItemString(dict, "nsigmas", Py_BuildValue("d", disp->nsigmas)); |
---|
67 | #endif |
---|
68 | } |
---|
69 | |
---|
70 | void DispersionVisitor:: array_to_dict(void* dispersion, void* dictionary) { |
---|
71 | #ifndef __MODELS_STANDALONE__ |
---|
72 | ArrayDispersion * disp = (ArrayDispersion*)dispersion; |
---|
73 | PyObject * dict = (PyObject*)dictionary; |
---|
74 | |
---|
75 | PyDict_SetItemString(dict, "type", Py_BuildValue("s", "array")); |
---|
76 | #endif |
---|
77 | } |
---|
78 | |
---|
79 | void DispersionVisitor:: dispersion_from_dict(void* dispersion, void* dictionary) { |
---|
80 | #ifndef __MODELS_STANDALONE__ |
---|
81 | DispersionModel * disp = (DispersionModel*)dispersion; |
---|
82 | PyObject * dict = (PyObject*)dictionary; |
---|
83 | |
---|
84 | disp->npts = PyInt_AsLong( PyDict_GetItemString(dict, "npts") ); |
---|
85 | disp->width = PyFloat_AsDouble( PyDict_GetItemString(dict, "width") ); |
---|
86 | #endif |
---|
87 | } |
---|
88 | |
---|
89 | void DispersionVisitor:: gaussian_from_dict(void* dispersion, void* dictionary) { |
---|
90 | #ifndef __MODELS_STANDALONE__ |
---|
91 | GaussianDispersion * disp = (GaussianDispersion*)dispersion; |
---|
92 | PyObject * dict = (PyObject*)dictionary; |
---|
93 | |
---|
94 | disp->npts = PyInt_AsLong( PyDict_GetItemString(dict, "npts") ); |
---|
95 | disp->width = PyFloat_AsDouble( PyDict_GetItemString(dict, "width") ); |
---|
96 | disp->nsigmas = PyFloat_AsDouble( PyDict_GetItemString(dict, "nsigmas") ); |
---|
97 | #endif |
---|
98 | } |
---|
99 | |
---|
100 | void DispersionVisitor:: rectangle_from_dict(void* dispersion, void* dictionary) { |
---|
101 | #ifndef __MODELS_STANDALONE__ |
---|
102 | RectangleDispersion * disp = (RectangleDispersion*)dispersion; |
---|
103 | PyObject * dict = (PyObject*)dictionary; |
---|
104 | |
---|
105 | disp->npts = PyInt_AsLong( PyDict_GetItemString(dict, "npts") ); |
---|
106 | disp->width = PyFloat_AsDouble( PyDict_GetItemString(dict, "width") ); |
---|
107 | disp->nsigmas = PyFloat_AsDouble( PyDict_GetItemString(dict, "nsigmas") ); |
---|
108 | #endif |
---|
109 | } |
---|
110 | |
---|
111 | void DispersionVisitor:: lognormal_from_dict(void* dispersion, void* dictionary) { |
---|
112 | #ifndef __MODELS_STANDALONE__ |
---|
113 | LogNormalDispersion * disp = (LogNormalDispersion*)dispersion; |
---|
114 | PyObject * dict = (PyObject*)dictionary; |
---|
115 | |
---|
116 | disp->npts = PyInt_AsLong( PyDict_GetItemString(dict, "npts") ); |
---|
117 | disp->width = PyFloat_AsDouble( PyDict_GetItemString(dict, "width") ); |
---|
118 | disp->nsigmas = PyFloat_AsDouble( PyDict_GetItemString(dict, "nsigmas") ); |
---|
119 | #endif |
---|
120 | } |
---|
121 | void DispersionVisitor:: schulz_from_dict(void* dispersion, void* dictionary) { |
---|
122 | #ifndef __MODELS_STANDALONE__ |
---|
123 | SchulzDispersion * disp = (SchulzDispersion*)dispersion; |
---|
124 | PyObject * dict = (PyObject*)dictionary; |
---|
125 | |
---|
126 | disp->npts = PyInt_AsLong( PyDict_GetItemString(dict, "npts") ); |
---|
127 | disp->width = PyFloat_AsDouble( PyDict_GetItemString(dict, "width") ); |
---|
128 | disp->nsigmas = PyFloat_AsDouble( PyDict_GetItemString(dict, "nsigmas") ); |
---|
129 | #endif |
---|
130 | } |
---|
131 | |
---|
132 | void DispersionVisitor:: array_from_dict(void* dispersion, void* dictionary) {} |
---|