Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
TraceMessage.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/* TraceMessage.cc (C) 2000-2025 */
9/* */
10/* Message management. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/trace/ITraceMng.h"
15#include "arccore/base/String.h"
16
17#include <iostream>
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28TraceMessage::
29TraceMessage(std::ostream* ostr, ITraceMng* m, Trace::eMessageType id, int level)
30: m_stream(ostr)
31, m_parent(m)
32, m_type(id)
33, m_level(level)
34, m_color(0)
35{
36 if (m_parent)
37 m_parent->beginTrace(this);
38}
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43TraceMessage::
44TraceMessage(const TraceMessage& from)
45: m_stream(from.m_stream)
46, m_parent(from.m_parent)
47, m_type(from.m_type)
48, m_level(from.m_level)
49, m_color(from.m_color)
50{
51 if (m_parent)
52 m_parent->beginTrace(this);
53}
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58const TraceMessage& TraceMessage::
59operator=(const TraceMessage& from)
60{
61 ITraceMng* from_parent = from.parent();
62 if (from_parent)
63 from_parent->beginTrace(&from);
64 if (m_parent)
65 m_parent->endTrace(this);
66 m_stream = from.m_stream;
67 m_parent = from_parent;
68 m_type = from.m_type;
69 m_level = from.m_level;
70 m_color = from.m_color;
71 return *this;
72}
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77// NOTE: this destructor may throw an exception if the message is
78// of type Fatal or ParallelFatal. With C++11, it must be signaled
79// explicitly otherwise the code terminates via a call to std::terminate().
80// Note that with gcc 4.7 and before, even with the std=c++11 option it is
81// not necessary to specify noexcept.
82TraceMessage::
83~TraceMessage() ARCCORE_NOEXCEPT_FALSE
84{
85 if (m_parent)
86 m_parent->endTrace(this);
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92const TraceMessage& TraceMessage::
93width(Integer v) const
94{
95 m_stream->width(v);
96 return *this;
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102std::ostream& TraceMessage::
103file() const
104{
105 return *m_stream;
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113//static int zeroi = 0;
114std::ostream& Trace::
115operator<<(std::ostream& o, const Trace::Width& w)
116{
117 o.width(w.m_width);
118 //if (zeroi==1)
119 //o.flags(ios::left|ios::scientific);
120 //++zeroi;
121 return o;
122}
123
124std::ostream& Trace::
125operator<<(std::ostream& o, const Trace::Precision& w)
126{
127 bool is_scientific = w.m_scientific;
128 std::ios::fmtflags old_flags = o.flags();
129 if (is_scientific) {
130 o.flags(std::ios::scientific);
131 }
132 std::streamsize p = o.precision(w.m_precision);
133 o << w.m_value;
134 o.precision(p);
135 if (is_scientific)
136 o.flags(old_flags);
137 return o;
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143const TraceMessage&
144operator<<(const TraceMessage& o, const Trace::Color& c)
145{
146 o.m_color = c.m_color;
147 return o;
148}
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156Trace::Setter::
157Setter(ITraceMng* msg, const String& name)
158: m_msg(msg)
159{
160 m_msg->pushTraceClass(name);
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
167~Setter()
168{
169 m_msg->popTraceClass();
170 m_msg->flush();
171}
172
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176} // namespace Arcane
177
178/*---------------------------------------------------------------------------*/
179/*---------------------------------------------------------------------------*/
~Setter()
Releases the instance and restores the previous message class in m_msg.
eMessageType
Stream on which messages are sent.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --