programmer's documentation
cs_gui_util.h
Go to the documentation of this file.
1 #ifndef __CS_GUI_UTIL_H__
2 #define __CS_GUI_UTIL_H__
3 
4 /*============================================================================
5  * Management of the GUI parameters file: xpath request and utilities
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2015 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 /*----------------------------------------------------------------------------
31  * Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_base.h"
35 
36 /*----------------------------------------------------------------------------*/
37 
39 
40 /*============================================================================
41  * Public function prototypes for Fortran API
42  *============================================================================*/
43 
44 /*-----------------------------------------------------------------------------
45  * Return the information if the requested xml file is missing
46  *
47  * Fortran Interface:
48  *
49  * SUBROUTINE CSIHMP (IIHMPR)
50  * *****************
51  *
52  * INTEGER IIHMPR <-- 1 if the file exists, 0 otherwise
53  *----------------------------------------------------------------------------*/
54 
55 void
56 CS_PROCF (csihmp, CSIHMP) (int *const iihmpr);
57 
58 /*=============================================================================
59  * Public function prototypes
60  *============================================================================*/
61 
62 /*-----------------------------------------------------------------------------
63  * Indicate if an XML file has been loaded
64  *
65  * returns:
66  * 1 if an XML file has been loaded, 0 otherwise
67  *----------------------------------------------------------------------------*/
68 
69 int
71 
72 /*----------------------------------------------------------------------------
73  * Load the XML file in memory.
74  *
75  * parameter:
76  * filename <-- XML file containing the parameters
77  *
78  * returns:
79  * error code (0 in case of success)
80  *----------------------------------------------------------------------------*/
81 
82 int
83 cs_gui_load_file(const char *filename);
84 
85 /*-----------------------------------------------------------------------------
86  * Check the xml file version.
87  *----------------------------------------------------------------------------*/
88 
89 void
91 
92 /*----------------------------------------------------------------------------
93  * Initialize the path for the xpath request with the root node.
94  *
95  * returns:
96  * the root path
97  *----------------------------------------------------------------------------*/
98 
99 char*
100 cs_xpath_init_path(void);
101 
102 /*----------------------------------------------------------------------------
103  * Initialize the path for the xpath request with a short way.
104  *
105  * returns:
106  * the short path.
107  *----------------------------------------------------------------------------*/
108 
109 char*
110 cs_xpath_short_path(void);
111 
112 /*----------------------------------------------------------------------------
113  * Add all elements (*) to the path.
114  *
115  * parameter:
116  * path <--> path for the xpath request
117  *----------------------------------------------------------------------------*/
118 
119 void
120 cs_xpath_add_all_elements(char **path);
121 
122 /*----------------------------------------------------------------------------
123  * Add an element (i.e. markup's label) to the path.
124  *
125  * parameters:
126  * path <-> path for the xpath request
127  * element <-- label of the new element in the path
128  *----------------------------------------------------------------------------*/
129 
130 void
131 cs_xpath_add_element(char **path,
132  const char *element);
133 
134 /*----------------------------------------------------------------------------
135  * Add a list of elements (i.e. markup's label) to the path.
136  *
137  * parameters:
138  * path <-> path for the xpath request
139  * nbr <-- size of the labels list
140  * ... <-- list of labels of new elements in the path
141  *----------------------------------------------------------------------------*/
142 
143 void
144 cs_xpath_add_elements(char **path,
145  int nbr,
146  ...);
147 
148 /*----------------------------------------------------------------------------
149  * Add an element's attribute to the path.
150  *
151  * parameters:
152  * path <-> path for the xpath request
153  * attribute_name <-- label of the new attribute in the path
154  *----------------------------------------------------------------------------*/
155 
156 void
157 cs_xpath_add_attribute(char **path,
158  const char *attribute_name);
159 
160 /*----------------------------------------------------------------------------
161  * Add the i'th element to the path.
162  *
163  * parameters:
164  * path <-> path for the xpath request
165  * element <-- label of the new element in the path
166  * num <-- number of the element's markup
167  *----------------------------------------------------------------------------*/
168 
169 void
170 cs_xpath_add_element_num(char **path,
171  const char *element,
172  int num);
173 
174 /*----------------------------------------------------------------------------
175  * Add a test on a value associated to an attribute to the path.
176  *
177  * parameters:
178  * path <-> path for the xpath request
179  * attribute_type <-- label of the attribute for the test in the path
180  * attribute_value <-- value of the attribute for the test in the path
181  *----------------------------------------------------------------------------*/
182 
183 void
184 cs_xpath_add_test_attribute(char **path,
185  const char *attribute_type,
186  const char *attribute_value);
187 
188 /*----------------------------------------------------------------------------
189  * Add the 'text()' xpath function to the path.
190  *
191  * parameters:
192  * path <-> path for the xpath request
193  *----------------------------------------------------------------------------*/
194 
195 void
196 cs_xpath_add_function_text(char **path);
197 
198 /*----------------------------------------------------------------------------
199  * Return a list of attribute node names from the xpath request in an array.
200  *
201  * Example: from <a attr="c"/><b attr="d"/> return {c,d}
202  *
203  * parameters:
204  * path <-- path for the xpath request
205  * size --> array size
206  *----------------------------------------------------------------------------*/
207 
208 char**
209 cs_gui_get_attribute_values(char *path,
210  int *size);
211 
212 /*----------------------------------------------------------------------------
213  * Return the value of an element's attribute.
214  *
215  * Example: from <a b="c"/> return c
216  *
217  * parameters:
218  * path <-- path for the xpath request
219  *----------------------------------------------------------------------------*/
220 
221 char*
222 cs_gui_get_attribute_value(char *path);
223 
224 /*----------------------------------------------------------------------------
225  * Return a list of children nodes name from the xpath request in an array.
226  *
227  * Example: from <a>3<\a><b>4<\b> return {a,b}
228  *
229  * parameters:
230  * path <-- path for the xpath request
231  * size --> array size
232  *
233  * returns:
234  * node's names
235  *----------------------------------------------------------------------------*/
236 
237 char**
238 cs_gui_get_nodes_name(char *path,
239  int *size);
240 
241 /*----------------------------------------------------------------------------
242  * Return a single node's name from the xpath request.
243  *
244  * parameter:
245  * path <-- path for the xpath request
246  *
247  * returns:
248  * node's name
249  *----------------------------------------------------------------------------*/
250 
251 char*
252 cs_gui_get_node_name(char *path);
253 
254 /*----------------------------------------------------------------------------
255  * Return a list of children text nodes from the xpath request in an array.
256  *
257  * Example: from <a>3<\a><a>4<\a> return {3,4}
258  *
259  * parameters:
260  * path <-- path for the xpath request
261  * size --> array size
262  *----------------------------------------------------------------------------*/
263 
264 char**
265 cs_gui_get_text_values(char *path,
266  int *size);
267 
268 /*----------------------------------------------------------------------------
269  * Return a single child text node from the xpath request.
270  *
271  * parameter:
272  * path <-- path for the xpath request
273  *
274  * returns:
275  * child node based on request
276  *----------------------------------------------------------------------------*/
277 
278 char*
279 cs_gui_get_text_value(char *path);
280 
281 /*----------------------------------------------------------------------------
282  * Query a double value parameter.
283  *
284  * parameters:
285  * path <-- path for the xpath request
286  * value --> double result of the xpath request
287  *
288  * returns:
289  * 1 if the xpath request succeeded, 0 otherwise.
290  *----------------------------------------------------------------------------*/
291 
292 int
293 cs_gui_get_double(char *path,
294  double *value);
295 
296 /*----------------------------------------------------------------------------
297  * Query an integer value parameter.
298  *
299  * parameters:
300  * path <-- path for the xpath request
301  * value --> double result of the xpath request
302  *
303  * returns:
304  * 1 if the xpath request succeeded, 0 otherwise.
305  *----------------------------------------------------------------------------*/
306 
307 int
308 cs_gui_get_int(char *path,
309  int *value);
310 
311 /*----------------------------------------------------------------------------
312  * Query the number of elements (i.e. the number of xml markups)
313  * from a xpath request.
314  *
315  * Example: from <a>3<\a><a>4<\a> return 2
316  *
317  * parameters:
318  * path <-- path for the xpath request
319  *
320  * returns:
321  * the number of elements in xpath request
322  *----------------------------------------------------------------------------*/
323 
324 int
325 cs_gui_get_nb_element(char *path);
326 
327 /*----------------------------------------------------------------------------
328  * Query the maximum integer value from an xpath request result list.
329  *
330  * Example: from <a>3<\a><a>4<\a> return 4
331  *
332  * parameters:
333  * path <-- path for the xpath request
334  *
335  * returns:
336  * the maximum integer value in the list
337  *----------------------------------------------------------------------------*/
338 
339 int
340 cs_gui_get_max_value(char *path);
341 
342 /*-----------------------------------------------------------------------------
343  * Evaluate the "status" attribute value.
344  *
345  * parameter:
346  * path <-- path for the xpath request
347  * result --> status="on" return 1, status="off" return 0
348  *
349  * returns:
350  * 1 if the xpath request has succeeded, 0 otherwise
351  *----------------------------------------------------------------------------*/
352 
353 int
354 cs_gui_get_status(char *path,
355  int *result);
356 
357 /*-----------------------------------------------------------------------------
358  * Return the xml markup quantity.
359  *
360  * parameters:
361  * markup <-- path for the markup
362  * flag <-- 1: initialize the path with the root node;
363  * 0: initialize the path with a short way
364  *
365  * returns:
366  * XML markup quantity
367  *----------------------------------------------------------------------------*/
368 
369 int
370 cs_gui_get_tag_count(const char *markup,
371  int flag);
372 
373 /*-----------------------------------------------------------------------------
374  * Return the number of characters needed to print an integer number
375  *
376  * parameters:
377  * num <-- integer number
378  *
379  * returns:
380  * number of characters required
381  *----------------------------------------------------------------------------*/
382 
383 int
384 cs_gui_characters_number(int num);
385 
386 /*-----------------------------------------------------------------------------
387  * Compare two strings.
388  *
389  * parameters:
390  * s1 <-- first string
391  * s2 <-- second string
392  *
393  * returns:
394  * 1 if the strings are equal, 0 otherwise.
395  *----------------------------------------------------------------------------*/
396 
397 int
398 cs_gui_strcmp(const char *s1,
399  const char *s2);
400 
401 /*-----------------------------------------------------------------------------
402  * Copy a C string into a Fortran string.
403  *
404  * parameters:
405  * chainef <-> Fortran string
406  * chainc <-- C string
407  * lstrF <-- maximum length of the Fortran string
408  *----------------------------------------------------------------------------*/
409 
410 void
411 cs_gui_strcpy_c2f(char *chainef,
412  const char *chainec,
413  const int lstrF);
414 
415 /*-----------------------------------------------------------------------------
416  * Test if 2 real values are equal (avoiding compiler warnings)
417  *
418  * parameters:
419  * v1 <-- first value to compare
420  * v2 <-- second value to compare
421  *
422  * returns:
423  * 1 if values are equal, 0 otherwise
424  *----------------------------------------------------------------------------*/
425 
426 int
428  cs_real_t v2);
429 
430 /*-----------------------------------------------------------------------------
431  * Add timing increment to global MEI time counter.
432  *
433  * parameters:
434  * t <-- timing increment to add
435  *----------------------------------------------------------------------------*/
436 
437 void
438 cs_gui_add_mei_time(double t);
439 
440 /*-----------------------------------------------------------------------------
441  * Get cumulative global MEI time counter.
442  *
443  * returns:
444  * cumulative global MEI time counter
445  *----------------------------------------------------------------------------*/
446 
447 double
449 
450 /*----------------------------------------------------------------------------*/
451 
453 
454 #endif /* __CS_GUI_UTIL_H__ */
int cs_gui_strcmp(const char *s1, const char *s2)
Definition: cs_gui_util.c:1112
int cs_gui_load_file(const char *filename)
Definition: cs_gui_util.c:159
char ** cs_gui_get_attribute_values(char *path, int *size)
Definition: cs_gui_util.c:541
int cs_gui_get_max_value(char *path)
Definition: cs_gui_util.c:949
char * cs_xpath_short_path(void)
Definition: cs_gui_util.c:317
char * cs_xpath_init_path(void)
Definition: cs_gui_util.c:287
#define BEGIN_C_DECLS
Definition: cs_defs.h:429
int cs_gui_is_equal_real(cs_real_t v1, cs_real_t v2)
Definition: cs_gui_util.c:1158
char * cs_gui_get_text_value(char *path)
Definition: cs_gui_util.c:806
void cs_xpath_add_test_attribute(char **path, const char *attribute_type, const char *attribute_value)
Definition: cs_gui_util.c:488
void cs_gui_strcpy_c2f(char *chainef, const char *chainec, const int lstrF)
Definition: cs_gui_util.c:1131
void cs_gui_add_mei_time(double t)
Definition: cs_gui_util.c:1183
void cs_xpath_add_element_num(char **path, const char *element, int num)
Definition: cs_gui_util.c:445
void cs_xpath_add_attribute(char **path, const char *attribute_name)
Definition: cs_gui_util.c:421
int cs_gui_get_nb_element(char *path)
Definition: cs_gui_util.c:906
int cs_gui_get_int(char *path, int *value)
Definition: cs_gui_util.c:874
void cs_xpath_add_function_text(char **path)
Definition: cs_gui_util.c:519
void cs_gui_check_version(void)
Definition: cs_gui_util.c:234
int cs_gui_get_double(char *path, double *value)
Definition: cs_gui_util.c:844
void cs_xpath_add_element(char **path, const char *element)
Definition: cs_gui_util.c:355
integer, save iihmpr
indicator of the use of the GUI (We could avoid this module by querying a C structure) ...
Definition: ihmpre.f90:44
int cs_gui_file_is_loaded(void)
Definition: cs_gui_util.c:138
char ** cs_gui_get_text_values(char *path, int *size)
Definition: cs_gui_util.c:741
int cs_gui_get_tag_count(const char *markup, int flag)
Definition: cs_gui_util.c:1053
void cs_xpath_add_all_elements(char **path)
Definition: cs_gui_util.c:335
double cs_gui_get_mei_times(void)
Definition: cs_gui_util.c:1196
int cs_gui_characters_number(int num)
Definition: cs_gui_util.c:1084
char * cs_gui_get_node_name(char *path)
Definition: cs_gui_util.c:704
void cs_xpath_add_elements(char **path, int nbr,...)
Definition: cs_gui_util.c:382
void csihmp(int *const iihmpr)
Definition: cs_gui_util.c:114
#define END_C_DECLS
Definition: cs_defs.h:430
double cs_real_t
Definition: cs_defs.h:296
#define CS_PROCF(x, y)
Definition: cs_defs.h:453
char ** cs_gui_get_nodes_name(char *path, int *size)
Definition: cs_gui_util.c:643
Definition: cs_field_pointer.h:93
int cs_gui_get_status(char *path, int *result)
Definition: cs_gui_util.c:1013
char * cs_gui_get_attribute_value(char *path)
Definition: cs_gui_util.c:606