Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ConfigurationPropertyReader.h
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/* ConfigurationPropertyReader.h (C) 2000-2025 */
9/* */
10/* Reading properties from an 'IConfiguration'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_INTERNAL_CONFIGURATIONPROPERTYREADER_H
13#define ARCANE_CORE_INTERNAL_CONFIGURATIONPROPERTYREADER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17/*
18 * NOTE: The classes in this file are currently under development.
19 * NOTE: The API may change at any time. Do not use outside of Arcane.
20 */
21
22#include "arcane/core/IConfiguration.h"
23#include "arccore/common/internal/Property.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::properties
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34template <typename T>
35class ConfigurationPropertyReader
36: public PropertyVisitor<T>
37{
38 public:
39
40 ConfigurationPropertyReader(IConfigurationSection* cs, T& instance)
41 : m_configuration_section(cs)
42 , m_instance(instance)
43 {}
44
45 private:
46
47 IConfigurationSection* m_configuration_section;
48 T& m_instance;
49
50 public:
51
52 void visit(const PropertySettingBase<T>& s) override
53 {
54 const String& pname = s.setting()->name();
55 String value = m_configuration_section->value(pname, String());
56 if (value.null())
57 return;
58 s.setFromString(value, m_instance);
59 s.print(std::cout, m_instance);
60 }
61};
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
72template <typename T> inline void
73readFromConfiguration(IConfiguration* c, T& instance)
74{
75 if (!c)
76 return;
77 const char* instance_property_name = T ::propertyClassName();
78 ScopedPtrT<IConfigurationSection> cs(c->createSection(instance_property_name));
79 ConfigurationPropertyReader reader(cs.get(), instance);
80 T ::applyPropertyVisitor(reader);
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86} // End namespace Arcane::properties
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91#endif
Interface for a configuration section.
Interface for a configuration.
virtual IConfigurationSection * createSection(const String &name) const =0
Creates a configuration section.
Encapsulation of an automatically destructing pointer.
Definition ScopedPtr.h:44
virtual String name() const =0
Property name.
Base class of a property typed by a class.
Definition Property.h:143
Base class of a typed visitor on a property.
Definition Property.h:205