Arcane  v3.16.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ParameterCaseOption.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* ParameterCaseOption.cc (C) 2000-2025 */
9/* */
10/* Classe permettant d'interroger les paramètres pour savoir si des options */
11/* du jeu de données doivent être modifiées par ceux-ci. */
12/*---------------------------------------------------------------------------*/
13/*---------------------------------------------------------------------------*/
14
15#include "arcane/utils/ParameterCaseOption.h"
16
17#include "arcane/utils/ApplicationInfo.h"
18#include "arcane/utils/ValueConvert.h"
19#include "arcane/utils/Array.h"
20#include "arcane/utils/FatalErrorException.h"
21#include "arcane/utils/ITraceMng.h"
22#include "arcane/utils/Ref.h"
23
24#include "arcane/utils/internal/ParameterOption.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35ParameterCaseOption::
36ParameterCaseOption(ParameterOptionElementsCollection* parameter_options, const String& lang)
37: m_is_fr(lang == "fr")
38, m_lines(parameter_options) // On ne récupère pas la propriété.
39{}
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44String ParameterCaseOption::
45getParameterOrNull(const String& xpath_before_index, const String& xpath_after_index, Integer index) const
46{
47 if (index <= 0) {
48 ARCANE_FATAL("Index in XML start at 1");
49 }
50
51 ParameterOptionAddr addr{ _removeUselessPartInXpath(xpath_before_index.view()) };
52 addr.lastAddrPart()->setIndex(index);
53 addr.addAddrPart(new ParameterOptionAddrPart(xpath_after_index.view()));
54
55 std::optional<StringView> value = m_lines->value(addr);
56 if (value.has_value())
57 return value.value();
58 return {};
59}
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64String ParameterCaseOption::
65getParameterOrNull(const String& xpath_before_index, Integer index, bool allow_elems_after_index) const
66{
67 if (index <= 0) {
68 ARCANE_FATAL("Index in XML start at 1");
69 }
70 ParameterOptionAddr addr{ _removeUselessPartInXpath(xpath_before_index.view()) };
71 addr.lastAddrPart()->setIndex(index);
72 if (allow_elems_after_index) {
73 addr.addAddrPart(new ParameterOptionAddrPart());
74 }
75
76 std::optional<StringView> value = m_lines->value(addr);
77 if (value.has_value())
78 return value.value();
79 return {};
80}
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85String ParameterCaseOption::
86getParameterOrNull(const String& full_xpath) const
87{
88 const ParameterOptionAddr addr{ _removeUselessPartInXpath(full_xpath.view()) };
89
90 std::optional<StringView> value = m_lines->value(addr);
91 if (value.has_value())
92 return value.value();
93 return {};
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99bool ParameterCaseOption::
100exist(const String& full_xpath) const
101{
102 const ParameterOptionAddr addr{ _removeUselessPartInXpath(full_xpath.view()) };
103 return m_lines->isExistAddr(addr);
104}
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108
109bool ParameterCaseOption::
110existAnyIndex(const String& xpath_before_index, const String& xpath_after_index) const
111{
112 ParameterOptionAddr addr{ _removeUselessPartInXpath(xpath_before_index.view()) };
113 addr.lastAddrPart()->setIndex(ParameterOptionAddrPart::ANY_INDEX);
114
115 addr.addAddrPart(new ParameterOptionAddrPart(xpath_after_index.view()));
116
117 return m_lines->isExistAddr(addr);
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123bool ParameterCaseOption::
124existAnyIndex(const String& full_xpath) const
125{
126 const ParameterOptionAddr addr{ _removeUselessPartInXpath(full_xpath.view()) };
127 addr.lastAddrPart()->setIndex(ParameterOptionAddrPart::ANY_INDEX);
128
129 return m_lines->isExistAddr(addr);
130}
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135void ParameterCaseOption::
136indexesInParam(const String& xpath_before_index, const String& xpath_after_index, UniqueArray<Integer>& indexes) const
137{
138 ParameterOptionAddr addr{ _removeUselessPartInXpath(xpath_before_index.view()) };
139 addr.lastAddrPart()->setIndex(ParameterOptionAddrPart::GET_INDEX);
140 addr.addAddrPart(new ParameterOptionAddrPart(xpath_after_index.view()));
141
142 m_lines->getIndexInAddr(addr, indexes);
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148void ParameterCaseOption::
149indexesInParam(const String& xpath_before_index, UniqueArray<Integer>& indexes, bool allow_elems_after_index) const
150{
151 ParameterOptionAddr addr{ _removeUselessPartInXpath(xpath_before_index.view()) };
152 addr.lastAddrPart()->setIndex(ParameterOptionAddrPart::GET_INDEX);
153 if (allow_elems_after_index) {
154 addr.addAddrPart(new ParameterOptionAddrPart());
155 }
156
157 m_lines->getIndexInAddr(addr, indexes);
158}
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163Integer ParameterCaseOption::
164count(const String& xpath_before_index, const String& xpath_after_index) const
165{
166 ParameterOptionAddr addr{ _removeUselessPartInXpath(xpath_before_index.view()) };
167 addr.lastAddrPart()->setIndex(ParameterOptionAddrPart::ANY_INDEX);
168 addr.addAddrPart(new ParameterOptionAddrPart(xpath_after_index.view()));
169
170 return m_lines->countAddr(addr);
171}
172
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176Integer ParameterCaseOption::
177count(const String& xpath_before_index) const
178{
179 const ParameterOptionAddr addr{ _removeUselessPartInXpath(xpath_before_index.view()) };
180 addr.lastAddrPart()->setIndex(ParameterOptionAddrPart::ANY_INDEX);
181
182 return m_lines->countAddr(addr);
183}
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188/*---------------------------------------------------------------------------*/
189/*---------------------------------------------------------------------------*/
190
191inline StringView ParameterCaseOption::
192_removeUselessPartInXpath(StringView xpath) const
193{
194 if (m_is_fr)
195 return xpath.subView(6);
196 return xpath.subView(7);
197}
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
202} // End namespace Arcane
203
204/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue sur une chaîne de caractères UTF-8.
Definition StringView.h:47
StringView subView(Int64 pos) const
Sous-chaîne commençant à la position pos.
Definition StringView.cc:37
Chaîne de caractères unicode.
StringView view() const
Retourne une vue sur la chaîne actuelle.
Definition String.cc:367
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.