Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
PrintCaseDocumentVisitor.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* Visitor to display the values of the dataset. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/NotImplementedException.h"
15
16#include "arcane/core/AbstractCaseDocumentVisitor.h"
17
18#include "arcane/core/CaseOptions.h"
19#include "arcane/core/CaseOptionService.h"
20#include "arcane/core/ICaseFunction.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
34class PrintCaseDocumentVisitor
36{
37 public:
38
39 struct Indent
40 {
41 Indent(int n)
42 : m_n(n)
43 {}
44 int m_n;
45 };
46
47 public:
48
49 PrintCaseDocumentVisitor(ITraceMng* tm, const String& lang)
50 : m_trace_mng(tm)
51 , m_lang(lang)
52 {
53 }
54 void beginVisit(const ICaseOptions* opt) override;
55 void endVisit(const ICaseOptions* opt) override;
56 void applyVisitor(const CaseOptionSimple* opt) override
57 {
58 _printOption(opt);
59 }
60 void applyVisitor(const CaseOptionMultiSimple* opt) override
61 {
62 _printOption(opt);
63 }
64 void applyVisitor(const CaseOptionExtended* opt) override
65 {
66 _printOption(opt);
67 }
68 void applyVisitor(const CaseOptionMultiExtended* opt) override
69 {
70 _printOption(opt);
71 }
72 void applyVisitor(const CaseOptionEnum* opt) override
73 {
74 _printOption(opt);
75 }
76 void applyVisitor(const CaseOptionMultiEnum* opt) override
77 {
78 _printOption(opt);
79 }
80 void beginVisit(const CaseOptionServiceImpl* opt) override
81 {
82 //std::cout << "BEGIN_VISIT SERVICE name=" << opt->name() << "\n";
83 // The visitor first calls the service and then the ICaseOptions associated
84 // with this service
85 m_current_service_name = opt->serviceName();
86 }
87 void endVisit(const CaseOptionServiceImpl* opt) override
88 {
89 ARCANE_UNUSED(opt);
90 //std::cout << "END_VISIT SERVICE name=" << opt->name() << "\n";
91 }
92 void beginVisit(const CaseOptionMultiServiceImpl* opt, Integer index) override
93 {
94 //std::cout << "WARNING: BEGIN MULTI_SERVICE index=" << index << "\n";
95 m_current_service_name = opt->serviceName(index);
96 //opt->print(m_lang,m_stream);
97 }
98 void endVisit(const CaseOptionMultiServiceImpl* opt, Integer index) override
99 {
100 ARCANE_UNUSED(opt);
101 ARCANE_UNUSED(index);
102 //std::cout << "WARNING: END MULTI_SERVICE\n";
103 //opt->print(m_lang,m_stream);
104 }
105
106 protected:
107
108 void _printOption(const CaseOptionBase* co)
109 {
110 m_stream = std::ostringstream();
111 std::ostream& o = m_stream;
112 _printOption(co, o);
113 m_trace_mng->info() << m_stream.str();
114 }
115 void _printOption(const CaseOptionBase* co, std::ostream& o);
116
117 private:
118
119 ITraceMng* m_trace_mng;
120 String m_lang;
121 std::ostringstream m_stream;
122 int m_indent = 0;
123 String m_current_service_name;
124};
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
129inline std::ostream&
130operator<<(std::ostream& o, const PrintCaseDocumentVisitor::Indent& indent)
131{
132 for (int i = 0; i < indent.m_n; ++i)
133 o << ' ';
134 return o;
135}
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
140void PrintCaseDocumentVisitor::
141beginVisit(const ICaseOptions* opt)
142{
143 String service_name;
144 if (!m_current_service_name.null()) {
145 service_name = " name=\"" + m_current_service_name + "\"";
146 }
147 else {
148 IServiceInfo* service = opt->caseServiceInfo();
149 if (service)
150 m_trace_mng->info() << "WARNING: service_name not handled name=\"" + service->localName() + "\"";
151 }
152 m_current_service_name = String();
153 m_trace_mng->info() << Indent(m_indent) << "<" << opt->translatedName(m_lang) << service_name << ">";
154 ++m_indent;
155}
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
160void PrintCaseDocumentVisitor::
161endVisit(const ICaseOptions* opt)
162{
163 --m_indent;
164 m_trace_mng->info() << Indent(m_indent) << "</" << opt->translatedName(m_lang) << ">";
165}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
170void PrintCaseDocumentVisitor::
171_printOption(const CaseOptionBase* co, std::ostream& o)
172{
173 std::ios_base::fmtflags f = o.flags(std::ios::left);
174 o << " ";
175 o << Indent(m_indent);
176 o.width(40 - m_indent);
177 o << co->translatedName(m_lang);
178 co->print(m_lang, o);
179 ICaseFunction* func = co->function();
180 if (func) {
181 o << " (fonction: " << func->name() << ")";
182 }
183 o.flags(f);
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189extern "C++" std::unique_ptr<ICaseDocumentVisitor>
190createPrintCaseDocumentVisitor(ITraceMng* tm, const String& lang)
191{
192 return std::make_unique<PrintCaseDocumentVisitor>(tm, lang);
193}
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198} // End namespace Arcane
199
200/*---------------------------------------------------------------------------*/
201/*---------------------------------------------------------------------------*/
Abstract visitor for a scalar data point.
Base class for a data set option.
Base class for simple options (single value).
Interface for a list of data set options.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.