Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Properties.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/* Properties.cc (C) 2000-2024 */
9/* */
10/* List of properties. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/Properties.h"
15
16#include "arcane/utils/String.h"
17#include "arcane/utils/Array.h"
18#include "arcane/utils/TraceAccessor.h"
19#include "arcane/utils/TraceInfo.h"
20#include "arcane/utils/ArgumentException.h"
21#include "arcane/utils/FatalErrorException.h"
22
23#include "arcane/core/datatype/SmallVariant.h"
24#include "arcane/core/datatype/DataTypeTraits.h"
25
26#include "arcane/core/IPropertyMng.h"
27#include "arcane/core/ISerializer.h"
28
29#include <map>
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arcane
35{
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40class PropertyVariant
41{
42 public:
43
44 enum eType
45 {
46 PV_None = 0,
47
48 PV_ScalarReal = 1,
49 PV_ScalarInt32 = 2,
50 PV_ScalarInt64 = 3,
51 PV_ScalarBool = 4,
52 PV_ScalarString = 5,
53
54 PV_ArrayReal = 6,
55 PV_ArrayInt32 = 7,
56 PV_ArrayInt64 = 8,
57 PV_ArrayBool = 9,
58 PV_ArrayString = 10,
59 };
60 static const int NB_TYPE = 11;
61
62 private:
63
64 PropertyVariant()
65 : m_int32(0)
66 , m_int64(0)
67 , m_real(0)
68 , m_bool(0)
69 , m_string(0)
70 , m_is_scalar(false)
71 , m_type(PV_None)
72 {
73 }
74
75 public:
76
77 ~PropertyVariant()
78 {
79 delete m_int32;
80 delete m_int64;
81 delete m_real;
82 delete m_bool;
83 delete m_string;
84 }
85 static PropertyVariant* create(Int32ConstArrayView v)
86 {
87 PropertyVariant* p = new PropertyVariant();
88 p->m_int32 = new UniqueArray<Int32>(v);
89 p->m_type = PV_ArrayInt32;
90 return p;
91 }
92
93 static PropertyVariant* create(Int64ConstArrayView v)
94 {
95 PropertyVariant* p = new PropertyVariant();
96 p->m_int64 = new UniqueArray<Int64>(v);
97 p->m_type = PV_ArrayInt64;
98 return p;
99 }
100
101 static PropertyVariant* create(RealConstArrayView v)
102 {
103 PropertyVariant* p = new PropertyVariant();
104 p->m_real = new UniqueArray<Real>(v);
105 p->m_type = PV_ArrayReal;
106 return p;
107 }
108
109 static PropertyVariant* create(BoolConstArrayView v)
110 {
111 PropertyVariant* p = new PropertyVariant();
112 p->m_bool = new UniqueArray<bool>(v);
113 p->m_type = PV_ArrayBool;
114 return p;
115 }
116
117 static PropertyVariant* create(StringConstArrayView v)
118 {
119 PropertyVariant* p = new PropertyVariant();
120 p->m_string = new UniqueArray<String>(v);
121 p->m_type = PV_ArrayString;
122 return p;
123 }
124
125 static PropertyVariant* create(const SmallVariant& sv)
126 {
127 PropertyVariant* p = new PropertyVariant();
128 p->m_is_scalar = true;
129 p->m_scalar = sv;
130 switch (sv.type()) {
131 case SmallVariant::TUnknown:
132 p->m_type = PV_None;
133 break;
134 case SmallVariant::TReal:
135 p->m_type = PV_ScalarReal;
136 break;
137 case SmallVariant::TInt32:
138 p->m_type = PV_ScalarInt32;
139 break;
140 case SmallVariant::TInt64:
141 p->m_type = PV_ScalarInt64;
142 break;
143 case SmallVariant::TBool:
144 p->m_type = PV_ScalarBool;
145 break;
146 case SmallVariant::TString:
147 p->m_type = PV_ScalarString;
148 break;
149 }
150 return p;
151 }
152
153 SmallVariant* getScalar()
154 {
155 if (!m_is_scalar)
156 return 0;
157 return &m_scalar;
158 }
159
160 UniqueArray<Int32>* get(Int32) const
161 {
162 return m_int32;
163 }
164
165 UniqueArray<Int64>* get(Int64) const
166 {
167 return m_int64;
168 }
169
170 UniqueArray<Real>* get(Real) const
171 {
172 return m_real;
173 }
174
175 UniqueArray<bool>* get(bool) const
176 {
177 return m_bool;
178 }
179
180 UniqueArray<String>* get(const String&) const
181 {
182 return m_string;
183 }
184
185 eType type() const { return m_type; }
186
187 private:
188
189 UniqueArray<Int32>* m_int32;
190 UniqueArray<Int64>* m_int64;
191 UniqueArray<Real>* m_real;
192 UniqueArray<bool>* m_bool;
193 UniqueArray<String>* m_string;
194 bool m_is_scalar;
195 eType m_type;
196 SmallVariant m_scalar;
197};
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
202class IPropertyType
203{
204 public:
205
206 virtual ~IPropertyType() {}
207
208 public:
209
210 virtual void print(std::ostream& o, PropertyVariant* v) = 0;
211 virtual const String& typeName() const = 0;
212 virtual void serializeReserve(ISerializer* s, PropertyVariant* v) = 0;
213 virtual void serializePut(ISerializer* s, PropertyVariant* v) = 0;
214};
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
219namespace
220{
221
222 template <typename DataType>
223 void _directPutScalar(ISerializer* s, const DataType& value)
224 {
225 s->put(value);
226 }
227
228 void _directPutScalar(ISerializer* s, const bool& value)
229 {
230 s->putByte(value);
231 }
232
233 template <typename DataType>
234 void _directReserveScalar(ISerializer* s, const DataType&)
235 {
237 }
238
239 void _directReserveScalar(ISerializer* s, const String& value)
240 {
241 s->reserve(value);
242 }
243
244 template <typename DataType>
245 void _directReserve(ISerializer* s, Span<const DataType> values)
246 {
247 s->reserveInt64(1);
248 s->reserveSpan(DataTypeTraitsT<DataType>::basicDataType(), values.size());
249 }
250
251 void _directReserve(ISerializer* s, Span<const bool> values)
252 {
253 Int64 n = values.size();
254 s->reserveInt64(1);
255 s->reserveSpan(eBasicDataType::Byte, n);
256 }
257
258 void _directReserve(ISerializer* s, Span<const String> values)
259 {
260 s->reserveInt64(1);
261 Int64 n = values.size();
262 for (Integer i = 0; i < n; ++i)
263 s->reserve(values[i]);
264 }
265
266 template <typename DataType>
267 void _directPut(ISerializer* s, Span<const DataType> values)
268 {
269 s->putInt64(values.size());
270 s->putSpan(values);
271 }
272
273 void _directPut(ISerializer* s, Span<const bool> values)
274 {
275 Int64 n = values.size();
276 s->putInt64(n);
277 UniqueArray<Byte> bytes(n);
278 for (Int64 i = 0; i < n; ++i)
279 bytes[i] = values[i] ? 1 : 0;
280
281 s->putSpan(bytes);
282 }
283
284 void _directPut(ISerializer* s, Span<const String> values)
285 {
286 Int64 n = values.size();
287 s->putInt64(n);
288 for (Integer i = 0; i < n; ++i)
289 s->put(values[i]);
290 }
291
292 template <typename DataType>
293 void _directGet(ISerializer* s, Array<DataType>& values)
294 {
295 Int64 n = s->getInt64();
296 //std::cout << "GET_N=" << n << '\n';
297 values.resize(n);
298 s->getSpan(values);
299 }
300
301 void _directGet(ISerializer* s, Array<bool>& values)
302 {
303 Int64 n = s->getInt64();
304 values.resize(n);
305
306 UniqueArray<Byte> bytes(n);
307 s->getSpan(bytes);
308
309 for (Integer i = 0; i < n; ++i)
310 values[i] = (bytes[i] != 0);
311 }
312
313 void _directGet(ISerializer* s, Array<String>& values)
314 {
315 Int64 n = s->getInt64();
316 values.resize(n);
317
318 for (Integer i = 0; i < n; ++i)
319 s->get(values[i]);
320 }
321} // namespace
322
323/*---------------------------------------------------------------------------*/
324/*---------------------------------------------------------------------------*/
325
326template <typename DataType>
327class ScalarPropertyType
328: public IPropertyType
329{
330 public:
331
332 ScalarPropertyType()
333 {
334 m_type_name = DataTypeTraitsT<DataType>::name();
335 }
336
337 public:
338
339 void print(std::ostream& o, PropertyVariant* v) override
340 {
341 SmallVariant* x = v->getScalar();
342 DataType d = DataType();
343 x->value(d);
344 o << d;
345 }
346
347 const String& typeName() const override
348 {
349 return m_type_name;
350 }
351
352 void serializeReserve(ISerializer* s, PropertyVariant* v) override
353 {
354 SmallVariant* x = v->getScalar();
355 DataType d = DataType();
356 x->value(d);
357 _directReserveScalar(s, d);
358 }
359
360 void serializePut(ISerializer* s, PropertyVariant* v) override
361 {
362 SmallVariant* x = v->getScalar();
363 DataType d = DataType();
364 x->value(d);
365 _directPutScalar(s, d);
366 }
367
368 private:
369
370 String m_type_name;
371};
372
373/*---------------------------------------------------------------------------*/
374/*---------------------------------------------------------------------------*/
375
376template <typename DataType>
377class ArrayPropertyType
378: public IPropertyType
379{
380 public:
381
382 ArrayPropertyType()
383 {
384 m_type_name = String(DataTypeTraitsT<DataType>::name()) + "[]";
385 }
386
387 public:
388
389 virtual void print(std::ostream& o, PropertyVariant* v)
390 {
391 UniqueArray<DataType>* x = v->get(DataType());
392 Integer n = x->size();
393 o << "(size=" << n;
394 if (n >= 1) {
395 for (Integer i = 0; i < n; ++i)
396 o << ',' << '[' << i << "]=" << x->operator[](i);
397 }
398 o << ')';
399 }
400 virtual const String& typeName() const
401 {
402 return m_type_name;
403 }
404 virtual void serializeReserve(ISerializer* s, PropertyVariant* v)
405 {
406 UniqueArray<DataType>* x = v->get(DataType());
407 //s->reserve(DataTypeTraitsT<DataType>::type(),x->size());
408 _directReserve(s, x->constSpan());
409 }
410 virtual void serializePut(ISerializer* s, PropertyVariant* v)
411 {
412 UniqueArray<DataType>* x = v->get(DataType());
413 _directPut(s, x->constSpan());
414 }
415
416 private:
417
418 String m_type_name;
419};
420
421/*---------------------------------------------------------------------------*/
422/*---------------------------------------------------------------------------*/
423
429class PropertiesImpl
430: public PropertiesImplBase
431, public TraceAccessor
432{
433 public:
434
435 // To be modified if serializations are changed and incompatible with
436 // older versions. Version 2 (December 2019) uses string serialization
437 // on an Int64.
438 static const Int32 SERIALIZE_VERSION = 2;
439
440 public:
441
442 typedef std::map<String, PropertyVariant*> MapType;
443
444 public:
445
446 PropertiesImpl(IPropertyMng* pm, const String& name);
447 ~PropertiesImpl();
448
449 public:
450
451 virtual void deleteMe() { delete this; }
452
453 public:
454
455 IPropertyMng* m_property_mng;
456 PropertiesImpl* m_parent_property;
457 String m_name;
458 String m_full_name;
459 MapType m_property_map;
461
462 public:
463
464 template <typename DataType>
465 bool getScalarValue(const String& name, DataType& value)
466 {
467 typename MapType::const_iterator v = m_property_map.find(name);
468 if (v == m_property_map.end()) {
469 return false;
470 }
471
472 SmallVariant* x = v->second->getScalar();
473 if (!x)
474 throw ArgumentException(A_FUNCINFO, "Bad data dimension for property (expecting scalar but property is array)");
475 x->value(value);
476 return true;
477 }
478
479 template <typename DataType>
480 void _setScalarValue(SmallVariant& s, const DataType& value)
481 {
482 s.setValueAll(value);
483 }
484 void _setScalarValue(SmallVariant& s, const String& value)
485 {
486 s.setValue(value);
487 }
488
489 template <typename DataType>
490 DataType setScalarValue(const String& name, const DataType& value)
491 {
492 DataType old_value = DataType();
493 MapType::iterator v = m_property_map.find(name);
494 if (v != m_property_map.end()) {
495 SmallVariant* x = v->second->getScalar();
496 if (!x)
497 throw ArgumentException(A_FUNCINFO, "Bad data dimension for property (expecting scalar but property is array)");
498 // Retrieve the old value
499 x->value(old_value);
500 _setScalarValue(*x, value);
501 }
502 else {
503 SmallVariant sv;
504 _setScalarValue(sv, value);
505 m_property_map.insert(std::make_pair(name, PropertyVariant::create(sv)));
506 }
507 return old_value;
508 }
509
510 template <typename DataType>
511 void setArrayValue(const String& name, ConstArrayView<DataType> value)
512 {
513 MapType::iterator v = m_property_map.find(name);
514 if (v != m_property_map.end()) {
515 UniqueArray<DataType>* x = v->second->get(DataType());
516 if (!x)
517 throw ArgumentException(A_FUNCINFO, "Bad datatype for property");
518 x->copy(value);
519 }
520 else {
521 m_property_map.insert(std::make_pair(name, PropertyVariant::create(value)));
522 }
523 }
524
525 template <typename DataType>
526 void getArrayValue(const String& name, Array<DataType>& value)
527 {
528 MapType::const_iterator v = m_property_map.find(name);
529 if (v == m_property_map.end()) {
530 value.clear();
531 return;
532 }
533 UniqueArray<DataType>* x = v->second->get(DataType());
534 if (!x)
535 throw ArgumentException(A_FUNCINFO, "Bad datatype for property");
536 value.copy(*x);
537 }
538
539 public:
540
541 void print(std::ostream& o);
542
543 void serialize(ISerializer* serializer);
544
545 void serializeReserve(ISerializer* serializer);
546 void serializePut(ISerializer* serializer);
547 void serializeGet(ISerializer* serializer);
548
549 private:
550
551 template <typename DataType> void
552 _serializeGetArray(ISerializer* serializer, const String& name, const DataType&)
553 {
554 UniqueArray<DataType> values;
555 _directGet(serializer, values);
556 setArrayValue(name, values.constView());
557 }
558};
559
560/*---------------------------------------------------------------------------*/
561/*---------------------------------------------------------------------------*/
562
563PropertiesImpl::
564PropertiesImpl(IPropertyMng* pm, const String& name)
565: TraceAccessor(pm->traceMng())
566, m_property_mng(pm)
567, m_parent_property(0)
568, m_name(name)
569, m_full_name(name)
570{
571 m_types.resize(PropertyVariant::NB_TYPE);
572 m_types.fill(0);
573 m_types[PropertyVariant::PV_ScalarReal] = new ScalarPropertyType<Real>();
574 m_types[PropertyVariant::PV_ScalarInt32] = new ScalarPropertyType<Int32>();
575 m_types[PropertyVariant::PV_ScalarInt64] = new ScalarPropertyType<Int64>();
576 m_types[PropertyVariant::PV_ScalarBool] = new ScalarPropertyType<bool>();
577 m_types[PropertyVariant::PV_ScalarString] = new ScalarPropertyType<String>();
578
579 m_types[PropertyVariant::PV_ArrayReal] = new ArrayPropertyType<Real>();
580 m_types[PropertyVariant::PV_ArrayInt32] = new ArrayPropertyType<Int32>();
581 m_types[PropertyVariant::PV_ArrayInt64] = new ArrayPropertyType<Int64>();
582 m_types[PropertyVariant::PV_ArrayBool] = new ArrayPropertyType<bool>();
583 m_types[PropertyVariant::PV_ArrayString] = new ArrayPropertyType<String>();
584}
585
586/*---------------------------------------------------------------------------*/
587/*---------------------------------------------------------------------------*/
588
589PropertiesImpl::
590~PropertiesImpl()
591{
592 MapType::iterator v = m_property_map.begin();
593 MapType::iterator vend = m_property_map.end();
594 for (; v != vend; ++v)
595 delete v->second;
596
597 for (Integer i = 0, n = m_types.size(); i < n; ++i)
598 delete m_types[i];
599
600 info(5) << "DESTROY PROPERTY name=" << m_name << " this=" << this;
601}
602
603/*---------------------------------------------------------------------------*/
604/*---------------------------------------------------------------------------*/
605
606void PropertiesImpl::
607print(std::ostream& o)
608{
609 MapType::iterator v = m_property_map.begin();
610 MapType::iterator vend = m_property_map.end();
611 for (; v != vend; ++v) {
612 PropertyVariant* p = v->second;
613 PropertyVariant::eType et = p->type();
614 IPropertyType* pt = m_types[et];
615 o << " " << v->first << " = ";
616 if (pt) {
617 o << "(" << pt->typeName();
618 o << ") ";
619 pt->print(o, p);
620 }
621 else {
622 o << "??";
623 }
624 o << '\n';
625 }
626}
627
628/*---------------------------------------------------------------------------*/
629/*---------------------------------------------------------------------------*/
630
631void PropertiesImpl::
632serialize(ISerializer* serializer)
633{
634 switch (serializer->mode()) {
635 case ISerializer::ModeReserve:
636 serializeReserve(serializer);
637 break;
639 serializePut(serializer);
640 break;
642 serializeGet(serializer);
643 break;
644 }
645}
646
647/*---------------------------------------------------------------------------*/
648/*---------------------------------------------------------------------------*/
649
650void PropertiesImpl::
651serializeReserve(ISerializer* serializer)
652{
653 serializer->reserveInt32(1); // SERIALIZE_VERSION
654 serializer->reserveInt64(1); // Number of elements in the map
655
656 MapType::iterator v = m_property_map.begin();
657 MapType::iterator vend = m_property_map.end();
658 for (; v != vend; ++v) {
659 PropertyVariant* p = v->second;
660 PropertyVariant::eType et = p->type();
661 serializer->reserveInt32(1);
662 serializer->reserve(v->first);
663 IPropertyType* pt = m_types[et];
664 pt->serializeReserve(serializer, p);
665 }
666}
667
668/*---------------------------------------------------------------------------*/
669/*---------------------------------------------------------------------------*/
670
671void PropertiesImpl::
672serializePut(ISerializer* serializer)
673{
674 serializer->putInt32(SERIALIZE_VERSION);
675
676 Int64 n = (Int64)m_property_map.size();
677 serializer->putInt64(n);
678
679 MapType::iterator v = m_property_map.begin();
680 MapType::iterator vend = m_property_map.end();
681 for (; v != vend; ++v) {
682 PropertyVariant* p = v->second;
683 PropertyVariant::eType et = p->type();
684 IPropertyType* pt = m_types[et];
685 serializer->putInt32(et);
686 serializer->put(v->first);
687 pt->serializePut(serializer, p);
688 }
689}
690
691/*---------------------------------------------------------------------------*/
692/*---------------------------------------------------------------------------*/
693
694void PropertiesImpl::
695serializeGet(ISerializer* serializer)
696{
697 Int64 version = serializer->getInt32();
698 if (version != SERIALIZE_VERSION) {
699 // Reading is done with a protection from an old version of Arcane
700 // which is not compatible. Displays a warning and does nothing.
701 // (NOTE: this still risks causing problems for those who use the
702 // properties, so maybe a fatal error should be thrown?)
703 pwarning() << "Can not reading properties from imcompatible checkpoint";
704 return;
705 }
706
707 Int64 n = serializer->getInt64();
708 String name;
709 for (Integer i = 0; i < n; ++i) {
710 Int32 type = serializer->getInt32();
711 serializer->get(name);
712 //std::cout << "TYPE=" << type << " name=" << name << '\n';
713 //TODO: Verify value validity + do this cleanly without a switch
714 switch (type) {
715 case PropertyVariant::PV_ScalarReal:
716 setScalarValue(name, serializer->getReal());
717 break;
718 case PropertyVariant::PV_ScalarInt32:
719 setScalarValue(name, serializer->getInt32());
720 break;
721 case PropertyVariant::PV_ScalarInt64:
722 setScalarValue(name, serializer->getInt64());
723 break;
724 case PropertyVariant::PV_ScalarBool:
725 setScalarValue(name, (bool)serializer->getByte());
726 break;
727 case PropertyVariant::PV_ScalarString: {
728 String str;
729 serializer->get(str);
730 setScalarValue(name, str);
731 } break;
732
733 case PropertyVariant::PV_ArrayReal:
734 _serializeGetArray(serializer, name, Real());
735 break;
736 case PropertyVariant::PV_ArrayInt32:
737 _serializeGetArray(serializer, name, Int32());
738 break;
739 case PropertyVariant::PV_ArrayInt64:
740 _serializeGetArray(serializer, name, Int64());
741 break;
742 case PropertyVariant::PV_ArrayBool:
743 _serializeGetArray(serializer, name, bool());
744 break;
745 case PropertyVariant::PV_ArrayString:
746 _serializeGetArray(serializer, name, String());
747 break;
748 default:
749 throw FatalErrorException(A_FUNCINFO, "Bad type");
750 }
751 }
752}
753
754/*---------------------------------------------------------------------------*/
755/*---------------------------------------------------------------------------*/
756
757/*---------------------------------------------------------------------------*/
758/*---------------------------------------------------------------------------*/
759
761Properties(IPropertyMng* pm, const String& aname)
762: m_p(0)
763, m_ref(0)
764{
765 PropertiesImpl* pi = pm->getPropertiesImpl(aname);
766 bool has_create = false;
767 if (!pi) {
768 pi = new PropertiesImpl(pm, aname);
769 has_create = true;
770 }
771 m_p = pi;
772 m_ref = pi;
773 if (has_create)
774 pm->registerProperties(*this);
775}
776
777/*---------------------------------------------------------------------------*/
778/*---------------------------------------------------------------------------*/
779
781Properties(const Properties& parent_property, const String& aname)
782{
783 String full_name = parent_property.fullName() + "." + aname;
784 IPropertyMng* pm = parent_property.propertyMng();
785 PropertiesImpl* pi = pm->getPropertiesImpl(full_name);
786
787 bool has_create = false;
788 if (!pi) {
789 pi = new PropertiesImpl(pm, full_name);
790 has_create = true;
791 }
792 m_p = pi;
793 m_ref = pi;
794 if (has_create)
795 pm->registerProperties(*this);
796}
797
798/*---------------------------------------------------------------------------*/
799/*---------------------------------------------------------------------------*/
800
803: m_p(p)
804, m_ref(m_p)
805{
806}
807
808/*---------------------------------------------------------------------------*/
809/*---------------------------------------------------------------------------*/
810
815
816/*---------------------------------------------------------------------------*/
817/*---------------------------------------------------------------------------*/
818
820Properties(const Properties& rhs)
821: m_p(rhs.m_p)
822, m_ref(rhs.m_ref)
823{
824}
825
826/*---------------------------------------------------------------------------*/
827/*---------------------------------------------------------------------------*/
828
830operator=(const Properties& rhs)
831{
832 if (&rhs != this) {
833 m_p = rhs.m_p;
834 m_ref = rhs.m_ref;
835 }
836 return (*this);
837}
838
839/*---------------------------------------------------------------------------*/
840/*---------------------------------------------------------------------------*/
841
843setBool(const String& aname, bool value)
844{
845 m_p->setScalarValue(aname, value);
846}
848set(const String& aname, bool value)
849{
850 setBool(aname, value);
851}
853getBoolWithDefault(const String& aname, bool default_value) const
854{
855 bool v = default_value;
856 get(aname, v);
857 return v;
858}
860getBool(const String& aname) const
861{
862 return getBoolWithDefault(aname, false);
863}
865get(const String& aname, bool& value) const
866{
867 return m_p->getScalarValue(aname, value);
868}
869
870/*---------------------------------------------------------------------------*/
871/*---------------------------------------------------------------------------*/
872
874setInt32(const String& aname, Int32 value)
875{
876 m_p->setScalarValue(aname, value);
877}
879set(const String& aname, Int32 value)
880{
881 setInt32(aname, value);
882}
884getInt32WithDefault(const String& name, Int32 default_value) const
885{
886 Int32 v = default_value;
887 m_p->getScalarValue(name, v);
888 return v;
889}
891getInt32(const String& name) const
892{
893 return getInt32WithDefault(name, 0);
894}
896get(const String& name, Int32& value) const
897{
898 return m_p->getScalarValue(name, value);
899 //value = getInt32(name);
900}
901
902/*---------------------------------------------------------------------------*/
903/*---------------------------------------------------------------------------*/
904
906setInt64(const String& aname, Int64 value)
907{
908 m_p->setScalarValue(aname, value);
909}
911set(const String& aname, Int64 value)
912{
913 setInt64(aname, value);
914}
916getInt64WithDefault(const String& aname, Int64 default_value) const
917{
918 Int64 v = default_value;
919 m_p->getScalarValue(aname, v);
920 return v;
921}
923getInt64(const String& aname) const
924{
925 return getInt64WithDefault(aname, 0);
926}
928get(const String& aname, Int64& value) const
929{
930 return m_p->getScalarValue(aname, value);
931}
932
933/*---------------------------------------------------------------------------*/
934/*---------------------------------------------------------------------------*/
935
937setInteger(const String& aname, Integer value)
938{
939 set(aname, value);
940}
942getIntegerWithDefault(const String& aname, Integer default_value) const
943{
944 Integer x = default_value;
945 m_p->getScalarValue(aname, x);
946 return x;
947}
949getInteger(const String& name) const
950{
951 return getIntegerWithDefault(name, 0);
952}
953
954/*---------------------------------------------------------------------------*/
955/*---------------------------------------------------------------------------*/
956
958setReal(const String& aname, Real value)
959{
960 m_p->setScalarValue(aname, value);
961}
963set(const String& aname, Real value)
964{
965 setReal(aname, value);
966}
968getRealWithDefault(const String& aname, Real default_value) const
969{
970 Real v = default_value;
971 m_p->getScalarValue(aname, v);
972 return v;
973}
975getReal(const String& aname) const
976{
977 return getRealWithDefault(aname, 0.0);
978}
980get(const String& aname, Real& value) const
981{
982 return m_p->getScalarValue(aname, value);
983}
984
985/*---------------------------------------------------------------------------*/
986/*---------------------------------------------------------------------------*/
987
989setString(const String& aname, const String& value)
990{
991 m_p->setScalarValue(aname, value);
992}
994set(const String& aname, const String& value)
995{
996 setString(aname, value);
997}
999getStringWithDefault(const String& aname, const String& default_value) const
1000{
1001 String v = default_value;
1002 m_p->getScalarValue(aname, v);
1003 return v;
1004}
1006getString(const String& aname) const
1007{
1008 return getStringWithDefault(aname, String());
1009}
1011get(const String& aname, String& value) const
1012{
1013 return m_p->getScalarValue(aname, value);
1014}
1015
1016/*---------------------------------------------------------------------------*/
1017/*---------------------------------------------------------------------------*/
1018
1020set(const String& aname, BoolConstArrayView value)
1021{
1022 m_p->setArrayValue(aname, value);
1023}
1025get(const String& aname, BoolArray& value) const
1026{
1027 m_p->getArrayValue(aname, value);
1028}
1029
1030/*---------------------------------------------------------------------------*/
1031/*---------------------------------------------------------------------------*/
1032
1034set(const String& aname, Int32ConstArrayView value)
1035{
1036 m_p->setArrayValue(aname, value);
1037}
1039get(const String& aname, Int32Array& value) const
1040{
1041 m_p->getArrayValue(aname, value);
1042}
1043
1044/*---------------------------------------------------------------------------*/
1045/*---------------------------------------------------------------------------*/
1046
1048set(const String& aname, Int64ConstArrayView value)
1049{
1050 m_p->setArrayValue(aname, value);
1051}
1053get(const String& aname, Int64Array& value) const
1054{
1055 m_p->getArrayValue(aname, value);
1056}
1057
1058/*---------------------------------------------------------------------------*/
1059/*---------------------------------------------------------------------------*/
1060
1062set(const String& aname, RealConstArrayView value)
1063{
1064 m_p->setArrayValue(aname, value);
1065}
1067get(const String& aname, RealArray& value) const
1068{
1069 m_p->getArrayValue(aname, value);
1070}
1071
1072/*---------------------------------------------------------------------------*/
1073/*---------------------------------------------------------------------------*/
1074
1076set(const String& aname, StringConstArrayView value)
1077{
1078 m_p->setArrayValue(aname, value);
1079}
1081get(const String& aname, StringArray& value) const
1082{
1083 m_p->getArrayValue(aname, value);
1084}
1085
1086/*---------------------------------------------------------------------------*/
1087/*---------------------------------------------------------------------------*/
1088
1090print(std::ostream& o) const
1091{
1092 m_p->print(o);
1093}
1094
1095/*---------------------------------------------------------------------------*/
1096/*---------------------------------------------------------------------------*/
1097
1099serialize(ISerializer* serializer)
1100{
1101 m_p->serialize(serializer);
1102}
1103
1104/*---------------------------------------------------------------------------*/
1105/*---------------------------------------------------------------------------*/
1106
1108name() const
1109{
1110 return m_p->m_name;
1111}
1112
1113/*---------------------------------------------------------------------------*/
1114/*---------------------------------------------------------------------------*/
1115
1117fullName() const
1118{
1119 return m_p->m_full_name;
1120}
1121
1122/*---------------------------------------------------------------------------*/
1123/*---------------------------------------------------------------------------*/
1124
1125IPropertyMng* Properties::
1126propertyMng() const
1127{
1128 return m_p->m_property_mng;
1129}
1130
1131/*---------------------------------------------------------------------------*/
1132/*---------------------------------------------------------------------------*/
1133
1135destroy()
1136{
1137 m_p->m_property_mng->destroyProperties(*this);
1138}
1139
1140/*---------------------------------------------------------------------------*/
1141/*---------------------------------------------------------------------------*/
1142
1143} // End namespace Arcane
1144
1145/*---------------------------------------------------------------------------*/
1146/*---------------------------------------------------------------------------*/
Integer size() const
Number of elements in the vector.
Base class for 1D data vectors.
Span< const T > constSpan() const
Constant view of this array.
Interface of the property manager.
virtual void registerProperties(const Properties &p)=0
Registers the properties referenced by p.
virtual PropertiesImpl * getPropertiesImpl(const String &full_name)=0
Retrieves the list of properties by full name full_name.
virtual void destroyProperties(const Properties &p)=0
Deletes the properties referenced by p.
Interface of a property type.
Definition IProperty.h:106
virtual void deleteMe()
Destroys the referenced object.
Int64 getInt64(const String &name) const
Value of the property named name.
bool get(const String &name, bool &value) const
Value of the property named name.
bool getBoolWithDefault(const String &name, bool default_value) const
Value of the property named name.
const String & name() const
Name of the property.
Int32 getInt32WithDefault(const String &name, Int32 default_value) const
Value of the property named name.
Int32 getInt32(const String &name) const
Value of the property named name.
Integer getInteger(const String &name) const
Value of the property named name.
Integer getIntegerWithDefault(const String &name, Integer default_value) const
Value of the property named name.
bool getBool(const String &name) const
Value of the property named name.
void setInteger(const String &name, Integer value)
Sets an Integer property of name name and value value.
void setInt64(const String &name, Int64 value)
Sets an Int64 property of name name and value value.
void destroy()
Destroys the associated values of properties linked to this reference.
Real getReal(const String &name) const
Value of the property named name.
void setInt32(const String &name, Int32 value)
Sets an Int32 property of name name and value value.
Int64 getInt64WithDefault(const String &name, Int64 default_value) const
Value of the property named name.
void set(const String &name, bool value)
Sets a boolean property of name name and value value.
String getString(const String &name) const
Value of the property named name.
Real getRealWithDefault(const String &name, Real default_value) const
Value of the property named name.
const Properties & operator=(const Properties &rhs)
Copy assignment operator.
String getStringWithDefault(const String &name, const String &default_value) const
Value of the property named name.
void serialize(ISerializer *serializer)
Performs the serialization of the properties.
Properties(IPropertyMng *pm, const String &name)
Creates or retrieves a list of properties with name name.
virtual ~Properties()
Destroys the reference to this property.
void setBool(const String &name, bool value)
Sets a boolean property of name name and value value.
void setString(const String &name, const String &value)
Sets a String property of name name and value value.
const String & fullName() const
Full name of the property.
void print(std::ostream &o) const
Prints the properties and their values to the stream o.
void setReal(const String &name, Real value)
Sets a Real property of name name and value value.
Class managing a polymorphic type.
View of an array of elements of type T.
Definition Span.h:635
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage info() const
Flow for an information message.
TraceMessage pwarning() const
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
Definition UtilsTypes.h:125
ConstArrayView< String > StringConstArrayView
C equivalent of a 1D array of strings.
Definition UtilsTypes.h:492
Array< String > StringArray
Dynamic one-dimensional array of strings.
Definition UtilsTypes.h:145
Array< bool > BoolArray
Dynamic one-dimensional array of booleans.
Definition UtilsTypes.h:143
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
ConstArrayView< bool > BoolConstArrayView
C equivalent of a 1D array of booleans.
Definition UtilsTypes.h:490
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
double Real
Type representing a real number.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127
Array< Real > RealArray
Dynamic one-dimensional array of reals.
Definition UtilsTypes.h:135
std::int32_t Int32
Signed integer type of 32 bits.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.
Definition UtilsTypes.h:488