16#include "arccore/alina/AlinaUtils.h"
17#include "arccore/alina/CSRMatrixView.h"
19#include <boost/property_tree/ptree.hpp>
20#include <boost/property_tree/json_parser.hpp>
25namespace Arcane::Alina
30using BoostPTree = boost::property_tree::ptree;
34 const BoostPTree& empty_ptree()
36 static const BoostPTree p;
45 static const BoostPTree& toBoostPTree(
const PropertyTree& p)
47 return *(
static_cast<const BoostPTree*
>(p.m_property_tree));
51 return *(
static_cast<BoostPTree*
>(p.m_property_tree));
61 return detail::PropertyWrapper::toBoostPTree(p);
63 const BoostPTree& toBoostPTree(
const PropertyTree* p)
65 return detail::PropertyWrapper::toBoostPTree(*p);
67 BoostPTree& toBoostPTree(PropertyTree* p)
69 return detail::PropertyWrapper::toBoostPTree(*p);
78: m_property_tree(new BoostPTree())
87PropertyTree(
const PropertyTree& rhs)
90 m_property_tree =
new BoostPTree(toBoostPTree(rhs));
94 m_property_tree = rhs.m_property_tree;
115 delete &toBoostPTree(
this);
121PropertyTree PropertyTree::
122get_child_empty(
const std::string& path)
const
124 const BoostPTree& child = toBoostPTree(
this).get_child(path, detail::empty_ptree());
126 p.m_property_tree =
const_cast<BoostPTree*
>(&child);
135erase(
const char* name)
137 return toBoostPTree(
this).erase(name);
144count(
const char* name)
const
146 return toBoostPTree(
this).count(name);
153read_json(
const std::string& filename)
155 BoostPTree& p = toBoostPTree(
this);
156 boost::property_tree::json_parser::read_json(filename, p);
159Int32 PropertyTree::get(
const char* param_type,
Int32 default_value)
const
161 return toBoostPTree(
this).get(param_type, default_value);
163Int64 PropertyTree::get(
const char* param_type,
Int64 default_value)
const
165 return toBoostPTree(
this).get(param_type, default_value);
167double PropertyTree::get(
const char* param_type,
double default_value)
const
169 return toBoostPTree(
this).get(param_type, default_value);
171double* PropertyTree::get(
const char* param_type,
double* default_value)
const
173 return toBoostPTree(
this).get(param_type, default_value);
175void* PropertyTree::get(
const char* param_type,
void* default_value)
const
177 return toBoostPTree(
this).get(param_type, default_value);
179std::string PropertyTree::get(
const char* param_type,
const std::string& default_value)
const
181 return toBoostPTree(
this).get(param_type, default_value);
184void PropertyTree::put(
const std::string& path,
Int32 value)
186 toBoostPTree(
this).put(path, value);
188void PropertyTree::put(
const std::string& path,
Int64 value)
190 toBoostPTree(
this).put(path, value);
192void PropertyTree::put(
const std::string& path,
double value)
194 toBoostPTree(
this).put(path, value);
196void PropertyTree::put(
const std::string& path,
const std::string& value)
198 toBoostPTree(
this).put(path, value);
200void PropertyTree::put(
const std::string& path,
double* value)
202 toBoostPTree(
this).put(path, value);
204void PropertyTree::put(
const std::string& path,
void* value)
206 toBoostPTree(
this).put(path, value);
213_addChild(
const std::string& path,
const char* name,
214 const PropertyTree& obj)
216 auto& p = toBoostPTree(
this);
217 p.add_child(std::string(path) + name, toBoostPTree(obj));
224check_params(
const std::set<std::string>& names)
const
226 const auto& p = toBoostPTree(
this);
227 bool has_error =
false;
228 for (
const auto& n : names) {
230 ARCCORE_ALINA_PARAM_MISSING(n);
233 for (
const auto& v : p) {
234 if (!names.count(v.first)) {
235 std::cerr <<
"WARNING: unknown parameter " << v.first <<
"\n";
247check_params(
const std::set<std::string>& names,
248 const std::set<std::string>& opt_names)
const
250 const auto& p = toBoostPTree(
this);
251 bool has_error =
false;
253 for (
const auto& n : names) {
255 ARCCORE_ALINA_PARAM_MISSING(n);
258 for (
const auto& n : opt_names) {
260 ARCCORE_ALINA_PARAM_MISSING(n);
263 for (
const auto& v : p) {
264 if (!names.count(v.first) && !opt_names.count(v.first)) {
265 std::cerr <<
"WARNING: unknown parameter " << v.first <<
"\n";
277putKeyValue(
const std::string& param)
279 auto& p = toBoostPTree(
this);
280 size_t eq_pos = param.find(
'=');
281 if (eq_pos == std::string::npos)
282 ARCANE_FATAL(
"param in put() should have \"key=value\" format (param='{0}')", param);
283 p.put(param.substr(0, eq_pos), param.substr(eq_pos + 1));
289detail::empty_params::
290empty_params(
const PropertyTree& ap)
292 const auto& p = toBoostPTree(ap);
293 for (
const auto& v : p) {
294 std::cerr <<
"Alina: unknown parameter " << v.first <<
"\n";
301std::ostream& operator<<(std::ostream& o,
const PropertyTree& obj)
303 const auto& p = toBoostPTree(obj);
304 std::ostringstream ostr;
305 boost::property_tree::json_parser::write_json(ostr, p);
Fichier de configuration d'Arcane.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.