Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
PrintCaseDocumentVisitor.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* PrintCaseDocumentVisitor.h (C) 2000-2019 */
9/* */
10/* Visiteur pour afficher les valeurs du jeu de données. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/NotImplementedException.h"
15
16#include "arcane/AbstractCaseDocumentVisitor.h"
17
18#include "arcane/CaseOptions.h"
19#include "arcane/CaseOptionService.h"
20#include "arcane/ICaseFunction.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
35{
36 public:
37 struct Indent
38 {
39 Indent(int n): m_n(n) {}
40 int m_n;
41 };
42 public:
44 : m_trace_mng(tm), m_lang(lang)
45 {
46 }
47 void beginVisit(const ICaseOptions* opt) override;
48 void endVisit(const ICaseOptions* opt) override;
49 void applyVisitor(const CaseOptionSimple* opt) override
50 {
51 _printOption(opt);
52 }
53 void applyVisitor(const CaseOptionMultiSimple* opt) override
54 {
55 _printOption(opt);
56 }
57 void applyVisitor(const CaseOptionExtended* opt) override
58 {
59 _printOption(opt);
60 }
61 void applyVisitor(const CaseOptionMultiExtended* opt) override
62 {
63 _printOption(opt);
64 }
65 void applyVisitor(const CaseOptionEnum* opt) override
66 {
67 _printOption(opt);
68 }
69 void applyVisitor(const CaseOptionMultiEnum* opt) override
70 {
71 _printOption(opt);
72 }
73 void beginVisit(const CaseOptionServiceImpl* opt) override
74 {
75 //std::cout << "BEGIN_VISIT SERVICE name=" << opt->name() << "\n";
76 // Le visiteur appelle d'abord le service puis le ICaseOptions associé
77 // à ce service
78 m_current_service_name = opt->serviceName();
79 }
80 void endVisit(const CaseOptionServiceImpl* opt) override
81 {
82 ARCANE_UNUSED(opt);
83 //std::cout << "END_VISIT SERVICE name=" << opt->name() << "\n";
84 }
85 void beginVisit(const CaseOptionMultiServiceImpl* opt,Integer index) override
86 {
87 //std::cout << "WARNING: BEGIN MULTI_SERVICE index=" << index << "\n";
88 m_current_service_name = opt->serviceName(index);
89 //opt->print(m_lang,m_stream);
90 }
91 void endVisit(const CaseOptionMultiServiceImpl* opt,Integer index) override
92 {
93 ARCANE_UNUSED(opt);
94 ARCANE_UNUSED(index);
95 //std::cout << "WARNING: END MULTI_SERVICE\n";
96 //opt->print(m_lang,m_stream);
97 }
98 protected:
99 void _printOption(const CaseOptionBase* co)
100 {
101 m_stream = std::ostringstream();
102 std::ostream& o = m_stream;
103 _printOption(co,o);
104 m_trace_mng->info() << m_stream.str();
105 }
106 void _printOption(const CaseOptionBase* co,std::ostream& o);
107 private:
108 ITraceMng* m_trace_mng;
109 String m_lang;
110 std::ostringstream m_stream;
111 int m_indent = 0;
112 String m_current_service_name;
113};
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118inline std::ostream&
119operator<< (std::ostream& o, const PrintCaseDocumentVisitor::Indent& indent)
120{
121 for( int i=0; i<indent.m_n; ++i )
122 o << ' ';
123 return o;
124}
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
129void PrintCaseDocumentVisitor::
130beginVisit(const ICaseOptions* opt)
131{
132 String service_name;
133 if (!m_current_service_name.null()){
134 service_name = " name=\""+ m_current_service_name + "\"";
135 }
136 else {
137 IServiceInfo* service = opt->caseServiceInfo();
138 if (service)
139 m_trace_mng->info() << "WARNING: service_name not handled name=\""+ service->localName() + "\"";
140 }
141 m_current_service_name = String();
142 m_trace_mng->info() << Indent(m_indent) << "<" << opt->translatedName(m_lang) << service_name << ">";
143 ++m_indent;
144}
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
149void PrintCaseDocumentVisitor::
150endVisit(const ICaseOptions* opt)
151{
152 --m_indent;
153 m_trace_mng->info() << Indent(m_indent) << "</" << opt->translatedName(m_lang) << ">";
154}
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159void PrintCaseDocumentVisitor::
160_printOption(const CaseOptionBase* co,std::ostream& o)
161{
162 std::ios_base::fmtflags f = o.flags(std::ios::left);
163 o << " ";
164 o << Indent(m_indent);
165 o.width(40-m_indent);
166 o << co->translatedName(m_lang);
167 co->print(m_lang,o);
168 ICaseFunction* func = co->function();
169 if (func){
170 o << " (fonction: " << func->name() << ")";
171 }
172 o.flags(f);
173}
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178extern "C++" std::unique_ptr<ICaseDocumentVisitor>
179createPrintCaseDocumentVisitor(ITraceMng* tm,const String& lang)
180{
181 return std::make_unique<PrintCaseDocumentVisitor>(tm,lang);
182}
183
184/*---------------------------------------------------------------------------*/
185/*---------------------------------------------------------------------------*/
186
187} // End namespace Arcane
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
Visiteur abstrait pour une donnée scalaire.
Classe de base des options simples (uniquement une valeur).
Interface d'une liste d'options du jeu de données.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Visiteur pour afficher les valeurs du jeu de données.
Interface du gestionnaire de traces.
virtual TraceMessage info()=0
Flot pour un message d'information.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
Definition String.cc:304
std::ostream & operator<<(std::ostream &o, eExecutionPolicy exec_policy)
Affiche le nom de la politique d'exécution.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-