Arcane  v4.1.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ArccoreGlobal.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/* ArccoreGlobal.cc (C) 2000-2026 */
9/* */
10/* Déclarations générales de Arccore. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
15#include "arccore/base/TraceInfo.h"
16#include "arccore/base/PlatformUtils.h"
17#include "arccore/base/String.h"
18#include "arccore/base/IndexOutOfRangeException.h"
19#include "arccore/base/FatalErrorException.h"
20#include "arccore/base/Ref.h"
21
22// Nécessaire pour les exports de symboles
24#include "arccore/base/Float16.h"
25#include "arccore/base/BFloat16.h"
26#include "arccore/base/Float128.h"
27#include "arccore/base/Int128.h"
28#include "arccore/base/IRangeFunctor.h"
29#include "arccore/base/CheckedConvert.h"
30#include "arccore/base/ForLoopRunInfo.h"
31#include "arccore/base/ForLoopRanges.h"
32#include "arccore/base/ParallelLoopOptions.h"
33#include "arccore/base/ISymbolizerService.h"
34#include "arccore/base/internal/IDynamicLibraryLoader.h"
35
36#include <iostream>
37#include <cstring>
38#include <sstream>
39#include <cstdarg>
40
41#ifndef ARCCORE_OS_WIN32
42#include <unistd.h>
43#endif
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47/*!
48 * \file ArccoreGlobal.h
49 *
50 * \brief Définitions et globaux de %Arccore
51 */
52/*!
53 * \namespace Arccore
54 *
55 * \brief Espace de nom de %Arccore
56 *
57 * Toutes les classes et types utilisés dans \b Arccore sont dans ce
58 * namespace.
59 */
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63namespace Arcane
64{
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68namespace
69{
70#ifdef ARCCORE_CHECK
71static bool global_arccore_is_check = true;
72#else
73static bool global_arccore_is_check = false;
74#endif
75}
76
77extern "C++" ARCCORE_BASE_EXPORT
79{
80 return global_arccore_is_check;
81}
82
83extern "C++" ARCCORE_BASE_EXPORT
84void arccoreSetCheck(bool v)
85{
86 global_arccore_is_check = v;
87}
88
89extern "C++" ARCCORE_BASE_EXPORT
91{
92#ifdef ARCCORE_DEBUG
93 return true;
94#else
95 return false;
96#endif
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102namespace
103{
104bool global_pause_on_error = false;
105}
106
107extern "C++" ARCCORE_BASE_EXPORT void
109{
110 global_pause_on_error = v;
111}
112
113extern "C++" ARCCORE_BASE_EXPORT void
114arccoreDebugPause(const char* msg)
115{
116 if (global_pause_on_error){
117 std::ostringstream ostr;
118 String host_name(Platform::getHostName());
119 ostr << "** FATAL: Debug mode activated. Execution paused\n"
120 << "** FATAL: message:" << msg << "\n"
121 << "** FATAL: To find the location of the error, start\n"
122 << "** FATAL: start the debugger using the process number\n"
123 << "** FATAL: (pid=" << Platform::getProcessId() << ",host=" << host_name << ").\n";
124 std::cerr << ostr.str();
125#ifndef ARCCORE_OS_WIN32
126 ::pause();
127#endif
128 }
129}
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
133
134extern "C++" ARCCORE_BASE_EXPORT void
135arccoreRangeError(Int64 i,Int64 min_value_inclusive,Int64 max_value_exclusive)
136{
137 arccoreDebugPause("arccoreRangeError");
138 throw IndexOutOfRangeException(A_FUNCINFO,String(),i,min_value_inclusive,max_value_exclusive);
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144extern "C++" ARCCORE_BASE_EXPORT void
145arccoreRangeError(Int32 i,Int32 max_size)
146{
147 arccoreDebugPause("arccoreRangeError");
148 throw IndexOutOfRangeException(A_FUNCINFO,String(),i,0,max_size);
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154extern "C++" ARCCORE_BASE_EXPORT void
156{
157 arccoreDebugPause("arccoreRangeError");
158 throw IndexOutOfRangeException(A_FUNCINFO,String(),i,0,max_size);
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164extern "C++" ARCCORE_BASE_EXPORT void
166{
167 std::cerr << "** FATAL: null pointer.\n";
168 std::cerr << "** FATAL: Trying to dereference a null pointer.\n";
169 arccoreDebugPause("arcaneNullPointerPtr");
170 throw FatalErrorException(A_FUNCINFO,"null pointer");
171}
172
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176extern "C++" ARCCORE_BASE_EXPORT void
177arccoreThrowNullPointerError(const char* ptr_name,const char* text)
178{
179 throw FatalErrorException(A_FUNCINFO,text ? text : ptr_name);
180}
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
185// Cette fonction peut être appelée souvent et certaines fois
186// dans des conditions d'exceptions. Pour cette raison, il ne
187// faut pas qu'elle fasse d'allocations.
188namespace
189{
190void _printFuncName(std::ostream& o,const char* name)
191{
192 const char* par_pos = std::strchr(name,'(');
193 if (!par_pos){
194 o << name;
195 return;
196 }
197
198 // Recherche quelque chose du type namespace::class_name::func_name
199 // et essaye de ne conserver que class_name::func_name
200 ptrdiff_t len = par_pos - name;
201 ptrdiff_t last_scope = 0;
202 ptrdiff_t last_scope2 = 0;
203 for( ptrdiff_t i=0; i<len; ++i ){
204 if (name[i]==':' && name[i+1]==':'){
205 last_scope2 = last_scope;
206 last_scope = i;
207 }
208 }
209 if (last_scope2!=0)
210 last_scope2+=2;
211 ptrdiff_t true_pos = last_scope2;
212 ptrdiff_t true_len = len - true_pos;
213 o.write(&name[true_pos],true_len);
214 o << "()";
215}
216}
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
220
221extern "C++" ARCCORE_BASE_EXPORT std::ostream&
222operator<<(std::ostream& o,const TraceInfo& t)
223{
224 if (t.printSignature())
225 o << t.name() << ":" << t.line();
226 else{
227 _printFuncName(o,t.name());
228 }
229 return o;
230}
231
232/*---------------------------------------------------------------------------*/
233/*---------------------------------------------------------------------------*/
234
235/*---------------------------------------------------------------------------*/
236/*---------------------------------------------------------------------------*/
237
238namespace
239{
240/// Fonction appelée lorsqu'une assertion échoue.
241typedef void (*fDoAssert)(const char*,const char*,const char*,size_t);
242/// Fonction appelée pour indiquer s'il faut afficher l'information de débug
243typedef bool (*fCheckDebug)(unsigned int);
244
245fDoAssert g_do_assert_func = 0;
246}
247
248/*---------------------------------------------------------------------------*/
249/*---------------------------------------------------------------------------*/
250/*!
251 * Affichage d'une assertion ayant échouée.
252 */
253extern "C++" ARCCORE_BASE_EXPORT void
254_doAssert(const char* text,const char* file,const char* func,int line)
255{
256 if (g_do_assert_func)
257 (*g_do_assert_func)(text,file,func,line);
258 else{
259 std::ostringstream ostr;
260 ostr << text << ':' << file << ':' << func << ':' << line << ": ";
261 throw FatalErrorException("Assert",ostr.str());
262 }
263}
264
265/*---------------------------------------------------------------------------*/
266/*---------------------------------------------------------------------------*/
267
268extern "C++" ARCCORE_BASE_EXPORT void
269arccorePrintf(const char* format,...)
270{
271 // \n écrit en meme temps pour éviter des écritures intermédiares parasites
272 char buffer[4096];
273 va_list ap;
274 va_start(ap,format);
275 vsnprintf(buffer,4095,format,ap);
276 va_end(ap);
277 std::cerr << buffer << "\n";
278 std::cout << "*E* " << buffer << "\n";
279}
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283
284} // End namespace Arccore
285
286/*---------------------------------------------------------------------------*/
287/*---------------------------------------------------------------------------*/
Définitions et globaux de Arccore.
Gestion des références à une classe C++.
Exception lorsqu'une erreur fatale est survenue.
Exception lorsqu'une valeur n'est pas dans un intervalle donné.
Chaîne de caractères unicode.
Integer len(const char *s)
Retourne la longueur de la chaîne s.
String getHostName()
Nom de la machine sur lequel tourne le processus.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
void arccoreSetPauseOnError(bool v)
Indique si on l'appel à arccoreDebugPause() effectue une pause.
void arccoreDebugPause(const char *msg)
Passe en mode pause ou lance une erreur fatale.
bool arccoreIsDebug()
Vrai si la macro ARCCORE_DEBUG est définie.
void arccoreThrowNullPointerError(const char *ptr_name, const char *text)
Signalee l'utilisation d'un pointeur nul en envoyant une exception.
std::int64_t Int64
Type entier signé sur 64 bits.
void arccorePrintf(const char *format,...)
Encapsulation de la fonction C printf.
void arccoreRangeError(Int64 i, Int64 min_value_inclusive, Int64 max_value_exclusive)
Signale qu'une valeur n'est pas dans l'intervalle souhaité.
void(* fDoAssert)(const char *, const char *, const char *, size_t)
Fonction appelée lorsqu'une assertion échoue.
Definition Misc.cc:212
void arccoreNullPointerError()
Signalue l'utilisation d'un pointeur nul.
void arccoreSetCheck(bool v)
Active ou désactive le mode vérification.
bool(* fCheckDebug)(unsigned int)
Fonction appelée pour indiquer s'il faut afficher l'information de débug.
Definition Misc.cc:214
void _doAssert(const char *text, const char *file, const char *func, size_t line)
Definition Misc.cc:225
bool arccoreIsCheck()
Vrai si on est en mode vérification.
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Opérateur de sortie sur un flot.