16#include "arccore/alina/AlinaUtils.h"
18#include <boost/property_tree/ptree.hpp>
19#include <boost/property_tree/json_parser.hpp>
24namespace Arcane::Alina
29using BoostPTree = boost::property_tree::ptree;
33 const BoostPTree& empty_ptree()
35 static const BoostPTree p;
44 static const BoostPTree& toBoostPTree(
const PropertyTree& p)
46 return *(
static_cast<const BoostPTree*
>(p.m_property_tree));
50 return *(
static_cast<BoostPTree*
>(p.m_property_tree));
60 return detail::PropertyWrapper::toBoostPTree(p);
62 const BoostPTree& toBoostPTree(
const PropertyTree* p)
64 return detail::PropertyWrapper::toBoostPTree(*p);
66 BoostPTree& toBoostPTree(PropertyTree* p)
68 return detail::PropertyWrapper::toBoostPTree(*p);
77: m_property_tree(new BoostPTree())
86PropertyTree(
const PropertyTree& rhs)
89 m_property_tree =
new BoostPTree(toBoostPTree(rhs));
93 m_property_tree = rhs.m_property_tree;
114 delete &toBoostPTree(
this);
120PropertyTree PropertyTree::
121get_child_empty(
const std::string& path)
const
123 const BoostPTree& child = toBoostPTree(
this).get_child(path, detail::empty_ptree());
125 p.m_property_tree =
const_cast<BoostPTree*
>(&child);
134erase(
const char* name)
136 return toBoostPTree(
this).erase(name);
143count(
const char* name)
const
145 return toBoostPTree(
this).count(name);
152read_json(
const std::string& filename)
154 BoostPTree& p = toBoostPTree(
this);
155 boost::property_tree::json_parser::read_json(filename, p);
158Int32 PropertyTree::get(
const char* param_type,
Int32 default_value)
const
160 return toBoostPTree(
this).get(param_type, default_value);
162Int64 PropertyTree::get(
const char* param_type,
Int64 default_value)
const
164 return toBoostPTree(
this).get(param_type, default_value);
166double PropertyTree::get(
const char* param_type,
double default_value)
const
168 return toBoostPTree(
this).get(param_type, default_value);
170double* PropertyTree::get(
const char* param_type,
double* default_value)
const
172 return toBoostPTree(
this).get(param_type, default_value);
174void* PropertyTree::get(
const char* param_type,
void* default_value)
const
176 return toBoostPTree(
this).get(param_type, default_value);
178std::string PropertyTree::get(
const char* param_type,
const std::string& default_value)
const
180 return toBoostPTree(
this).get(param_type, default_value);
183void PropertyTree::put(
const std::string& path,
Int32 value)
185 toBoostPTree(
this).put(path, value);
187void PropertyTree::put(
const std::string& path,
Int64 value)
189 toBoostPTree(
this).put(path, value);
191void PropertyTree::put(
const std::string& path,
double value)
193 toBoostPTree(
this).put(path, value);
195void PropertyTree::put(
const std::string& path,
const std::string& value)
197 toBoostPTree(
this).put(path, value);
199void PropertyTree::put(
const std::string& path,
double* value)
201 toBoostPTree(
this).put(path, value);
203void PropertyTree::put(
const std::string& path,
void* value)
205 toBoostPTree(
this).put(path, value);
212_addChild(
const std::string& path,
const char* name,
213 const PropertyTree& obj)
215 auto& p = toBoostPTree(
this);
216 p.add_child(std::string(path) + name, toBoostPTree(obj));
223check_params(
const std::set<std::string>& names)
const
225 const auto& p = toBoostPTree(
this);
226 bool has_error =
false;
227 for (
const auto& n : names) {
229 ARCCORE_ALINA_PARAM_MISSING(n);
232 for (
const auto& v : p) {
233 if (!names.count(v.first)) {
234 std::cerr <<
"WARNING: unknown parameter " << v.first <<
"\n";
246check_params(
const std::set<std::string>& names,
247 const std::set<std::string>& opt_names)
const
249 const auto& p = toBoostPTree(
this);
250 bool has_error =
false;
252 for (
const auto& n : names) {
254 ARCCORE_ALINA_PARAM_MISSING(n);
257 for (
const auto& n : opt_names) {
259 ARCCORE_ALINA_PARAM_MISSING(n);
262 for (
const auto& v : p) {
263 if (!names.count(v.first) && !opt_names.count(v.first)) {
264 std::cerr <<
"WARNING: unknown parameter " << v.first <<
"\n";
276putKeyValue(
const std::string& param)
278 auto& p = toBoostPTree(
this);
279 size_t eq_pos = param.find(
'=');
280 if (eq_pos == std::string::npos)
281 ARCANE_FATAL(
"param in put() should have \"key=value\" format (param='{0}')", param);
282 p.put(param.substr(0, eq_pos), param.substr(eq_pos + 1));
288detail::empty_params::
289empty_params(
const PropertyTree& ap)
291 const auto& p = toBoostPTree(ap);
292 for (
const auto& v : p) {
293 std::cerr <<
"Alina: unknown parameter " << v.first <<
"\n";
300std::ostream& operator<<(std::ostream& o,
const PropertyTree& obj)
302 const auto& p = toBoostPTree(obj);
303 std::ostringstream ostr;
304 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.