14#include "arcane/core/AxlOptionsBuilder.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/Array.h"
18#include "arcane/utils/JSONWriter.h"
19#include "arcane/utils/ScopedPtr.h"
21#include "arcane/core/DomUtils.h"
22#include "arcane/core/XmlNode.h"
23#include "arcane/core/IXmlDocumentHolder.h"
24#include "arcane/core/CaseNodeNames.h"
29namespace Arcane::AxlOptionsBuilder
47 void add(
const std::initializer_list<OneOption>& options)
49 for (
const auto& o : options)
75 const std::initializer_list<OneOption>& options)
78 m_sub_option->add(options);
86ServiceInstance(
const String& option_name,
const String& service_name,
87 const OptionList& options)
88: OneOption(
Type::CO_ServiceInstance, option_name, options)
90 m_service_name = service_name;
97ServiceInstance(
const String& option_name,
const String& service_name)
98: OneOption(
Type::CO_ServiceInstance, option_name, String{})
100 m_service_name = service_name;
107Complex(
const String& name,
const std::initializer_list<OneOption>& options)
108: OneOption(
Type::CO_Complex, name, OptionList{})
110 m_sub_option->add(options);
117Complex(
const String& name,
const OptionList& options)
118: OneOption(
Type::CO_Complex, name, options)
138OptionList(
const std::initializer_list<OneOption>& options)
150 m_p->m_options.add(
OneOption(OneOption::Type::CO_Complex, name,
option));
157OptionList& OptionList::
158add(
const std::initializer_list<OneOption>& options)
160 for (
const auto& o : options)
161 m_p->m_options.add(o);
168OptionList OptionList::
172 new_opt.m_p->m_options = m_p->m_options;
189 auto*
doc = domutils::createXmlDocument();
206 if (o.m_sub_option.get())
209 if (!o.m_service_name.null())
212 if (!o.m_function_name.null()) {
222 : m_case_node_names(
lang)
243 return writer.m_json_writer.getBuffer();
251 m_json_writer.write(
"language",
doc.language());
252 m_json_writer.write(
"version",
"1");
255 _write(
doc.m_options.m_p.get());
276 if (o.m_type==OneOption::Type::CO_ServiceInstance){
284 if (o.m_type==OneOption::Type::CO_Complex){
298 if (!o.m_function_name.
null()) {
300 m_json_writer.write(m_case_function_json_name,o.m_function_name);
301 m_json_writer.write(
"$value",o.
m_value);
305 m_json_writer.write(o.m_name, o.
m_value);
311 : m_case_node_names(
lang)
313 m_case_function_json_name =
String(
"$") + m_case_node_names.function_ref;
320 String m_case_function_json_name;
329 return DocumentXmlWriter::toXml(d);
346extern "C++" ARCANE_CORE_EXPORT
void
347_testAxlOptionsBuilder()
349 using namespace AxlOptionsBuilder;
350 std::cout <<
"TestOptionList\n";
351 OptionList sub_opt({ Simple(
"max", 35),
353 Simple(
"test", 1) });
355 OptionList service_opt({ Simple(
"service-option1", 42),
356 Simple(
"service-option2", -1.5) });
358 OptionList dco({ Simple(
"toto", 3),
359 Simple(
"titi", 3.1).addFunction(
"func1"),
360 Simple(
"tutu",
"Hello"),
361 Enumeration(
"a",
"vx"),
362 Extended(
"extended1",
"ext"),
363 ServiceInstance(
"my-service1",
"TestService1",
364 { Simple(
"service-option1", 25),
365 Simple(
"service-option2", 3.2) }),
366 ServiceInstance(
"my-service2",
"TestService2"),
368 ServiceInstance(
"my-service3",
"TestService3", service_opt),
372 Simple(
"test", 4) }),
373 Complex(
"sub-opt2", sub_opt) });
375 ScopedPtrT<IXmlDocumentHolder> x(DocumentXmlWriter::toXml(doc));
376 String s = x->save();
377 std::cout <<
"VALUE:" << s <<
"\n";
379 String ref_str =
"<?xml version=\"1.0\"?>\n"
380 "<root xml:lang=\"fr\"><dynamic-options><toto>3</toto><titi fonction=\"func1\">3.1</titi>"
381 "<tutu>Hello</tutu><a>vx</a><extended1>ext</extended1><my-service1 name=\"TestService1\">"
382 "<service-option1>25</service-option1><service-option2>3.2</service-option2></my-service1>"
383 "<my-service2 name=\"TestService2\"/><my-service3 name=\"TestService3\">"
384 "<service-option1>42</service-option1><service-option2>-1.5</service-option2></my-service3>"
385 "<sub-opt1><max>25</max><min>23.2</min><test>4</test></sub-opt1><sub-opt2><max>35</max>"
386 "<min>13.2</min><test>1</test></sub-opt2></dynamic-options></root>\n";
388 ARCANE_FATAL(
"BAD VALUE v={0} expected={1}", s, ref_str);
391 String json_string = DocumentJSONWriter::toJSON(doc);
393 std::ofstream ofile(
"test1.json");
394 ofile << json_string;
396 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 -*-