Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ConfigurationReader.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ConfigurationReader.cc (C) 2000-2023 */
9/* */
10/* Configuration file readers. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/impl/ConfigurationReader.h"
15#include "arcane/utils/JSONReader.h"
16#include "arcane/core/IConfiguration.h"
17#include "arcane/core/XmlNode.h"
18#include "arcane/core/XmlNodeList.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
30addValuesFromXmlNode(const XmlNode& root_elem, Integer priority)
31{
32 UniqueArray<String> all_names;
33
34 XmlNodeList sections = root_elem.children("add");
35 for (Integer i = 0, n = sections.size(); i < n; ++i) {
36 XmlNode sec_node = sections[i];
37
38 String sec_name = sec_node.attrValue("name");
39 String sec_value = sec_node.attrValue("value");
40
41 if (sec_name.null()) {
42 pwarning() << "Missing 'name' attribute in <section> in configuration file";
43 continue;
44 }
45
46 if (sec_value.null()) {
47 pwarning() << "Missing 'value' attribute in <section> in configuration file";
48 continue;
49 }
50 //info() << "GET CONFIG name=" << sec_name << " value=" << sec_value;
51
52 all_names.clear();
53 sec_name.split(all_names, '.');
54 m_configuration->addValue(sec_name, sec_value, priority);
55 }
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61void ConfigurationReader::
62_addValuesFromJSON(const JSONValue& jv, Integer priority, const String& base_name)
63{
64 for (JSONKeyValue v : jv.keyValueChildren()) {
65 String name = v.name();
66 JSONValue value = v.value();
67 if (value.isObject()) {
68 _addValuesFromJSON(value, priority, base_name + name + ".");
69 }
70 else if (value.isArray()) {
71 // Does not process arrays for now because they are
72 // not supported in the configuration.
73 }
74 else {
75 String v_value = value.value();
76 //info() << "B=" << base_name << " N=" << name << " V=" << v_value;
77 m_configuration->addValue(base_name + name, v_value, priority);
78 }
79 }
80}
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
86addValuesFromJSON(const JSONValue& jv, Integer priority)
87{
88 _addValuesFromJSON(jv, priority, String());
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94} // End namespace Arcane
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
void clear()
Removes the elements from the array.
void addValuesFromXmlNode(const XmlNode &element, Integer priority)
Adds values to the configuration.
void addValuesFromJSON(const JSONValue &jv, Integer priority)
Adds values to the configuration.
Represents a (key,value) pair of JSON.
String value() const
Value in String format. The returned string is null if 'null()' is true.
bool null() const
Returns true if the string is null.
Definition String.cc:306
void split(StringContainer &str_array, char c) const
Splits the string based on the character c.
TraceMessage pwarning() const
1D data vector with value semantics (STL style).
List of nodes of a DOM tree.
Definition XmlNodeList.h:36
Node of a DOM tree.
Definition XmlNode.h:51
String attrValue(const String &name, bool throw_exception=false) const
Value of attribute name.
Definition XmlNode.cc:234
XmlNodeList children(const String &name) const
Set of child nodes of this node having the name name.
Definition XmlNode.cc:102
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.