upgrading copyright year from 2015 to 2016
[hkl.git] / hkl / hkl-binding.c
blobf87a97f073fa7dbf25cecc63b6d1c73c61fee869
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-2016 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_axis_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_axis_names_get
77 * Returns: (array length=length) (transfer none): array of the axes names.
78 **/
79 const char **hkl_geometry_axis_names_get_binding(const HklGeometry *self,
80 size_t *length)
82 const darray_string *axes = hkl_geometry_axis_names_get(self);
84 *length = darray_size(*axes);
86 return &darray_item(*axes, 0);
89 /**
90 * hkl_geometry_axis_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_axis_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_axis_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_axis_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_axis_names_get
168 * Return value: (array length=length) (transfer none): All the pseudo_axes names of the #HklEngine
171 const char **hkl_engine_pseudo_axis_names_get_binding(HklEngine *self, size_t *length)
173 *length = darray_size(self->pseudo_axis_names);
174 return &darray_item(self->pseudo_axis_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_axis_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_axis_names_get
200 * Return value: (array length=length) (transfer none): axes of the #HklEngine for the given mode.
202 const char **hkl_engine_axis_names_get_binding(const HklEngine *self,
203 HklEngineAxisNamesGet mode,
204 size_t *length)
206 const darray_string *axes = hkl_engine_axis_names_get(self, mode);
208 *length = darray_size(*axes);
210 return &darray_item(*axes, 0);
214 * hkl_engine_parameters_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_parameters_values_get
221 * Return value: (array length=len) (transfer container): list of parameters values,
222 * free the list with free when done.
224 double *hkl_engine_parameters_values_get_binding(const HklEngine *self, guint *len,
225 HklUnitEnum unit_type)
227 double *values;
228 uint i = 0;
229 HklParameter **parameter;
231 if(!self || !len || !self->mode || darray_size(self->mode->parameters) == 0)
232 return NULL;
234 *len = darray_size(self->mode->parameters);
235 values = malloc(*len * sizeof(*values));
237 darray_foreach(parameter, self->mode->parameters){
238 values[i++] = hkl_parameter_value_get(*parameter, unit_type);
241 return values;
245 * hkl_engine_pseudo_axis_values_get_binding:
246 * @self: the this ptr
247 * @len: (out caller-allocates): the length of the returned array
248 * @unit_type: the unit type (default or user) of the returned value
250 * Rename to: hkl_engine_pseudo_axis_values_get
252 * Return value: (array length=len) (transfer container): list of pseudo axes values,
253 * free the list with free when done.
255 double *hkl_engine_pseudo_axis_values_get_binding(const HklEngine *self, guint *len,
256 HklUnitEnum unit_type)
258 double *values;
259 uint i = 0;
260 HklParameter **axis;
262 if(!self || !len || darray_size(self->pseudo_axes) == 0)
263 return NULL;
265 *len = darray_size(self->pseudo_axes);
266 values = malloc(darray_size(self->pseudo_axes) * sizeof(*values));
268 darray_foreach(axis, self->pseudo_axes){
269 values[i++] = hkl_parameter_value_get(*axis, unit_type);
272 return values;
276 * hkl_engine_list_engines_get_as_gslist:
277 * @self: the this ptr
279 * Return value: (element-type HklEngine) (transfer container): list of engines,
280 * free the list with g_slist_free when done.
282 * Rename to: hkl_engine_list_engines_get
284 GSList* hkl_engine_list_engines_get_as_gslist(HklEngineList *self)
286 GSList *list = NULL;
287 HklEngine **engine;
289 darray_foreach(engine, *self){
290 list = g_slist_append(list, *engine);
293 return list;
296 /*************/
297 /* HklSample */
298 /*************/
301 * hkl_sample_reflections_get:
302 * @self: the this ptr
304 * Return value: (element-type HklSampleReflection) (transfer container): list of reflections,
305 * free the list with g_slist_free when done.
307 GSList *hkl_sample_reflections_get(const HklSample *self)
309 GSList *list = NULL;
310 HklSampleReflection *reflection;
312 list_for_each(&self->reflections, reflection, list){
313 list = g_slist_append(list, reflection);
316 return list;
320 * hkl_sample_add_reflection_binding:
321 * @self: the this ptr
322 * @geometry: the geometry of the HklSampleReflection
323 * @detector: the detector of the HklSampleReflection
324 * @h: the h coordinate
325 * @k: the k coordinate
326 * @l: the l coordinate
327 * @error: return location for a GError, or NULL
329 * Return value: (transfer none): the newly created HklSampleReflection
331 * Rename to: hkl_sample_add_reflection
333 HklSampleReflection *hkl_sample_add_reflection_binding(HklSample *self,
334 const HklGeometry *geometry,
335 const HklDetector *detector,
336 double h, double k, double l,
337 GError **error)
339 HklSampleReflection *reflection;
341 hkl_error (error == NULL || *error == NULL);
343 reflection = hkl_sample_reflection_new(geometry, detector,
344 h, k, l, error);
345 if(!reflection){
346 g_assert (error == NULL || *error != NULL);
347 return NULL;
349 g_assert (error == NULL || *error == NULL);
351 hkl_sample_add_reflection(self, reflection);
353 return reflection;