Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
utils/Property.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* Property.cc (C) 2000-2023 */
9/* */
10/* Gestion des propriétés. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/Property.h"
15
16#include "arcane/utils/Ref.h"
17#include "arcane/utils/JSONReader.h"
18#include "arcane/utils/List.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/ValueConvert.h"
21#include "arcane/utils/CheckedConvert.h"
22
23#include <cstdlib>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::properties
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34auto PropertySettingTraits<String>::
35fromJSON(const JSONValue& jv) -> InputType
36{
37 return jv.value();
38}
39
40auto PropertySettingTraits<String>::
41fromString(const String& v) -> InputType
42{
43 return v;
44}
45
46void PropertySettingTraits<String>::
47print(std::ostream& o,InputType v)
48{
49 o << v;
50}
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
55auto PropertySettingTraits<StringList>::
56fromJSON(const JSONValue& jv) -> InputType
57{
58 StringList string_list;
59 for(JSONValue jv2 : jv.valueAsArray())
60 string_list.add(jv2.value());
61 return string_list;
62}
63
64auto PropertySettingTraits<StringList>::
65fromString(const String& v) -> InputType
66{
67 StringList string_list;
68 string_list.add(v);
69 return string_list;
70}
71
72void PropertySettingTraits<StringList>::
73print(std::ostream& o,StringCollection v)
74{
75 bool is_not_first = false;
76 for( String x : v ){
77 if (is_not_first)
78 o << ',';
79 o << x;
80 is_not_first = true;
81 }
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
87auto PropertySettingTraits<bool>::
88fromJSON(const JSONValue& jv) -> InputType
89{
90 return jv.valueAsInt64()!=0;
91}
92
93auto PropertySettingTraits<bool>::
94fromString(const String& v) -> InputType
95{
96 if (v=="0" || v=="false")
97 return false;
98 if (v=="1" || v=="true")
99 return true;
100 ARCANE_FATAL("Can not convert '{0}' to type bool "
101 "(valid values are '0', '1', 'true', 'false')",v);
102}
103
104void PropertySettingTraits<bool>::
105print(std::ostream& o,InputType v)
106{
107 o << v;
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113auto PropertySettingTraits<Int64>::
114fromJSON(const JSONValue& jv) -> InputType
115{
116 return jv.valueAsInt64();
117}
118
119auto PropertySettingTraits<Int64>::
120fromString(const String& v) -> InputType
121{
122 Int64 read_value = 0;
123 bool is_bad = builtInGetValue(read_value,v);
124 if (is_bad)
125 ARCANE_FATAL("Can not convert '{0}' to type 'Int64' ",v);
126 return read_value;
127}
128
129void PropertySettingTraits<Int64>::
130print(std::ostream& o,InputType v)
131{
132 o << v;
133}
134
135/*---------------------------------------------------------------------------*/
136/*---------------------------------------------------------------------------*/
137
138auto PropertySettingTraits<Int32>::
139fromJSON(const JSONValue& jv) -> InputType
140{
141 return CheckedConvert::toInt32(jv.valueAsInt64());
142}
143
144auto PropertySettingTraits<Int32>::
145fromString(const String& v) -> InputType
146{
147 Int32 read_value = 0;
148 bool is_bad = builtInGetValue(read_value,v);
149 if (is_bad)
150 ARCANE_FATAL("Can not convert '{0}' to type 'Int32' ",v);
151 return read_value;
152}
153
154void PropertySettingTraits<Int32>::
155print(std::ostream& o,InputType v)
156{
157 o << v;
158}
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
166namespace
167{
168PropertySettingsRegisterer* global_arcane_first_registerer = nullptr;
169Integer global_arcane_nb_registerer = 0;
170}
171
172PropertySettingsRegisterer::
173PropertySettingsRegisterer(CreateFunc func,CreateBuildInfoFunc, const char* name) ARCANE_NOEXCEPT
174: m_name(name)
175, m_create_func(func)
176{
177 _init();
178}
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183void PropertySettingsRegisterer::
184_init()
185{
186 if (global_arcane_first_registerer==nullptr){
187 global_arcane_first_registerer = this;
188 _setPreviousRegisterer(nullptr);
189 _setNextRegisterer(nullptr);
190 }
191 else{
192 auto* next = global_arcane_first_registerer->nextRegisterer();
193 _setNextRegisterer(global_arcane_first_registerer);
194 global_arcane_first_registerer = this;
195 if (next)
196 next->_setPreviousRegisterer(this);
197 }
198 ++global_arcane_nb_registerer;
199
200 { // Check integrity
201 auto* p = global_arcane_first_registerer;
202 Integer count = global_arcane_nb_registerer;
203 while (p && count > 0) {
204 p = p->nextRegisterer();
205 --count;
206 }
207 if (p) {
208 std::cerr << "Arcane Fatal Error: Registerer '" << m_name
209 << "' conflict in registerer registration\n";
210 std::abort();
211 }
212 else if (count > 0) {
213 cout << "Arcane Fatal Error: Registerer '" << m_name
214 << "' breaks registerer registration (inconsistent shortcut)\n";
215 std::abort();
216 }
217 }
218}
219
220/*---------------------------------------------------------------------------*/
221/*---------------------------------------------------------------------------*/
222
228
229/*---------------------------------------------------------------------------*/
230/*---------------------------------------------------------------------------*/
231
237
238/*---------------------------------------------------------------------------*/
239/*---------------------------------------------------------------------------*/
240
241Ref<IPropertySettingsInfo> PropertySettingsRegisterer::
242createSettingsInfoRef() const
243{
244 IPropertySettingsInfo* s = nullptr;
245 if (m_create_func){
247 s = (m_create_func)(sbi);
248 }
249 return makeRef(s);
250}
251
252/*---------------------------------------------------------------------------*/
253/*---------------------------------------------------------------------------*/
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258void
259visitAllRegisteredProperties(IPropertyVisitor* visitor)
260{
262 while (rs){
263 Ref<IPropertySettingsInfo> si = rs->createSettingsInfoRef();
264 si->applyVisitor(visitor);
265 rs = rs->nextRegisterer();
266 };
267}
268
269/*---------------------------------------------------------------------------*/
270/*---------------------------------------------------------------------------*/
271
272} // End namespace Arcane::properties
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Enregistreur de paramètres de propriétés.
Definition Property.h:386
const char * m_name
Nom de l'enregistreur.
Definition Property.h:436
static PropertySettingsRegisterer * firstRegisterer()
Accès au premier élément de la chaine d'enregistreur.
void _setPreviousRegisterer(PropertySettingsRegisterer *s)
Positionne l'enregistreur précédent.
Definition Property.h:421
static Integer nbRegisterer()
Nombre d'enregisteur dans la chaîne.
CreateFunc m_create_func
Fonction de création.
Definition Property.h:438
void _setNextRegisterer(PropertySettingsRegisterer *s)
Positionne l'enregistreur suivant.
Definition Property.h:424
Int32 toInt32(Int64 v)
Converti un Int64 en un Int32.
void add(ArrayView< T > lhs, ConstArrayView< T > copy_array)
Ajoute le tableau copy_array dans l'instance.
Definition MathUtils.h:885
Collection< String > StringCollection
Collection de chaînes de caractères.
Definition UtilsTypes.h:664
List< String > StringList
Tableau de chaînes de caractères unicode.
Definition UtilsTypes.h:667
Int32 Integer
Type représentant un entier.