14#include "arcane/core/AxlOptionsBuilder.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/Array.h"
18#include "arcane/utils/JSONWriter.h"
20#include "arcane/core/DomUtils.h"
21#include "arcane/core/XmlNode.h"
22#include "arcane/core/IXmlDocumentHolder.h"
23#include "arcane/core/CaseNodeNames.h"
28namespace Arcane::AxlOptionsBuilder
46 void add(
const std::initializer_list<OneOption>& options)
48 for (
const auto& o : options)
74 const std::initializer_list<OneOption>& options)
77 m_sub_option->add(options);
85ServiceInstance(
const String& option_name,
const String& service_name,
86 const OptionList& options)
87: OneOption(
Type::CO_ServiceInstance, option_name, options)
89 m_service_name = service_name;
96ServiceInstance(
const String& option_name,
const String& service_name)
97: OneOption(
Type::CO_ServiceInstance, option_name, String{})
99 m_service_name = service_name;
106Complex(
const String& name,
const std::initializer_list<OneOption>& options)
107: OneOption(
Type::CO_Complex, name, OptionList{})
109 m_sub_option->add(options);
116Complex(
const String& name,
const OptionList& options)
117: OneOption(
Type::CO_Complex, name, options)
137OptionList(
const std::initializer_list<OneOption>& options)
149 m_p->m_options.add(
OneOption(OneOption::Type::CO_Complex, name,
option));
156OptionList& OptionList::
157add(
const std::initializer_list<OneOption>& options)
159 for (
const auto& o : options)
160 m_p->m_options.add(o);
167OptionList OptionList::
171 new_opt.m_p->m_options = m_p->m_options;
188 auto*
doc = domutils::createXmlDocument();
205 if (o.m_sub_option.get())
208 if (!o.m_service_name.null())
211 if (!o.m_function_name.null()) {
221 : m_case_node_names(
lang)
242 return writer.m_json_writer.getBuffer();
250 m_json_writer.write(
"language",
doc.language());
251 m_json_writer.write(
"version",
"1");
254 _write(
doc.m_options.m_p.get());
275 if (o.m_type==OneOption::Type::CO_ServiceInstance){
283 if (o.m_type==OneOption::Type::CO_Complex){
297 if (!o.m_function_name.
null()) {
299 m_json_writer.write(m_case_function_json_name,o.m_function_name);
300 m_json_writer.write(
"$value",o.
m_value);
304 m_json_writer.write(o.m_name, o.
m_value);
310 : m_case_node_names(
lang)
312 m_case_function_json_name =
String(
"$") + m_case_node_names.function_ref;
319 String m_case_function_json_name;
328 return DocumentXmlWriter::toXml(d);
345extern "C++" ARCANE_CORE_EXPORT
void
346_testAxlOptionsBuilder()
348 using namespace AxlOptionsBuilder;
349 std::cout <<
"TestOptionList\n";
350 OptionList sub_opt({ Simple(
"max", 35),
352 Simple(
"test", 1) });
354 OptionList service_opt({ Simple(
"service-option1", 42),
355 Simple(
"service-option2", -1.5) });
357 OptionList dco({ Simple(
"toto", 3),
358 Simple(
"titi", 3.1).addFunction(
"func1"),
359 Simple(
"tutu",
"Hello"),
360 Enumeration(
"a",
"vx"),
361 Extended(
"extended1",
"ext"),
362 ServiceInstance(
"my-service1",
"TestService1",
363 { Simple(
"service-option1", 25),
364 Simple(
"service-option2", 3.2) }),
365 ServiceInstance(
"my-service2",
"TestService2"),
367 ServiceInstance(
"my-service3",
"TestService3", service_opt),
371 Simple(
"test", 4) }),
372 Complex(
"sub-opt2", sub_opt) });
374 auto* x = DocumentXmlWriter::toXml(doc);
375 String s = x->save();
376 std::cout <<
"VALUE:" << s <<
"\n";
378 String ref_str =
"<?xml version=\"1.0\"?>\n"
379 "<root xml:lang=\"fr\"><dynamic-options><toto>3</toto><titi fonction=\"func1\">3.1</titi>"
380 "<tutu>Hello</tutu><a>vx</a><extended1>ext</extended1><my-service1 name=\"TestService1\">"
381 "<service-option1>25</service-option1><service-option2>3.2</service-option2></my-service1>"
382 "<my-service2 name=\"TestService2\"/><my-service3 name=\"TestService3\">"
383 "<service-option1>42</service-option1><service-option2>-1.5</service-option2></my-service3>"
384 "<sub-opt1><max>25</max><min>23.2</min><test>4</test></sub-opt1><sub-opt2><max>35</max>"
385 "<min>13.2</min><test>1</test></sub-opt2></dynamic-options></root>\n";
387 ARCANE_FATAL(
"BAD VALUE v={0} expected={1}", s, ref_str);
390 String json_string = DocumentJSONWriter::toJSON(doc);
392 std::ofstream ofile(
"test1.json");
393 ofile << json_string;
395 std::cout <<
"JSON=" << json_string <<
"\n";
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Écrivain au format JSON pour un jeu de données.
Écrivain au format XML pour un jeu de données.
Option 'ServiceInstance' du jeu de données.
Classe de base d'une option dynamique.
String m_value
Nom de l'option.
String m_service_name
Valeur de l'option (si option CO_Simple)
Liste d'options du jeu de données.
OptionList()
Construit un jeu d'options vide.
Noms des noeuds XML d'un jeu de données Arcane.
Gestionnaire d'un document DOM.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-