Arcane  v4.1.1.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ArccoreGlobal.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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.h (C) 2000-2025 */
9/* */
10/* Déclarations générales de Arccore. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_BASE_ARCCOREGLOBAL_H
13#define ARCCORE_BASE_ARCCOREGLOBAL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include <cstdint>
18
19#include "arccore/arccore_config.h"
20
21#ifdef ARCCORE_VALID_TARGET
22# undef ARCCORE_VALID_TARGET
23#endif
24
25// Determine le type de l'os.
26#if defined(__linux)
27# define ARCCORE_OS_LINUX
28#elif defined(__APPLE__) && defined(__MACH__)
29# define ARCCORE_OS_MACOS
30#elif defined(_AIX)
31# define ARCCORE_OS_AIX
32#elif defined(__WIN32__) || defined(__NT__) || defined(WIN32) || defined(_WIN32) || defined(WIN32) || defined(_WINDOWS)
33# define ARCCORE_OS_WIN32
34#elif defined(__CYGWIN__)
35# define ARCCORE_OS_CYGWIN
36#endif
37
38#ifdef ARCCORE_OS_WIN32
39# define ARCCORE_VALID_TARGET
40# define ARCCORE_EXPORT __declspec(dllexport)
41# define ARCCORE_IMPORT __declspec(dllimport)
42
43/* Supprime certains avertissements du compilateur Microsoft */
44# ifdef _MSC_VER
45# pragma warning(disable: 4251) // class 'A' needs to have dll interface for to be used by clients of class 'B'.
46# pragma warning(disable: 4275) // non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
47# pragma warning(disable: 4800) // 'type' : forcing value to bool 'true' or 'false' (performance warning)
48# pragma warning(disable: 4355) // 'this' : used in base member initializer list
49# endif
50
51#endif
52
53// Sous Unix, indique que par défaut les symboles de chaque .so sont cachés.
54// Il faut alors explicitement marquer les
55// symboles qu'on souhaite exporter, comme sous windows.
56// La seule différence est que pour gcc avec les instantiations explicites
57// de template, il faut spécifier l'export lors de l'instantiation
58// explicite alors que sous windows c'est dans la classe.
59#ifndef ARCCORE_OS_WIN32
60# define ARCCORE_EXPORT __attribute__ ((visibility("default")))
61# define ARCCORE_IMPORT __attribute__ ((visibility("default")))
62# define ARCCORE_TEMPLATE_EXPORT ARCCORE_EXPORT
63#endif
64
65#ifdef ARCCORE_OS_CYGWIN
66# define ARCCORE_VALID_TARGET
67#endif
68
69#ifdef ARCCORE_OS_LINUX
70# define ARCCORE_VALID_TARGET
71#endif
72
73#ifdef ARCCORE_OS_MACOS
74# define ARCCORE_VALID_TARGET
75#endif
76
77#ifndef ARCCORE_VALID_TARGET
78#error "This target is not supported"
79#endif
80
81#ifndef ARCCORE_EXPORT
82#define ARCCORE_EXPORT
83#endif
84
85#ifndef ARCCORE_IMPORT
86#define ARCCORE_IMPORT
87#endif
88
89#ifndef ARCCORE_TEMPLATE_EXPORT
90#define ARCCORE_TEMPLATE_EXPORT
91#endif
92
93#ifndef ARCCORE_RESTRICT
94#define ARCCORE_RESTRICT
95#endif
96
97#define ARCCORE_STD std
98
99//Tag var as a voluntary unused variable.
100//Works with any compiler but might be improved by using attribute.
101#define ARCCORE_UNUSED(var) do { (void)(var) ; } while(false)
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106#ifdef DOXYGEN_DOC
107typedef ARCCORE_TYPE_INT16 Int16;
108typedef ARCCORE_TYPE_INT32 Int32;
109typedef ARCCORE_TYPE_INT64 Int64;
110#endif
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114/*
115 * Macros pour le support de la programmation hétérogène (CPU/GPU)
116 - ARCCORE_DEVICE_CODE: indique une partie de code compilée uniquement sur le device
117 - ARCCORE_HOST_DEVICE: indique que la méthode/variable est accessible à la fois
118 sur le device et l'hôte
119 - ARCCORE_DEVICE: indique que la méthode/variable est accessible uniquement sur
120 le device.
121*/
122
123#if defined(__SYCL_DEVICE_ONLY__)
124# define ARCCORE_DEVICE_CODE
125# define ARCCORE_DEVICE_TARGET_SYCL
126#elif defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
127# define ARCCORE_DEVICE_CODE
128# if defined(__HIP_DEVICE_COMPILE__)
129# define ARCCORE_DEVICE_TARGET_HIP
130# endif
131# if defined(__CUDA_ARCH__)
132# define ARCCORE_DEVICE_TARGET_CUDA
133// Nécessaire pour assert() par exemple dans arccoreCheckAt()
134// TODO: regarder si cela est aussi nécessaire pour AMD HIP.
135#include <cassert>
136# endif
137#endif
138
139#if defined(__CUDACC__) || defined(__HIP__)
140#define ARCCORE_HOST_DEVICE __host__ __device__
141#define ARCCORE_DEVICE __device__
142#endif
143
144
145#ifndef ARCCORE_HOST_DEVICE
146#define ARCCORE_HOST_DEVICE
147#endif
148
149#ifndef ARCCORE_DEVICE
150#define ARCCORE_DEVICE
151#endif
152
153#if defined(ARCCORE_HAS_CUDA) && defined(__CUDACC__)
154/*!
155 * \brief Macro pour indiquer qu'on compile %Arcane avec le support
156 * de CUDA et qu'on utilise le compilateur CUDA.
157 */
158#define ARCCORE_COMPILING_CUDA
159//! \deprecated
160#define ARCANE_COMPILING_CUDA
161#endif
162#if defined(ARCCORE_HAS_HIP) && defined(__HIP__)
163/*!
164 * \brief Macro pour indiquer qu'on compile %Arcane avec le support
165 * de HIP et qu'on utilise le compilateur HIP.
166 */
167#define ARCCORE_COMPILING_HIP
168//! \deprecated
169#define ARCANE_COMPILING_HIP
170#endif
171
172#if defined(ARCCORE_HAS_SYCL)
173# if defined(SYCL_LANGUAGE_VERSION) || defined(__ADAPTIVECPP__)
174/*!
175 * \brief Macro pour indiquer qu'on compile %Arcane avec le support
176 * de SYCL et qu'on utilise le compilateur SYCL.
177 */
178# define ARCCORE_COMPILING_SYCL
179//! \deprecated
180# define ARCANE_COMPILING_SYCL
181# endif
182#endif
183
184#if defined(ARCCORE_COMPILING_CUDA) || defined(ARCCORE_COMPILING_HIP)
185/*!
186 * \brief Macro pour indiquer qu'on compile avec le support
187 * de CUDA ou de HIP.
188 */
189#define ARCCORE_COMPILING_CUDA_OR_HIP
190//! \deprecated
191#define ARCANE_COMPILING_CUDA_OR_HIP
192#endif
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197#if defined(ARCCORE_COMPONENT_arccore_base)
198#define ARCCORE_BASE_EXPORT ARCCORE_EXPORT
199#define ARCCORE_BASE_EXTERN_TPL
200#else
201#define ARCCORE_BASE_EXPORT ARCCORE_IMPORT
202#define ARCCORE_BASE_EXTERN_TPL extern
203#endif
204
205#ifdef ARCCORE_REAL_USE_APFLOAT
206# include <apfloat.h>
207#endif
208
209/*---------------------------------------------------------------------------*/
210/*---------------------------------------------------------------------------*/
211
212namespace Arcane
213{
214
215/*---------------------------------------------------------------------------*/
216/*---------------------------------------------------------------------------*/
217/*
218 * Définition des types Arccore Int16, Int32 et Int64.
219 */
220//! Type entier signé sur 8 bits
221using Int8 = std::int8_t;
222//! Type entier signé sur 16 bits
223using Int16 = std::int16_t;
224//! Type entier signé sur 32 bits
225using Int32 = std::int32_t;
226//! Type entier signé sur 64 bits
227using Int64 = std::int64_t;
228//! Type entier non signé sur 32 bits
229using UInt32 = std::uint32_t;
230//! Type entier non signé sur 64 bits
231using UInt64 = std::uint64_t;
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
235/*!
236 * \brief Type représentant un pointeur.
237 *
238 * Il doit être utilisé partout ou un objet de type pointeur quelconque est attendu.
239 */
240using Pointer = void*;
241
242#ifdef ARCCORE_REAL_USE_APFLOAT
243# define ARCCORE_REAL(val) (Real(#val,1000))
244# define ARCCORE_REAL_NOT_BUILTIN
245using Real = apfloat;
246using APReal = apfloat;
247#else
248# ifdef ARCCORE_REAL_LONG
249# define ARCCORE_REAL(val) val##L
250/*!
251 * \brief Type représentant un réel.
252 *
253 * Il doit être utilisé partout ou un objet de type réel est attendu.
254 */
255using long double Real;
256# else
257# define ARCCORE_REAL(val) val
258# define ARCCORE_REAL_IS_DOUBLE
259/*!
260 * \brief Type représentant un réel.
261 *
262 * Il doit être utilisé partout ou un objet de type réel est attendu.
263 */
264using Real = double;
265# endif
266//! Emulation de réel en précision arbitraire.
268{
269 public:
270 Real v[4];
271};
272#endif
273
274#ifdef ARCCORE_64BIT
275# define ARCCORE_INTEGER_MAX ARCCORE_INT64_MAX
276using Short = Int32;
277using Integer = Int64;
278#else
279# define ARCCORE_INTEGER_MAX ARCCORE_INT32_MAX
280using Short = Int32;
282#endif
283
284/*!
285 * \def ARCCORE_INTEGER_MAX
286 * \brief Macro indiquant la valeur maximal que peut prendre le type #Integer
287 */
288
289
290/*!
291 * \typedef Int64
292 * \brief Type entier signé sur 64 bits.
293 */
294/*!
295 * \typedef Int32
296 * \brief Type entier signé sur 32 bits.
297 */
298/*!
299 * \typedef Int16
300 * \brief Type entier signé sur 16 bits.
301 */
302/*!
303 * \typedef Integer
304 * \brief Type représentant un entier
305 *
306 * Si la macro ARCCORE_64BIT est définie, le type Integer correspond à un
307 * entier Int64, sinon à un entier Int32.
308 */
309
310/*---------------------------------------------------------------------------*/
311/*---------------------------------------------------------------------------*/
312
313//! Brain Float16
314class BFloat16;
315
316//! Float 16 bit
317class Float16;
318
319//! Type flottant IEEE-753 simple précision
320using Float32 = float;
321
322//! Float 128 bit
323class Float128;
324
325//! Integer 128 bit
326class Int128;
327
328/*---------------------------------------------------------------------------*/
329/*---------------------------------------------------------------------------*/
330
331/*!
332 * \internal
333 * \brief Structure équivalente à la valeur booléenne \a vrai
334 */
335struct TrueType {};
336/*!
337 \internal
338 \brief Structure équivalente à la valeur booléenne \a vrai
339*/
340struct FalseType {};
341
342/*---------------------------------------------------------------------------*/
343/*---------------------------------------------------------------------------*/
344
345#ifdef __GNUG__
346# define ARCCORE_DEPRECATED __attribute__ ((deprecated))
347#endif
348
349#ifdef _MSC_VER
350# if _MSC_VER >= 1300
351# define ARCCORE_DEPRECATED __declspec(deprecated)
352# endif
353#endif
354
355#define ARCCORE_DEPRECATED_2017 ARCCORE_DEPRECATED
356#define ARCCORE_DEPRECATED_2018 ARCCORE_DEPRECATED
357#define ARCCORE_DEPRECATED_2019(reason) [[deprecated(reason)]]
358#define ARCCORE_DEPRECATED_2020(reason) [[deprecated(reason)]]
359#define ARCCORE_DEPRECATED_REASON(reason) [[deprecated(reason)]]
360
361// Définir cette macro si on souhaite supprimer de la compilation les
362// méthodes et types obsolètes.
363#define ARCCORE_NO_DEPRECATED
364
365#ifndef ARCCORE_DEPRECATED
366# define ARCCORE_DEPRECATED
367#endif
368
369/*---------------------------------------------------------------------------*/
370/*---------------------------------------------------------------------------*/
371
372/*---------------------------------------------------------------------------*/
373/*---------------------------------------------------------------------------*/
374// Macros de compatibilités avec les différents standards du C++.
375// Maintenant (en 2021) tous les compilateurs avec lesquels Arccore compile
376// ont le support du C++17 donc la plupart de ces macros ne sont plus utiles.
377// On les garde uniquement pour compatibilité avec le code existant.
378
379// La macro ARCCORE_NORETURN utilise l'attribut [[noreturn]] du C++11 pour
380// indiquer qu'une fonction ne retourne pas.
381#define ARCCORE_NORETURN [[noreturn]]
382
383//! Macro permettant de spécifier le mot-clé 'constexpr' du C++11
384#define ARCCORE_CONSTEXPR constexpr
385
386// Macro pour indiquer qu'on ne lance pas d'exceptions.
387#define ARCCORE_NOEXCEPT noexcept
388
389// Macros pour indiquer qu'on lance pas d'exceptions.
390#define ARCCORE_NOEXCEPT_FALSE noexcept(false)
391
392// Support pour operator[](a,b,...)
393#ifdef __cpp_multidimensional_subscript
394#define ARCCORE_HAS_MULTI_SUBSCRIPT
395#endif
396
397/*---------------------------------------------------------------------------*/
398/*---------------------------------------------------------------------------*/
399// Macros pour l'attribut [[no_unique_address]]
400// Avec VS2022, cet attribut n'est pas pris en compte et il faut
401// utiliser [[msvc::no_unique_address]]
402#ifdef _MSC_VER
403#define ARCCORE_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
404#else
405#define ARCCORE_NO_UNIQUE_ADDRESS [[no_unique_address]]
406#endif
407
408/*---------------------------------------------------------------------------*/
409/*---------------------------------------------------------------------------*/
410
411// Support pour l'alignement.
412// le C++11 utilise le mot clé alignas pour spécifier l'alignement.
413// Cela fonctionne avec GCC 4.9+ et Visual Studio 2015. Cela ne fonctionne
414// pas avec Visual Studio 2013. Donc pour Visual Studio on utilise dans tous
415// les cas __declspec qui fonctionne toujours. Sous Linux, __attribute__ fonctionne
416// aussi toujours donc on utilise cela. A noter que les structures Simd ont besoin
417// de l'attribut 'packed' qui n'existe que avec GCC et Intel. Il ne semble pas y avoir
418// d'équivalent avec MSVC.
419#ifdef _MSC_VER
420//! Macro pour garantir le compactage et l'alignement d'une classe sur \a value octets
421# define ARCCORE_ALIGNAS(value) __declspec(align(value))
422//! Macro pour garantir l'alignement d'une classe sur \a value octets
423# define ARCCORE_ALIGNAS_PACKED(value) __declspec(align(value))
424#else
425//! Macro pour garantir le compactage et l'alignement d'une classe sur \a value octets
426# define ARCCORE_ALIGNAS_PACKED(value) __attribute__ ((aligned (value),packed))
427//! Macro pour garantir l'alignement d'une classe sur \a value octets
428# define ARCCORE_ALIGNAS(value) __attribute__ ((aligned (value)))
429#endif
430
431/*---------------------------------------------------------------------------*/
432/*---------------------------------------------------------------------------*/
433
434#if defined(ARCCORE_CHECK) || defined(ARCCORE_DEBUG)
435# ifndef ARCCORE_DEBUG_ASSERT
436# define ARCCORE_DEBUG_ASSERT
437# endif
438#endif
439
440/*---------------------------------------------------------------------------*/
441/*---------------------------------------------------------------------------*/
442/*!
443 * \brief Vrai si on est en mode vérification.
444 *
445 * Ce mode est actif si la macro ARCCORE_CHECK est définie
446 * ou si la méthode arccoreSetCheck() a été positionnée a vrai.
447 */
448extern "C++" ARCCORE_BASE_EXPORT
449bool arccoreIsCheck();
450
451/*!
452 * \brief Active ou désactive le mode vérification.
453 *
454 * Le mode vérification est toujours actif si la macro ARCCORE_CHECK est définie.
455 * Sinon, il est possible de l'activer avec cette méthode. Cela permet
456 * d'activer certains tests même en mode optimisé.
457 */
458extern "C++" ARCCORE_BASE_EXPORT
459void arccoreSetCheck(bool v);
460
461/*!
462 * \brief Vrai si la macro ARCCORE_DEBUG est définie
463 */
464extern "C++" ARCCORE_BASE_EXPORT
466
467/*---------------------------------------------------------------------------*/
468/*---------------------------------------------------------------------------*/
469
470//! Encapsulation de la fonction C printf
471extern "C++" ARCCORE_BASE_EXPORT void
472arccorePrintf(const char*,...);
473
474/*---------------------------------------------------------------------------*/
475/*---------------------------------------------------------------------------*/
476/*!
477 * \brief Passe en mode pause ou lance une erreur fatale.
478 *
479 * Si arccoreSetPauseOnError() est appelé avec l'argument \a true,
480 * met le programme en pause
481 * pour éventuellement connecter un débugger dessus.
482 *
483 * Sinon, lance une exception FatalErrorException avec le message
484 * \a msg comme argument.
485 */
486extern "C++" ARCCORE_BASE_EXPORT void
487arccoreDebugPause(const char* msg);
488
489/*---------------------------------------------------------------------------*/
490/*---------------------------------------------------------------------------*/
491/*!
492 * \brief Indique si on l'appel à arccoreDebugPause() effectue une pause.
493 *
494 * \sa arccoreDebugPause()
495 */
496extern "C++" ARCCORE_BASE_EXPORT void
498
499/*---------------------------------------------------------------------------*/
500/*---------------------------------------------------------------------------*/
501/*!
502 * \brief Macro pour envoyer une exception avec formattage.
503 *
504 * \a exception_class est le type de l'exception. Les arguments suivants de
505 * la macro sont utilisés pour formatter un message d'erreur via la
506 * méthode String::format().
507 */
508#define ARCCORE_THROW(exception_class,...) \
509 throw exception_class (A_FUNCINFO,Arccore::String::format(__VA_ARGS__))
510
511/*!
512 * \brief Macro pour envoyer une exception avec formattage si \a cond est vrai.
513 *
514 * \a exception_class est le type de l'exception. Les arguments suivants de
515 * la macro sont utilisés pour formatter un message d'erreur via la
516 * méthode String::format().
517 *
518 * \sa ARCCORE_THROW
519 */
520#define ARCCORE_THROW_IF(cond, exception_class, ...) \
521 if (cond) [[unlikely]] \
522 ARCCORE_THROW(exception_class,__VA_ARGS__)
523
524/*---------------------------------------------------------------------------*/
525/*---------------------------------------------------------------------------*/
526/*!
527 * \brief Macro envoyant une exception FatalErrorException.
528 *
529 * Les arguments de la macro sont utilisés pour formatter un message
530 * d'erreur via la méthode String::format().
531 */
532#define ARCCORE_FATAL(...)\
533 ARCCORE_THROW(::Arccore::FatalErrorException,__VA_ARGS__)
534
535/*!
536 * \brief Macro envoyant une exception FatalErrorException si \a cond est vrai
537 *
538 * Les arguments de la macro sont utilisés pour formatter un message
539 * d'erreur via la méthode String::format().
540 *
541 * \sa ARCCORE_FATAL
542 */
543#define ARCCORE_FATAL_IF(cond, ...) \
544 ARCCORE_THROW_IF(cond, ::Arccore::FatalErrorException,__VA_ARGS__)
545
546/*---------------------------------------------------------------------------*/
547/*---------------------------------------------------------------------------*/
548/*!
549 * \brief Signalue l'utilisation d'un pointeur nul.
550 *
551 * Signale une tentative d'utilisation d'un pointeur nul.
552 * Affiche un message, appelle arccoreDebugPause() et lance une exception
553 * de type FatalErrorException.
554 */
555extern "C++" ARCCORE_BASE_EXPORT void
556arccoreNullPointerError ARCCORE_NORETURN ();
557
558/*---------------------------------------------------------------------------*/
559/*---------------------------------------------------------------------------*/
560/*!
561 * \brief Signale qu'une valeur n'est pas dans l'intervalle souhaité.
562 *
563 * Indique que l'assertion `min_value_inclusive <= i < max_value_exclusive`
564 * est fausse.
565 * Appelle arccoreDebugPause() puis lève une exception de type
566 * IndexOutOfRangeException.
567 *
568 * \param i valeur invalide.
569 * \param min_value_inclusive valeur minimale inclusive autorisée.
570 * \param max_value_exclusive valeur maximale exclusive autorisée.
571 */
572extern "C++" ARCCORE_BASE_EXPORT void
573arccoreRangeError ARCCORE_NORETURN (Int64 i,Int64 min_value_inclusive,
574 Int64 max_value_exclusive);
575
576/*---------------------------------------------------------------------------*/
577/*---------------------------------------------------------------------------*/
578/*!
579 * \brief Signale qu'une valeur n'est pas dans l'intervalle souhaité.
580 *
581 * Indique que l'assertion `0 <= i < max_value est fausse`.
582 * Lance une execption IndexOutOfRangeException.
583 *
584 * \param i indice invalide
585 * \param max_size nombre d'éléments du tableau
586 */
587extern "C++" ARCCORE_BASE_EXPORT void
588arccoreRangeError ARCCORE_NORETURN (Int64 i,Int64 max_size);
589
590/*---------------------------------------------------------------------------*/
591/*---------------------------------------------------------------------------*/
592/*!
593 * \brief Vérifie que `min_value_inclusive <= i < max_value_exclusive`.
594 *
595 * Si ce n'est pas le cas, appelle arccoreRangeError() pour lancer une
596 * exception.
597 */
598inline ARCCORE_HOST_DEVICE void
599arccoreCheckRange(Int64 i,Int64 min_value_inclusive,Int64 max_value_exclusive)
600{
601 if (i>=min_value_inclusive && i<max_value_exclusive)
602 return;
603#ifndef ARCCORE_DEVICE_CODE
604 arccoreRangeError(i,min_value_inclusive,max_value_exclusive);
605#elif defined(ARCCORE_DEVICE_TARGET_CUDA)
606 // Code pour le device.
607 // assert() est disponible pour CUDA.
608 // TODO: regarder si une fonction similaire existe pour HIP
609 assert(false);
610#endif
611}
612
613/*---------------------------------------------------------------------------*/
614/*---------------------------------------------------------------------------*/
615/*!
616 * \brief Vérifie un éventuel débordement de tableau.
617 *
618 * Appelle arccoreCheckRange(i,0,max_size).
619 */
620inline ARCCORE_HOST_DEVICE void
622{
623 arccoreCheckRange(i,0,max_size);
624}
625
626#if defined(ARCCORE_CHECK) || defined(ARCCORE_DEBUG)
627#define ARCCORE_CHECK_AT(a,b) ::Arccore::arccoreCheckAt((a),(b))
628#define ARCCORE_CHECK_RANGE(a,b,c) ::Arccore::arccoreCheckRange((a),(b),(c))
629#else
630#define ARCCORE_CHECK_AT(a,b)
631#define ARCCORE_CHECK_RANGE(a,b,c)
632#endif
633
634#define ARCCORE_CHECK_AT2(a0,a1,b0,b1) \
635 ARCCORE_CHECK_AT(a0,b0); ARCCORE_CHECK_AT(a1,b1)
636#define ARCCORE_CHECK_AT3(a0,a1,a2,b0,b1,b2) \
637 ARCCORE_CHECK_AT(a0,b0); ARCCORE_CHECK_AT(a1,b1); ARCCORE_CHECK_AT(a2,b2)
638#define ARCCORE_CHECK_AT4(a0,a1,a2,a3,b0,b1,b2,b3) \
639 ARCCORE_CHECK_AT(a0,b0); ARCCORE_CHECK_AT(a1,b1); ARCCORE_CHECK_AT(a2,b2); ARCCORE_CHECK_AT(a3,b3)
640
641/*---------------------------------------------------------------------------*/
642/*---------------------------------------------------------------------------*/
643
644#define ARCCORE_CAST_SMALL_SIZE(a) ((Integer)(a))
645
646/*---------------------------------------------------------------------------*/
647/*---------------------------------------------------------------------------*/
648
649extern "C++" ARCCORE_BASE_EXPORT void
650_doAssert(const char*,const char*,const char*,int);
651template<typename T> inline T*
652_checkPointer(const T* t,const char* file,const char* func,int line)
653{
654 if (!t){
655 _doAssert("ARCCORE_ASSERT",file,func,line);
656 arccorePrintf("Bad Pointer");
657 }
658 return t;
659}
660
661/*---------------------------------------------------------------------------*/
662/*---------------------------------------------------------------------------*/
663// Macro pour obtenir par le pré-processeur le nom de la fonction actuelle
664
665#if defined(__GNUG__)
666# define ARCCORE_MACRO_FUNCTION_NAME __PRETTY_FUNCTION__
667#elif defined( _MSC_VER)
668# define ARCCORE_MACRO_FUNCTION_NAME __FUNCTION__
669#else
670# define ARCCORE_MACRO_FUNCTION_NAME __func__
671#endif
672
673/*---------------------------------------------------------------------------*/
674/*---------------------------------------------------------------------------*/
675/*
676 * Macros utilisées pour le débug.
677 */
678#ifdef ARCCORE_DEBUG_ASSERT
679# define ARCCORE_D_WHERE(a) ::Arcane::_doAssert(a, __FILE__, ARCCORE_MACRO_FUNCTION_NAME, __LINE__)
680# define ARCCORE_DCHECK_POINTER(a) ::Arcane::_checkPointer((a), __FILE__, ARCCORE_MACRO_FUNCTION_NAME, __LINE__);
681# define ARCCORE_CHECK_PTR(a) \
682 { \
683 if (!(a)) { \
684 ::Arcane::arccorePrintf("Null value"); \
685 ARCCORE_D_WHERE("ARCCORE_ASSERT"); \
686 } \
687 }
688
689# define ARCCORE_ASSERT(a,b) \
690 { \
691 if (!(a)) { \
692 ::Arcane::arccorePrintf("Assertion '%s' fails:", #a); \
693 ::Arcane::arccorePrintf b; \
694 ARCCORE_D_WHERE("ARCCORE_ASSERT"); \
695 } \
696 }
697# define ARCCORE_WARNING(a) \
698 { \
699 ::Arcane::arccorePrintf a; \
700 ARCCORE_D_WHERE("ARCCORE_WARNING"); \
701 }
702#else
703# define ARCCORE_CHECK_PTR(a)
704# define ARCCORE_ASSERT(a,b)
705# define ARCCORE_WARNING(a)
706# define ARCCORE_DCHECK_POINTER(a) (a);
707#endif
708
709/*---------------------------------------------------------------------------*/
710/*---------------------------------------------------------------------------*/
711/*!
712 * \brief Signalee l'utilisation d'un pointeur nul en envoyant une exception
713 *
714 * Signale une tentative d'utilisation d'un pointeur nul.
715 * Lance une exception de type FatalErrorException.
716 *
717 * Dans l'exception, affiche \a text si non nul, sinon affiche \a ptr_name.
718 *
719 * Normalement cette méthode ne doit pas être appelée directement mais
720 * via la macro ARCCORE_CHECK_POINTER.
721 */
722extern "C++" ARCCORE_BASE_EXPORT void
723arccoreThrowNullPointerError [[noreturn]] (const char* ptr_name,const char* text);
724
725/*---------------------------------------------------------------------------*/
726/*---------------------------------------------------------------------------*/
727/*!
728 * \brief Vérifie qu'un pointeur n'est pas nul.
729 *
730 * Si le pointeur est nul, appelle arccoreThrowNullPointerError().
731 * Sinon, retourne le pointeur.
732 */
733inline void*
734arccoreThrowIfNull(void* ptr,const char* ptr_name,const char* text)
735{
736 if (!ptr)
737 arccoreThrowNullPointerError(ptr_name,text);
738 return ptr;
739}
740
741/*!
742 * \brief Vérifie qu'un pointeur n'est pas nul.
743 *
744 * Si le pointeur est nul, appelle arccoreThrowNullPointerError().
745 * Sinon, retourne le pointeur.
746 */
747inline const void*
748arccoreThrowIfNull(const void* ptr,const char* ptr_name,const char* text)
749{
750 if (!ptr)
751 arccoreThrowNullPointerError(ptr_name,text);
752 return ptr;
753}
754
755/*---------------------------------------------------------------------------*/
756/*---------------------------------------------------------------------------*/
757/*!
758 * \brief Macro retournant le pointeur \a ptr s'il est non nul
759 * ou lancant une exception s'il est nul.
760 *
761 * \sa arccoreThrowIfNull().
762 */
763#define ARCCORE_CHECK_POINTER(ptr) \
764 arccoreThrowIfNull(ptr,#ptr,nullptr)
765
766/*!
767 * \brief Macro retournant le pointeur \a ptr s'il est non nul
768 * ou lancant une exception s'il est nul.
769 *
770 * \sa arccoreThrowIfNull().
771 */
772#define ARCCORE_CHECK_POINTER2(ptr,text)\
773 arccoreThrowIfNull(ptr,#ptr,text)
774
775/*---------------------------------------------------------------------------*/
776/*---------------------------------------------------------------------------*/
777
778// Défitions des types de base.
779class String;
780class StringView;
782class StringBuilder;
783// Pas dans cette composante mais comme cette interface on la met ici
784// pour compatibilité avec l'existant
785class ITraceMng;
786
787/*---------------------------------------------------------------------------*/
788/*---------------------------------------------------------------------------*/
789
790} // End namespace Arcane
791
792/*---------------------------------------------------------------------------*/
793/*---------------------------------------------------------------------------*/
794
795/*---------------------------------------------------------------------------*/
796/*---------------------------------------------------------------------------*/
797
798namespace Arccore
799{
800using Arcane::ITraceMng;
801using Arcane::String;
802using Arcane::StringBuilder;
803using Arcane::StringFormatterArg;
804using Arcane::StringView;
805using Arcane::UInt32;
806using Arcane::UInt64;
807
808using Arcane::APReal;
809using Arcane::Integer;
810using Arcane::Pointer;
811using Arcane::Real;
812using Arcane::Short;
813
814//! Type 'Brain Float16'
816
817//! Type 'Float16' (binary16)
819
820//! Type flottant IEEE-753 simple précision (binary32)
821using Float32 = float;
822
823//! Type représentant un entier sur 8 bits
825
826//! Type représentant un floattan sur 128 bits
828
829//! Type représentant un entier sur 128 bits
831using Int16 = Arcane::Int16;
832using Int32 = Arcane::Int32;
833using Int64 = Arcane::Int64;
834
847
849using Arcane::TrueType;
851using Arcane::_checkPointer;
852}
853
854/*---------------------------------------------------------------------------*/
855/*---------------------------------------------------------------------------*/
856
857#endif
Emulation de réel en précision arbitraire.
Type flottant demi-précision.
Interface du gestionnaire de traces.
Constructeur de chaîne de caractère unicode.
Vue sur une chaîne de caractères UTF-8.
Definition StringView.h:47
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int8_t Int8
Type entier signé sur 8 bits.
void * arccoreThrowIfNull(void *ptr, const char *ptr_name, const char *text)
Vérifie qu'un pointeur n'est pas nul.
std::uint64_t UInt64
Type entier non signé sur 64 bits.
std::uint32_t UInt32
Type entier non signé sur 32 bits.
ARCCORE_BASE_EXPORT void arccoreNullPointerError()
Signalue l'utilisation d'un pointeur nul.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
void * Pointer
Type représentant un pointeur.
ARCCORE_BASE_EXPORT bool arccoreIsDebug()
Vrai si la macro ARCCORE_DEBUG est définie.
ARCCORE_BASE_EXPORT void arccorePrintf(const char *format,...)
Encapsulation de la fonction C printf.
__host__ __device__ void arccoreCheckRange(Int64 i, Int64 min_value_inclusive, Int64 max_value_exclusive)
Vérifie que min_value_inclusive <= i < max_value_exclusive.
__host__ __device__ void arccoreCheckAt(Int64 i, Int64 max_size)
Vérifie un éventuel débordement de tableau.
ARCCORE_BASE_EXPORT void arccoreDebugPause(const char *msg)
Passe en mode pause ou lance une erreur fatale.
std::int16_t Int16
Type entier signé sur 16 bits.
double Real
Type représentant un réel.
ARCCORE_BASE_EXPORT void arccoreRangeError(Int64 i, Int64 min_value_inclusive, Int64 max_value_exclusive)
Signale qu'une valeur n'est pas dans l'intervalle souhaité.
ARCCORE_BASE_EXPORT void arccoreThrowNullPointerError(const char *ptr_name, const char *text)
Signalee l'utilisation d'un pointeur nul en envoyant une exception.
float Float32
Type flottant IEEE-753 simple précision.
ARCCORE_BASE_EXPORT bool arccoreIsCheck()
Vrai si on est en mode vérification.
void _doAssert(const char *text, const char *file, const char *func, size_t line)
Definition Misc.cc:235
ARCCORE_BASE_EXPORT void arccoreSetPauseOnError(bool v)
Indique si on l'appel à arccoreDebugPause() effectue une pause.
ARCCORE_BASE_EXPORT void arccoreSetCheck(bool v)
Active ou désactive le mode vérification.
std::int32_t Int32
Type entier signé sur 32 bits.
Espace de nom de Arccore.
Arcane::Float128 Float128
Type représentant un floattan sur 128 bits.
Arcane::BFloat16 BFloat16
Type 'Brain Float16'.
float Float32
Type flottant IEEE-753 simple précision (binary32)
Arcane::Float16 Float16
Type 'Float16' (binary16)
Arcane::Int8 Int8
Type représentant un entier sur 8 bits.
Arcane::Int128 Int128
Type représentant un entier sur 128 bits.