fix all the references
[hkl.git] / hkl / hkl-binding.c
blobe1cf0a694f45f27185079a26749d09fa26ea0e22
1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2012-2014 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
23 #include <stdlib.h> // for malloc
24 #include <string.h> // for NULL, strdup
25 #include <sys/types.h> // for uint
26 #include "hkl-factory-private.h" // for __start_xautodata_factories, etc
27 #include "hkl-geometry-private.h" // for _HklGeometry, etc
28 #include "hkl-parameter-private.h"
29 #include "hkl-pseudoaxis-private.h" // for _HklEngine, HklEngineInfo
30 #include "hkl-sample-private.h" // for _HklSampleReflection, etc
31 #include "hkl.h" // for HklGeometry, HklEngine, etc
32 #include "hkl/ccan/autodata/autodata.h" // for autodata_get
33 #include "hkl/ccan/darray/darray.h" // for darray_foreach, darray_size
34 #include "hkl/ccan/list/list.h" // for list_for_each, list_head
36 /**************/
37 /* HklFactory */
38 /**************/
40 /**
41 * hkl_factories:
43 * return all the Hkl factories objects as a dictionnary
45 * Returns: (element-type utf8 Hkl.Factory) (transfer container):
46 **/
47 GHashTable *hkl_factories(void)
49 GHashTable *table = NULL;
50 size_t i, n;
51 HklFactory **factories;
53 table = g_hash_table_new(g_str_hash, g_str_equal);
54 factories = autodata_get(factories, &n);
55 for(i=0; i<n; ++i){
56 g_hash_table_insert(table,
57 (gpointer)hkl_factory_name_get(factories[i]),
58 factories[i]);
61 return table;
64 /************/
65 /* Geometry */
66 /************/
68 /**
69 * hkl_geometry_axes_names_get_binding:
70 * @self: the this ptr
71 * @length: (out caller-allocates): the length of the returned array
73 * get all the axes of the given geometry.
75 * Rename to: hkl_geometry_axes_names_get
77 * Returns: (array length=length) (transfer none): array of the axes names.
78 **/
79 const char **hkl_geometry_axes_names_get_binding(const HklGeometry *self,
80 size_t *length)
82 const darray_string *axes = hkl_geometry_axes_names_get(self);
84 *length = darray_size(*axes);
86 return &darray_item(*axes, 0);
89 /**
90 * hkl_geometry_axes_values_get_binding:
91 * @self: the this ptr
92 * @len: (out caller-allocates): the length of the returned array
93 * @unit_type: the unit type (default or user) of the returned value
95 * Rename to: hkl_geometry_axes_values_get
97 * Return value: (array length=len) (transfer container): list of axes values,
98 * free the list with free when done.
99 **/
100 double *hkl_geometry_axes_values_get_binding(const HklGeometry *self, guint *len,
101 HklUnitEnum unit_type)
103 double *values;
104 uint i = 0;
105 HklParameter **axis;
107 if(!self || !len || darray_size(self->axes) == 0)
108 return NULL;
110 *len = darray_size(self->axes);
111 values = malloc(darray_size(self->axes) * sizeof(*values));
113 darray_foreach(axis, self->axes){
114 values[i++] = hkl_parameter_value_get(*axis, unit_type);
117 return values;
120 /*******************/
121 /* HklGeometryList */
122 /*******************/
125 * hkl_geometry_list_items:
126 * @self: the #HklGeometryList
128 * Return value: (element-type HklGeometryListItem) (transfer container): list of items,
129 * free the list with g_slist_free when done.
131 GSList* hkl_geometry_list_items(HklGeometryList *self)
133 GSList *list = NULL;
134 HklGeometryListItem *item;
136 list_for_each(&self->items, item, list)
137 list = g_slist_append(list, item);
139 return list;
142 /*************/
143 /* HklEngine */
144 /*************/
147 * hkl_engine_modes_names_get_binding:
148 * @self: the this ptr
149 * @length: (out caller-allocates): return the length of the returned array.
151 * Rename to: hkl_engine_modes_names_get
153 * Return value: (array length=length) (transfer none): All the modes supported by the #HklEngine
155 const char **hkl_engine_modes_names_get_binding(const HklEngine *self, size_t *length)
157 *length = darray_size(self->mode_names);
158 return &darray_item(self->mode_names, 0);
162 * hkl_engine_pseudo_axes_names_get_binding:
163 * @self: the this ptr
164 * @length: (out caller-allocates): return the length of the returned array.
166 * Rename to: hkl_engine_pseudo_axes_names_get
168 * Return value: (array length=length) (transfer none): All the pseudo_axes names of the #HklEngine
171 const char **hkl_engine_pseudo_axes_names_get_binding(HklEngine *self, size_t *length)
173 *length = darray_size(self->pseudo_axes_names);
174 return &darray_item(self->pseudo_axes_names, 0);
178 * hkl_engine_parameters_names_get_binding:
179 * @self: the this ptr
180 * @length: (out caller-allocates): return the length of the returned array.
182 * Rename to: hkl_engine_parameters_names_get
184 * Return value: (array length=length) (transfer none): All the parameters of #HklEngine.
186 const char **hkl_engine_parameters_names_get_binding(const HklEngine *self, size_t *length)
188 *length = darray_size(self->mode->parameters_names);
189 return &darray_item(self->mode->parameters_names, 0);
193 * hkl_engine_axes_names_get_binding:
194 * @self: the this ptr
195 * @mode: the #HklEngineAxesNamesGet
196 * @length: (out caller-allocates): return the length of the returned array.
198 * Rename to: hkl_engine_axes_names_get
200 * Return value: (array length=length) (transfer none): axes of the #HklEngine for the given mode.
202 const char **hkl_engine_axes_names_get_binding(const HklEngine *self,
203 HklEngineAxesNamesGet mode,
204 size_t *length)
206 const darray_string *axes = hkl_engine_axes_names_get(self, mode);
208 *length = darray_size(*axes);
210 return &darray_item(*axes, 0);
214 * hkl_engine_pseudo_axes_values_get_binding:
215 * @self: the this ptr
216 * @len: (out caller-allocates): the length of the returned array
217 * @unit_type: the unit type (default or user) of the returned value
219 * Rename to: hkl_engine_pseudo_axes_values_get
221 * Return value: (array length=len) (transfer container): list of pseudo axes values,
222 * free the list with free when done.
224 double *hkl_engine_pseudo_axes_values_get_binding(const HklEngine *self, guint *len,
225 HklUnitEnum unit_type)
227 double *values;
228 uint i = 0;
229 HklParameter **axis;
231 if(!self || !len || darray_size(self->pseudo_axes) == 0)
232 return NULL;
234 *len = darray_size(self->pseudo_axes);
235 values = malloc(darray_size(self->pseudo_axes) * sizeof(*values));
237 darray_foreach(axis, self->pseudo_axes){
238 values[i++] = hkl_parameter_value_get(*axis, unit_type);
241 return values;
245 * hkl_engine_list_engines_get_as_gslist:
246 * @self: the this ptr
248 * Return value: (element-type HklEngine) (transfer container): list of engines,
249 * free the list with g_slist_free when done.
251 * Rename to: hkl_engine_list_engines_get
253 GSList* hkl_engine_list_engines_get_as_gslist(HklEngineList *self)
255 GSList *list = NULL;
256 HklEngine **engine;
258 darray_foreach(engine, *self){
259 list = g_slist_append(list, *engine);
262 return list;
265 /*************/
266 /* HklSample */
267 /*************/
270 * hkl_sample_reflections_get:
271 * @self: the this ptr
273 * Return value: (element-type HklSampleReflection) (transfer container): list of reflections,
274 * free the list with g_slist_free when done.
276 GSList *hkl_sample_reflections_get(const HklSample *self)
278 GSList *list = NULL;
279 HklSampleReflection *reflection;
281 list_for_each(&self->reflections, reflection, list){
282 list = g_slist_append(list, reflection);
285 return list;
289 * hkl_sample_add_reflection_binding:
290 * @self: the this ptr
291 * @geometry: the geometry of the HklSampleReflection
292 * @detector: the detector of the HklSampleReflection
293 * @h: the h coordinate
294 * @k: the k coordinate
295 * @l: the l coordinate
296 * @error: return location for a GError, or NULL
298 * Return value: (transfer none): the newly created HklSampleReflection
300 * Rename to: hkl_sample_add_reflection
302 HklSampleReflection *hkl_sample_add_reflection_binding(HklSample *self,
303 const HklGeometry *geometry,
304 const HklDetector *detector,
305 double h, double k, double l,
306 GError **error)
308 HklSampleReflection *reflection;
310 hkl_error (error == NULL || *error == NULL);
312 reflection = hkl_sample_reflection_new(geometry, detector,
313 h, k, l, error);
314 if(!reflection){
315 g_assert (error == NULL || *error != NULL);
316 return NULL;
318 g_assert (error == NULL || *error == NULL);
320 hkl_sample_add_reflection(self, reflection);
322 return reflection;