9.2
general documentation
cs_tree.h
Go to the documentation of this file.
1#ifndef CS_TREE_H
2#define CS_TREE_H
3
4/*============================================================================
5 * Tree structure used to store data and settings.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 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#include "base/cs_defs.h"
31
32/*----------------------------------------------------------------------------
33 * Local headers
34 *----------------------------------------------------------------------------*/
35
36#include "base/cs_base.h"
37#include "base/cs_log.h"
38
39/*============================================================================
40 * Macro definitions
41 *============================================================================*/
42
43/* Set of bit masks to tune finely the behavior of a node.
44 By default node value is assumed to be a string.
45 */
46
47#define CS_TREE_NODE_CHAR (1 << 0) /* 1: value is a character string */
48#define CS_TREE_NODE_INT (1 << 1) /* 2: value is an integer */
49#define CS_TREE_NODE_REAL (1 << 2) /* 4: value is a cs_real_t */
50#define CS_TREE_NODE_BOOL (1 << 3) /* 8: value is a bool */
51
52#define CS_TREE_NODE_TAG (1 << 4) /* 16: node is a tag
53 (metadata for XML conversion) */
54
55/*============================================================================
56 * Type definitions
57 *============================================================================*/
58
59typedef struct _cs_tree_node_t cs_tree_node_t;
61struct _cs_tree_node_t {
63 char *name; /* name of the node */
64 char *desc; /* null or short description/help about this node */
65 int flag; /* metadata used to specify the node behavior */
67 void *value; /* value related to this node. Cast on-the-fly */
68 int size; /* size > 1 if it is an array */
69
70 /* Pointers to other nodes to allow an easy navigation among the tree */
72 cs_tree_node_t *parent; /* Pointer to the parent node or null if root */
73 cs_tree_node_t *children; /* Pointer to the first child or null */
74 cs_tree_node_t *prev; /* Pointer to a previous node sharing the same
75 parent or null if this is the first child */
76 cs_tree_node_t *next; /* Pointer to a next node sharing the same parent
77 or null if there is no next node */
78
79};
80
81/*============================================================================
82 * Public function prototypes
83 *============================================================================*/
84
85/*----------------------------------------------------------------------------*/
86/*
87 * \brief Create an empty node.
88 *
89 * Only the name is assigned if given
90 *
91 * \param[in] name name of the node, or null
92 *
93 * \return pointer to a new allocated cs_tree_node_t structure
94 */
95/*----------------------------------------------------------------------------*/
96
97cs_tree_node_t *
98cs_tree_node_create(const char *name);
99
100/*----------------------------------------------------------------------------*/
101/*
102 * \brief Free a branch in a tree starting from a node.
103 *
104 * If the node is the root of the tree, the whole tree is freed.
105 *
106 * \param[in, out] pnode pointer to a pointer to a cs_tree_node_t to free
107 */
108/*----------------------------------------------------------------------------*/
109
110void
111cs_tree_node_free(cs_tree_node_t **pnode);
112
113/*----------------------------------------------------------------------------*/
114/*
115 * \brief Name or rename a node.
116 *
117 * \param[in, out] node pointer to a cs_tree_node_t to modify
118 * \param[in] name name to set
119 */
120/*----------------------------------------------------------------------------*/
121
122void
123cs_tree_node_set_name(cs_tree_node_t *node,
124 const char *name);
125
126/*----------------------------------------------------------------------------*/
127/*
128 * \brief Return a child node with a given name.
129*
130 * The child node must be located directly under the given node (i.e. it is
131 * a child, not a grand-child or beyond).
132 *
133 * This function is similar to \ref cs_tree_get_node, but is simpler
134 * (albeit more restricted in scope) and may be faster in cases where
135 * one level of the tree is searched at a time.
136 *
137 * In case of multiple children sharing the given name, the first such node
138 * is returned.
139 *
140 * \param[in] node pointer to the given node
141 * \param[in] name name of child node
142 *
143 * \return string value associated to tag if found, or null
144 */
145/*----------------------------------------------------------------------------*/
146
147cs_tree_node_t *
148cs_tree_node_get_child(cs_tree_node_t *node,
149 const char *name);
150
151/*----------------------------------------------------------------------------*/
152/*
153 * \brief Return the next sibling node with the same name (type)
154 * as a given node.
155 *
156 * The first node of a series is obtained using \ref cs_tree_get_node.
157 *
158 * \param[in] node pointer to the starting node
159 *
160 * \return pointer to next sibling node with same name, or null
161 */
162/*----------------------------------------------------------------------------*/
163
164cs_tree_node_t *
165cs_tree_node_get_next_of_name(cs_tree_node_t *node);
166
167/*----------------------------------------------------------------------------*/
168/*
169 * \brief Search for a child node (used as a tag) with a given name,
170 * and return its associated string value.
171 *
172 * The child node must be located directly under the given node (i.e. it is
173 * a child, not a grand-child or beyond).
174 *
175 * If the child "tag" node does not exist, a null pointer is returned.
176 *
177 * The CS_TREE_NODE_TAG flag is set for child nodes accessed by this function.
178 * It is currently only relevant for possible mapping to XML.
179 *
180 * \param[in] node pointer to the given node
181 * \param[in] tag name of child node used as tag
182 *
183 * \return string value associated to tag if found, or null
184 */
185/*----------------------------------------------------------------------------*/
186
187const char *
188cs_tree_node_get_tag(cs_tree_node_t *node,
189 const char *tag);
190
191/*----------------------------------------------------------------------------*/
192/*
193 * \brief Assign a tag to a given node.
194 *
195 * A tag is simply a string-valued child node.
196 *
197 * The CS_TREE_NODE_TAG flag is also set for this child.
198 * It is currently only relevant for possible mapping to XML.
199 *
200 * \param[in, out] node pointer to the given node
201 * \param[in] tag name of child node used as tag
202 * \param[in] tag_str character string to be copied to tag
203 */
204/*----------------------------------------------------------------------------*/
205
206void
207cs_tree_node_set_tag(cs_tree_node_t *node,
208 const char *tag,
209 const char *tag_str);
210
211/*----------------------------------------------------------------------------*/
212/*
213 * \brief Return a character string value associated to a node if present.
214 *
215 * If the node was never accessed before and the value type was not defined,
216 * it is set to CS_TREE_NODE_CHAR. If it was previously converted to
217 * a different type, an error is returned.
218 *
219 * \param[in] node pointer to a cs_tree_node_t to access, or null
220 *
221 * \return associated string, or null
222 */
223/*----------------------------------------------------------------------------*/
224
225const char *
226cs_tree_node_get_value_str(cs_tree_node_t *node);
227
228/*----------------------------------------------------------------------------*/
229/*
230 * \brief Assign a character string value to a node.
231 *
232 * The assigned value is copied to the node.
233 *
234 * \param[in, out] node pointer to a cs_tree_node_t to modify
235 * \param[in] val pointer to character string
236 */
237/*----------------------------------------------------------------------------*/
238
239void
240cs_tree_node_set_value_str(cs_tree_node_t *node,
241 const char *val);
242
243/*----------------------------------------------------------------------------*/
244/*
245 * \brief Return array of boolean values associated to a node if present.
246 *
247 * If the value type was not defined, or defined as a string, values are
248 * converted and the type flag set to CS_TREE_NODE_BOOL. If it was previously
249 * accessed (and converted) using a different type, an error is returned.
250 *
251 * The following strings (case-independent) are converted to "true":
252 * "true", "yes", "on", "1".
253 * All other strings are converted to "false".
254 *
255 * \param[in] node pointer to a cs_tree_node_t to access, or null
256 *
257 * \return pointer to associated values, or null
258 */
259/*----------------------------------------------------------------------------*/
260
261const bool *
262cs_tree_node_get_values_bool(cs_tree_node_t *node);
263
264/*----------------------------------------------------------------------------*/
265/*
266 * \brief Assign an array of boolean values to node.
267 *
268 * The assigned array is copied to the node.
269 *
270 * \param[in, out] node pointer to a cs_tree_node_t to modify
271 * \param[in] n number of elements in val
272 * \param[in] val array of boolean
273 */
274/*----------------------------------------------------------------------------*/
275
276void
277cs_tree_node_set_values_bool(cs_tree_node_t *node,
278 int n,
279 const bool *val);
280
281/*----------------------------------------------------------------------------*/
282/*
283 * \brief Assign a single boolean value to a node.
284 *
285 * \param[in, out] node pointer to a cs_tree_node_t to modify
286 * \param[in] val boolean value to assign
287 */
288/*----------------------------------------------------------------------------*/
289
290inline void
291cs_tree_node_set_value_bool(cs_tree_node_t *node,
292 bool val)
293{
294 cs_tree_node_set_values_bool(node, 1, &val);
295}
296
297/*----------------------------------------------------------------------------*/
298/*
299 * \brief Return an array of integer values associated to a node if present.
300 *
301 * If the value type was not defined, or defined as a string, values are
302 * converted and the type flag set to CS_TREE_NODE_INT. If it was previously
303 * accessed (and converted) using a different type, an error is returned.
304 *
305 * \param[in] node pointer to a cs_tree_node_t to access, or null
306 *
307 * \return pointer to associated array, or null
308 */
309/*----------------------------------------------------------------------------*/
310
311const int *
312cs_tree_node_get_values_int(cs_tree_node_t *node);
313
314/*----------------------------------------------------------------------------*/
315/*
316 * \brief Assign an array of integer values to a node.
317 *
318 * The array values are copied to the node.
319 *
320 * \param[in, out] node pointer to a cs_tree_node_t to modify
321 * \param[in] n number of elements in val
322 * \param[in] val array of integers
323 */
324/*----------------------------------------------------------------------------*/
325
326void
327cs_tree_node_set_values_int(cs_tree_node_t *node,
328 int n,
329 const int *val);
330
331/*----------------------------------------------------------------------------*/
332/*
333 * \brief Assign a single integer value to a node.
334 *
335 * \param[in, out] node pointer to a cs_tree_node_t to modify
336 * \param[in] val integer value to assign
337 */
338/*----------------------------------------------------------------------------*/
339
340inline void
341cs_tree_node_set_value_int(cs_tree_node_t *node,
342 int val)
343{
344 cs_tree_node_set_values_int(node, 1, &val);
345}
346
347/*----------------------------------------------------------------------------*/
348/*
349 * \brief Return an array of real values associated to a node if present.
350 *
351 * If the value type was not defined, or defined as a string, values are
352 * converted and the type flag set to CS_TREE_NODE_REAL. If it was previously
353 * accessed (and converted) using a different type, an error is returned.
354 *
355 * \param[in] node pointer to a cs_tree_node_t to access, or null
356 *
357 * \return pointer to associated array, or null
358 */
359/*----------------------------------------------------------------------------*/
360
361const cs_real_t *
362cs_tree_node_get_values_real(cs_tree_node_t *node);
363
364/*----------------------------------------------------------------------------*/
365/*
366 * \brief Assign an array of real values to a node.
367 *
368 * The array values are copied to the node.
369 *
370 * \param[in, out] node pointer to a cs_tree_node_t to modify
371 * \param[in] n number of elements in val
372 * \param[in] val array of real values
373 */
374/*----------------------------------------------------------------------------*/
375
376void
377cs_tree_node_set_values_real(cs_tree_node_t *node,
378 int n,
379 const cs_real_t *val);
380
381/*----------------------------------------------------------------------------*/
382/*
383 * \brief Assign a single real value to a node.
384 *
385 * \param[in, out] node pointer to a cs_tree_node_t to modify
386 * \param[in] val real value to assign
387 */
388/*----------------------------------------------------------------------------*/
389
390inline void
391cs_tree_node_set_value_real(cs_tree_node_t *node,
392 cs_real_t val)
393{
394 cs_tree_node_set_values_real(node, 1, &val);
395}
396
397/*----------------------------------------------------------------------------*/
398/*
399 * \brief Return a string value associated to a child node if present.
400 *
401 * The behavior is similar to that of \ref cs_tree_node_get_value_str.
402
403 * \param[in] node pointer to a cs_tree_node_t to access, or null
404 * \param[in] child_name name of child node
405 *
406 * \return pointer to associated values, or null
407 */
408/*----------------------------------------------------------------------------*/
409
410const char *
411cs_tree_node_get_child_value_str(cs_tree_node_t *node,
412 const char *child_name);
413
414/*----------------------------------------------------------------------------*/
415/*
416 * \brief Return array of boolean values associated to a child node if present.
417 *
418 * The behavior is similar to that of \ref cs_tree_node_get_values_bool.
419 *
420 * \param[in] node pointer to a cs_tree_node_t to access, or null
421 * \param[in] child_name name of child node
422 *
423 * \return pointer to associated values, or null
424 */
425/*----------------------------------------------------------------------------*/
426
427const bool *
428cs_tree_node_get_child_values_bool(cs_tree_node_t *node,
429 const char *child_name);
430
431/*----------------------------------------------------------------------------*/
432/*
433 * \brief Return an array of integer values associated to a child node
434 * if present.
435 *
436 * The behavior is similar to that of \ref cs_tree_node_get_values_int.
437 *
438 * \param[in] node pointer to a cs_tree_node_t to access, or null
439 * \param[in] child_name name of child node
440 *
441 * \return pointer to associated array, or null
442 */
443/*----------------------------------------------------------------------------*/
444
445const int *
446cs_tree_node_get_child_values_int(cs_tree_node_t *node,
447 const char *child_name);
448
449/*----------------------------------------------------------------------------*/
450/*
451 * \brief Return an array of real values associated to a child node if present.
452 *
453 * The behavior is similar to that of \ref cs_tree_node_get_values_real.
454 *
455 * \param[in] node pointer to a cs_tree_node_t to access, or null
456 * \param[in] child_name name of child node
457 *
458 * \return pointer to associated array, or null
459 */
460/*----------------------------------------------------------------------------*/
461
462const cs_real_t *
463cs_tree_node_get_child_values_real(cs_tree_node_t *node,
464 const char *child_name);
465
466/*----------------------------------------------------------------------------*/
467/*
468 * \brief Retrieve the pointer to a node with a child having a given
469 * (character string) tag value.
470 *
471 * This node is searched for among siblings of a given node sharing the
472 * same path (i.e. the same name).
473 *
474 * Using the following example tree:
475 *
476 * /
477 * section1
478 * section2
479 * entry
480 * label
481 * (value = a)
482 * entry
483 * label
484 * (value = b)
485 *
486 * Using \ref cs_tree_get_node(node, "section2/entry") will return
487 * the first node with path "section2/entry" (which has a child named
488 * "label" with value a).
489 *
490 * Using \ref cs_tree_node_get_sibling_with_tag(node, "label", "a") from that
491 * node will return the same node, while
492 * \ref cs_tree_node_get_sibling_with_tag(node, "label", "b") will return
493 * the second "section2/entry" node.
494 *
495 * This function can be called from any sibling (not necessarily the
496 * first).
497 *
498 * \param[in] node pointer to the starting node
499 * \param[in] tag name of the required "tag" child
500 * \param[in] tag_value value of the required "tag" child
501 *
502 * \return pointer to the node, or null if not found
503 */
504/*----------------------------------------------------------------------------*/
505
506cs_tree_node_t *
507cs_tree_node_get_sibling_with_tag(cs_tree_node_t *node,
508 const char *tag,
509 const char *tag_value);
510
511/*----------------------------------------------------------------------------*/
512/*
513 * \brief Dump a cs_tree_node_t structure.
514 *
515 * \param[in] log indicate which log file to use
516 * \param[in] depth shift to apply when printing
517 * \param[in] node pointer to a cs_tree_node_t to dump
518 */
519/*----------------------------------------------------------------------------*/
520
521void
523 int depth,
524 const cs_tree_node_t *node);
525
526/*----------------------------------------------------------------------------*/
527/*
528 * \brief Add a node to a tree.
529 *
530 * This node is located at "path" from the given node, with the path
531 * separator indicated by a "/".
532 *
533 * Exits on error if a node already exists on this path.
534 *
535 * \param[in, out] node pointer to the node where we start searching
536 * \param[in] path string describing the path access
537 *
538 * \return pointer to the new node
539 */
540/*----------------------------------------------------------------------------*/
541
542cs_tree_node_t *
543cs_tree_add_node(cs_tree_node_t *node,
544 const char *path);
545
546/*----------------------------------------------------------------------------*/
547/*
548 * \brief Retrieve the pointer to a node matching a given path.
549 *
550 * This node is located at "path" from the given node, with the path
551 * separator indicated by a "/".
552 *
553 * In case of multiple nodes sharing the given path, the first such node
554 * is returned.
555 *
556 * \param[in] node pointer to the node where we start searching
557 * \param[in] path string describing the path access
558 *
559 * \return pointer to the node, or null if not found
560 */
561/*----------------------------------------------------------------------------*/
562
563cs_tree_node_t *
564cs_tree_get_node(cs_tree_node_t *node,
565 const char *path);
566
567/*----------------------------------------------------------------------------*/
568/*
569 * \brief Count number of nodes sharing a given path.
570 *
571 * \param[in] node pointer to the node where we start searching
572 * \param[in] path string describing the path access
573 *
574 * \return number of nodes sharing path
575 */
576/*----------------------------------------------------------------------------*/
577
578int
579cs_tree_get_node_count(cs_tree_node_t *node,
580 const char *path);
581
582/*----------------------------------------------------------------------------*/
583/*
584 * \brief Retrieve the pointer to a node with a child having a given
585 * (character string) tag value.
586 *
587 * This node is located at "path" from the given node, with the path
588 * separator indicated by a "/".
589 *
590 * \param[in] node pointer to the node where we start searching
591 * \param[in] path string describing the path access
592 * \param[in] tag name of the required "tag" child
593 * \param[in] tag_value value of the required "tag" child
594 *
595 * \return pointer to the node, or null if not found
596 */
597/*----------------------------------------------------------------------------*/
598
599inline cs_tree_node_t *
600cs_tree_get_node_with_tag(cs_tree_node_t *node,
601 const char *path,
602 const char *tag,
603 const char *tag_value)
604{
605 cs_tree_node_t *_node = cs_tree_get_node(node, path);
606 if (_node != NULL)
607 _node = cs_tree_node_get_sibling_with_tag(_node, tag, tag_value);
608
609 return _node;
610}
611
612/*----------------------------------------------------------------------------*/
613/*
614 * \brief Retrieve the pointer to a node, adding it if not present.
615 *
616 * This node is located at "path" from the given node, with the path
617 * separator indicated by a "/".
618 *
619 * In case of multiple nodes sharing the given path, the first such node
620 * is returned.
621 *
622 * \param[in] node pointer to the node where we start searching
623 * \param[in] path string describing the path access
624 *
625 * \return pointer to the node, or null if not found
626 */
627/*----------------------------------------------------------------------------*/
628
629inline cs_tree_node_t *
630cs_tree_get_or_add_node(cs_tree_node_t *node,
631 const char *path)
632{
633 cs_tree_node_t *_node = cs_tree_get_node(node, path);
634 if (_node == NULL)
635 node = cs_tree_add_node(_node, path);
636
637 return _node;
638}
639
640/*----------------------------------------------------------------------------*/
641/*
642 * \brief Create and add a node in a tree below the given node.
643 *
644 * \param[in, out] parent pointer to the parent node
645 * \param[in] name name of the node to add
646 *
647 * \return pointer to the new node in the tree structure
648 */
649/*----------------------------------------------------------------------------*/
650
651cs_tree_node_t *
652cs_tree_add_child(cs_tree_node_t *parent,
653 const char *name);
654
655/*----------------------------------------------------------------------------*/
656/*
657 * \brief Create and add a string-valued node in a tree below the given node.
658 *
659 * This node has a string value set to val_str.
660 *
661 * \param[in, out] parent pointer to the parent node
662 * \param[in] name name of the node to add
663 * \param[in] val_str value to assign
664 *
665 * \return a pointer to the new node in the tree structure
666 */
667/*----------------------------------------------------------------------------*/
668
669inline cs_tree_node_t *
670cs_tree_add_child_str(cs_tree_node_t *parent,
671 const char *name,
672 const char *val_str)
673{
674 cs_tree_node_t *child = cs_tree_add_child(parent, name);
675 cs_tree_node_set_value_str(child, val_str);
676
677 return child;
678}
679
680/*----------------------------------------------------------------------------*/
681/*
682 * \brief Create and add a boolean-valued node in a tree below the given node.
683 *
684 * \param[in, out] parent pointer to the parent node
685 * \param[in] name name of the node to add
686 * \param[in] val value to assign
687 *
688 * \return pointer to the new node in the tree structure
689 */
690/*----------------------------------------------------------------------------*/
691
692inline cs_tree_node_t *
693cs_tree_add_child_bool(cs_tree_node_t *parent,
694 const char *name,
695 bool val)
696{
697 cs_tree_node_t *child = cs_tree_add_child(parent, name);
698 cs_tree_node_set_values_bool(child, 1, &val);
699
700 return child;
701}
702
703/*----------------------------------------------------------------------------*/
704/*
705 * \brief Create and add an integer-valued node in a tree below the given node.
706 *
707 * \param[in, out] parent pointer to the parent node
708 * \param[in] name name of the node to add
709 * \param[in] val value to assign
710 *
711 * \return pointer to the new node in the tree structure
712 */
713/*----------------------------------------------------------------------------*/
714
715inline cs_tree_node_t *
716cs_tree_add_child_int(cs_tree_node_t *parent,
717 const char *name,
718 int val)
719{
720 cs_tree_node_t *child = cs_tree_add_child(parent, name);
721 cs_tree_node_set_values_int(child, 1, &val);
722
723 return child;
724}
725
726/*----------------------------------------------------------------------------*/
727/*
728 * \brief Create and add an real-valued node in a tree below the given node.
729 *
730 * \param[in, out] parent pointer to the parent node
731 * \param[in] name name of the node to add
732 * \param[in] val value to assign
733 *
734 * \return pointer to the new node in the tree structure
735 */
736/*----------------------------------------------------------------------------*/
737
738inline cs_tree_node_t *
739cs_tree_add_child_real(cs_tree_node_t *parent,
740 const char *name,
741 cs_real_t val)
742{
743 cs_tree_node_t *child = cs_tree_add_child(parent, name);
744 cs_tree_node_set_values_real(child, 1, &val);
745
746 return child;
747}
748
749/*----------------------------------------------------------------------------*/
750/*
751 * \brief Create and add a node in a tree at the right of the given node.
752 *
753 * \param[in, out] sibling pointer to the sibling node to handle
754 * \param[in] name name of the node to add
755 *
756 * \return pointer to the new node in the tree structure
757 */
758/*----------------------------------------------------------------------------*/
759
760cs_tree_node_t *
761cs_tree_add_sibling(cs_tree_node_t *sibling,
762 const char *name);
763
764/*----------------------------------------------------------------------------*/
765/*
766 * \brief Retrieve the pointer to a node matching a given sub-path.
767 *
768 * This node is located at "path" from the given node or one of its
769 * descendants, with the path separator indicated by a "/".
770 *
771 * In case of multiple nodes sharing the given path, the first such node
772 * is returned, using a depth-first search.
773 *
774 * \param[in] root pointer to the root node where we start searching
775 * \param[in] sub_path string describing the path access
776 *
777 * \return pointer to the first matching node, or null if not found
778 */
779/*----------------------------------------------------------------------------*/
780
781cs_tree_node_t *
782cs_tree_find_node(cs_tree_node_t *root,
783 const char *sub_path);
784
785/*----------------------------------------------------------------------------*/
786/*
787 * \brief Retrieve the pointer to the next node matching a given sub-path
788 * and following a given node in a depth-first order.
789 *
790 * This node is located at "path" from the given node or one of its
791 * descendants, with the path separator indicated by a "/".
792 *
793 * If current is null, this function behaves as \ref cs_tree_find_node.
794 *
795 * \param[in] root pointer to the root node where we start searching
796 * \param[in] current pointer to the current node
797 * \param[in] sub_path string describing the path access
798 *
799 * \return pointer to the next matching node, or null if not found
800 */
801/*----------------------------------------------------------------------------*/
802
803cs_tree_node_t *
804cs_tree_find_node_next(cs_tree_node_t *root,
805 cs_tree_node_t *current,
806 const char *sub_path);
807
808/*----------------------------------------------------------------------------*/
809/*
810 * \brief Retrieve the pointer to a node's descendants matching a given name.
811 *
812 * This function is similar to \ref cs_tree_find_node,
813 * but is simpler (as it assumes a simple name instead of a more general path)
814 * and should thus be faster.
815 *
816 * In case of multiple nodes sharing the given path, the first such node
817 * is returned, using a depth-first search.
818 *
819 * \param[in] root pointer to the root node where we start searching
820 * \param[in] name node name searched for
821 *
822 * \return pointer to the first matching node, or null if not found
823 */
824/*----------------------------------------------------------------------------*/
825
826cs_tree_node_t *
827cs_tree_find_node_simple(cs_tree_node_t *root,
828 const char *name);
829
830/*----------------------------------------------------------------------------*/
831/*
832 * \brief Retrieve the pointer to the next node with a given name
833 * and following a given node in a depth-first order.
834 *
835 * This function is similar to \ref cs_tree_find_node_next,
836 * but is simpler (as it assumes a simple name instead of a more general path)
837 * and should thus be faster.
838 *
839 * If current is null, this function behaves as \ref cs_tree_find_node.
840 *
841 * \param[in] root pointer to the root node where we start searching
842 * \param[in] current pointer to the current node
843 * \param[in] name node name searched for
844 *
845 * \return pointer to the next matching node, or null if not found
846 */
847/*----------------------------------------------------------------------------*/
848
849cs_tree_node_t *
850cs_tree_find_node_next_simple(cs_tree_node_t *root,
851 cs_tree_node_t *current,
852 const char *name);
853
854/*----------------------------------------------------------------------------*/
855/*
856 * \brief Count a node's descendants matching a given sub-path.
857 *
858 * These nodes are located at "path" from the given node or one of its
859 * descendants, with the path separator indicated by a "/".
860 *
861 * \param[in] root pointer to the root node where we start searching
862 * \param[in] sub_path string describing the path access
863 *
864 * \return number of matching nodes
865 */
866/*----------------------------------------------------------------------------*/
867
868int
869cs_tree_get_sub_node_count(cs_tree_node_t *root,
870 const char *sub_path);
871
872/*----------------------------------------------------------------------------*/
873/*
874 * \brief Count a node's descendants with a given name
875 *
876 * This function is similar to \ref cs_tree_get_sub_node_count,
877 * but is simpler (as it assumes a simple name instead of a more general path)
878 * and should thus be faster.
879 *
880 * \param[in] root pointer to the root node where we start searching
881 * \param[in] name node name searched for
882 *
883 * \return number of matching nodes
884 */
885/*----------------------------------------------------------------------------*/
886
887int
888cs_tree_get_sub_node_count_simple(cs_tree_node_t *root,
889 const char *name);
890
891/*----------------------------------------------------------------------------*/
892/*
893 * \brief Dump a cs_tree_node_t structure starting from a given node
894 *
895 * \param[in] log indicate which log file to use
896 * \param[in] depth starting depth in the tree
897 * \param[in] node pointer to a cs_tree_node_t to dump
898 */
899/*----------------------------------------------------------------------------*/
900
901void
903 int depth,
904 const cs_tree_node_t *node);
905
906/*----------------------------------------------------------------------------*/
907
908#endif /* CS_TREE_H */
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
cs_log_t
Definition: cs_log.h:44
void cs_tree_node_set_name(cs_tree_node_t *node, const char *name)
Name or rename a node.
Definition: cs_tree.cpp:436
int cs_tree_get_sub_node_count(cs_tree_node_t *root, const char *sub_path)
Count a node's descendants matching a given sub-path.
Definition: cs_tree.cpp:1709
const char * cs_tree_node_get_tag(cs_tree_node_t *node, const char *tag)
Search for a child node (used as a tag) with a given name, and return its associated string value.
Definition: cs_tree.cpp:540
void cs_tree_node_set_value_bool(cs_tree_node_t *node, bool val)
Definition: cs_tree.h:290
cs_tree_node_t * cs_tree_add_child(cs_tree_node_t *parent, const char *name)
Create and add a node in a tree below the given parent node.
Definition: cs_tree.cpp:1412
void cs_tree_node_set_value_str(cs_tree_node_t *node, const char *val)
Assign a character string value to a node.
Definition: cs_tree.cpp:659
void cs_tree_node_dump(cs_log_t log, int depth, const cs_tree_node_t *node)
Dump a cs_tree_node_t structure.
Definition: cs_tree.cpp:1179
cs_tree_node_t * cs_tree_find_node_simple(cs_tree_node_t *root, const char *name)
Retrieve the pointer to a node's descendants matching a given name.
Definition: cs_tree.cpp:1611
int cs_tree_get_node_count(cs_tree_node_t *node, const char *path)
Count number of nodes sharing a given path.
Definition: cs_tree.cpp:1379
cs_tree_node_t * cs_tree_add_child_bool(cs_tree_node_t *parent, const char *name, bool val)
Definition: cs_tree.h:692
void cs_tree_dump(cs_log_t log, int depth, const cs_tree_node_t *node)
Dump a cs_tree_node_t structure starting from the node "root".
Definition: cs_tree.cpp:1764
const cs_real_t * cs_tree_node_get_values_real(cs_tree_node_t *node)
Return an array of real values associated to a node if present.
Definition: cs_tree.cpp:901
void cs_tree_node_set_tag(cs_tree_node_t *node, const char *tag, const char *tag_str)
Assign a tag to a given node.
Definition: cs_tree.cpp:595
const char * cs_tree_node_get_value_str(cs_tree_node_t *node)
Return a character string value associated to a node if present.
Definition: cs_tree.cpp:622
const int * cs_tree_node_get_child_values_int(cs_tree_node_t *node, const char *child_name)
Return an array of integer values associated to a child node if present.
Definition: cs_tree.cpp:1056
int cs_tree_get_sub_node_count_simple(cs_tree_node_t *root, const char *name)
Count a node's descendants with a given name.
Definition: cs_tree.cpp:1739
cs_tree_node_t * cs_tree_get_node_with_tag(cs_tree_node_t *node, const char *path, const char *tag, const char *tag_value)
Definition: cs_tree.h:599
void cs_tree_node_set_value_int(cs_tree_node_t *node, int val)
Definition: cs_tree.h:340
cs_tree_node_t * cs_tree_find_node_next(cs_tree_node_t *root, cs_tree_node_t *current, const char *sub_path)
Retrieve the pointer to the next node matching a given sub-path and following a given node in a depth...
Definition: cs_tree.cpp:1527
void cs_tree_node_set_values_bool(cs_tree_node_t *node, int n, const bool *val)
Assign an array of boolean values to node.
Definition: cs_tree.cpp:766
cs_tree_node_t * cs_tree_node_get_sibling_with_tag(cs_tree_node_t *node, const char *tag, const char *tag_value)
Retrieve the pointer to a node with a child having a given (character string) tag value.
Definition: cs_tree.cpp:1135
void cs_tree_node_set_values_int(cs_tree_node_t *node, int n, const int *val)
Assign an array of integer values to a node.
Definition: cs_tree.cpp:869
const cs_real_t * cs_tree_node_get_child_values_real(cs_tree_node_t *node, const char *child_name)
Return an array of real values associated to a child node if present.
Definition: cs_tree.cpp:1082
cs_tree_node_t * cs_tree_node_create(const char *name)
Create an empty node.
Definition: cs_tree.cpp:369
const bool * cs_tree_node_get_child_values_bool(cs_tree_node_t *node, const char *child_name)
Return array of boolean values associated to a child node if present.
Definition: cs_tree.cpp:1029
cs_tree_node_t * cs_tree_add_sibling(cs_tree_node_t *sibling, const char *name)
Create and add a node in a tree at the right of the given node.
Definition: cs_tree.cpp:1456
const bool * cs_tree_node_get_values_bool(cs_tree_node_t *node)
Return array of boolean values associated to a node if present.
Definition: cs_tree.cpp:695
cs_tree_node_t * cs_tree_node_get_child(cs_tree_node_t *node, const char *name)
Return a child node with a given name.
Definition: cs_tree.cpp:470
cs_tree_node_t * cs_tree_find_node(cs_tree_node_t *root, const char *sub_path)
Retrieve the pointer to a node matching a given sub-path.
Definition: cs_tree.cpp:1495
void cs_tree_node_set_value_real(cs_tree_node_t *node, cs_real_t val)
Definition: cs_tree.h:390
cs_tree_node_t * cs_tree_add_child_real(cs_tree_node_t *parent, const char *name, cs_real_t val)
Definition: cs_tree.h:738
void cs_tree_node_set_values_real(cs_tree_node_t *node, int n, const cs_real_t *val)
Assign an array of real values to a node.
Definition: cs_tree.cpp:972
cs_tree_node_t * cs_tree_find_node_next_simple(cs_tree_node_t *root, cs_tree_node_t *current, const char *name)
Retrieve the pointer to the next node with a given name and following a given node in a depth-first o...
Definition: cs_tree.cpp:1644
const char * cs_tree_node_get_child_value_str(cs_tree_node_t *node, const char *child_name)
Return a string value associated to a child node if present.
Definition: cs_tree.cpp:1003
cs_tree_node_t * cs_tree_get_node(cs_tree_node_t *node, const char *path)
Retrieve the pointer to a node matching a given path.
Definition: cs_tree.cpp:1354
const int * cs_tree_node_get_values_int(cs_tree_node_t *node)
Return an array of integer values associated to a node if present.
Definition: cs_tree.cpp:798
void cs_tree_node_free(cs_tree_node_t **pnode)
Free a branch in a tree starting from a node.
Definition: cs_tree.cpp:404
cs_tree_node_t * cs_tree_add_child_str(cs_tree_node_t *parent, const char *name, const char *val_str)
Definition: cs_tree.h:669
cs_tree_node_t * cs_tree_get_or_add_node(cs_tree_node_t *node, const char *path)
Definition: cs_tree.h:629
cs_tree_node_t * cs_tree_add_node(cs_tree_node_t *node, const char *path)
Add a node to a tree.
Definition: cs_tree.cpp:1324
cs_tree_node_t * cs_tree_add_child_int(cs_tree_node_t *parent, const char *name, int val)
Definition: cs_tree.h:715
cs_tree_node_t * cs_tree_node_get_next_of_name(cs_tree_node_t *node)
Return the next sibling node with the same name (type) as a given node.
Definition: cs_tree.cpp:502
Definition: cs_tree.h:60
void * value
Definition: cs_tree.h:66
cs_tree_node_t * children
Definition: cs_tree.h:72
char * desc
Definition: cs_tree.h:63
int size
Definition: cs_tree.h:67
char * name
Definition: cs_tree.h:62
cs_tree_node_t * parent
Definition: cs_tree.h:71
cs_tree_node_t * next
Definition: cs_tree.h:75
int flag
Definition: cs_tree.h:64
cs_tree_node_t * prev
Definition: cs_tree.h:73