Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ArcaneGlobal.h
Go to the documentation of this file.
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/* ArcaneGlobal.h (C) 2000-2025 */
9/* */
10/* General declarations for Arcane. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_ARCANEGLOBAL_H
13#define ARCANE_UTILS_ARCANEGLOBAL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19// Global information about compilation options such as
20// threads, debug mode, etc.
21#include "arcane_core_config.h"
22
23#ifdef ARCCORE_OS_LINUX
24#define ARCANE_OS_LINUX
25#include <cstddef>
26#endif
27
28#ifdef ARCCORE_OS_WIN32
29#define ARCANE_OS_WIN32
30#endif
31
32#ifdef ARCCORE_OS_MACOS
33#define ARCANE_OS_MACOS
34#endif
35
36#define ARCANE_EXPORT ARCCORE_EXPORT
37#define ARCANE_IMPORT ARCCORE_IMPORT
38#define ARCANE_TEMPLATE_EXPORT ARCCORE_TEMPLATE_EXPORT
39#define ARCANE_RESTRICT ARCCORE_RESTRICT
40
41#define ARCANE_STD std
42
43// Tag var as a voluntary unused variable.
44// Works with any compiler but might be improved by using attribute.
45#define ARCANE_UNUSED(var) ARCCORE_UNUSED(var)
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
50// TODO: remove the inclusion of <iosfwd> and the using statements.
51// For now (2022), these inclusions are removed only for Arcane.
52
53#ifndef ARCANE_NO_USING_FOR_STREAM
54#include <iosfwd>
55using std::ifstream;
56using std::ios;
57using std::istream;
58using std::istringstream;
59using std::ofstream;
60using std::ostream;
61using std::ostringstream;
62#endif
63
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
66
67#ifdef DOXYGEN_DOC
68typedef ARCANE_TYPE_INT16 Int16;
69typedef ARCANE_TYPE_INT32 Int32;
70typedef ARCANE_TYPE_INT64 Int64;
71#endif
72
73#define ARCANE_BEGIN_NAMESPACE \
74 namespace Arcane \
75 {
76#define ARCANE_END_NAMESPACE }
77#define NUMERICS_BEGIN_NAMESPACE \
78 namespace Numerics \
79 {
80#define NUMERICS_END_NAMESPACE }
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85#ifdef ARCANE_COMPONENT_FULL
86#define ARCANE_COMPONENT_arcane_utils
87#define ARCANE_COMPONENT_arcane
88#define ARCANE_COMPONENT_arcane_mesh
89#define ARCANE_COMPONENT_arcane_std
90#define ARCANE_COMPONENT_arcane_impl
91#define ARCANE_COMPONENT_arcane_script
92#endif
93
94#if defined(ARCANE_COMPONENT_arcane) || defined(ARCANE_COMPONENT_arcane_core)
95#define ARCANE_CORE_EXPORT ARCANE_EXPORT
96#define ARCANE_EXPR_EXPORT ARCANE_EXPORT
97#define ARCANE_DATATYPE_EXPORT ARCANE_EXPORT
98#define ARCANE_CORE_EXTERN_TPL
99#else
100#define ARCANE_CORE_EXPORT ARCANE_IMPORT
101#define ARCANE_EXPR_EXPORT ARCANE_IMPORT
102#define ARCANE_DATATYPE_EXPORT ARCANE_IMPORT
103#define ARCANE_CORE_EXTERN_TPL extern
104#endif
105
106#ifdef ARCANE_COMPONENT_arcane_utils
107#define ARCANE_UTILS_EXPORT ARCANE_EXPORT
108#define ARCANE_UTILS_EXTERN_TPL
109#else
110#define ARCANE_UTILS_EXPORT ARCANE_IMPORT
111#define ARCANE_UTILS_EXTERN_TPL extern
112#endif
113
114#ifdef ARCANE_COMPONENT_arcane_impl
115#define ARCANE_IMPL_EXPORT ARCANE_EXPORT
116#else
117#define ARCANE_IMPL_EXPORT ARCANE_IMPORT
118#endif
119
120#ifdef ARCANE_COMPONENT_arcane_mesh
121#define ARCANE_MESH_EXPORT ARCANE_EXPORT
122#else
123#define ARCANE_MESH_EXPORT ARCANE_IMPORT
124#endif
125
126#ifdef ARCANE_COMPONENT_arcane_std
127#define ARCANE_STD_EXPORT ARCANE_EXPORT
128#else
129#define ARCANE_STD_EXPORT ARCANE_IMPORT
130#endif
131
132#ifdef ARCANE_COMPONENT_arcane_script
133#define ARCANE_SCRIPT_EXPORT ARCANE_EXPORT
134#else
135#define ARCANE_SCRIPT_EXPORT ARCANE_IMPORT
136#endif
137
138#ifdef ARCANE_COMPONENT_arcane_solvers
139#define ARCANE_SOLVERS_EXPORT ARCANE_EXPORT
140#else
141#define ARCANE_SOLVERS_EXPORT ARCANE_IMPORT
142#endif
143
144#ifdef ARCANE_COMPONENT_arcane_geometry
145#define ARCANE_GEOMETRY_EXPORT ARCANE_EXPORT
146#else
147#define ARCANE_GEOMETRY_EXPORT ARCANE_IMPORT
148#endif
149
150#ifdef ARCANE_COMPONENT_arcane_thread
151#define ARCANE_THREAD_EXPORT ARCANE_EXPORT
152#else
153#define ARCANE_THREAD_EXPORT ARCANE_IMPORT
154#endif
155
156#ifdef ARCANE_COMPONENT_arcane_mpi
157#define ARCANE_MPI_EXPORT ARCANE_EXPORT
158#else
159#define ARCANE_MPI_EXPORT ARCANE_IMPORT
160#endif
161
162#ifdef ARCANE_COMPONENT_arcane_hyoda
163#define ARCANE_HYODA_EXPORT ARCANE_EXPORT
164#else
165#define ARCANE_HYODA_EXPORT ARCANE_IMPORT
166#endif
167
168#ifdef ARCANE_REAL_USE_APFLOAT
169#include <apfloat.h>
170#endif
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175namespace Arcane
176{
177
178/*---------------------------------------------------------------------------*/
179/*---------------------------------------------------------------------------*/
180
181#define ARCANE_HAS_LONG_LONG
182
183/*---------------------------------------------------------------------------*/
184/*---------------------------------------------------------------------------*/
185
186const double cgrEPSILON_DELTA = 1.0e-2;
187const double cgrPI = 3.14159265358979323846;
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
192#define ARCANE_REAL(val) ARCCORE_REAL(val)
193
194#ifdef ARCCORE_REAL_NOT_BUILTIN
195#define ARCANE_REAL_NOT_BUILTIN
196#endif
197
198#ifdef ARCCORE_REAL_LONG
199#define ARCANE_REAL_LONG
200#endif
201
202#ifdef ARCCORE_REAL_IS_DOUBLE
203#define ARCANE_REAL_IS_DOUBLE
204#endif
205
206/*!
207 * \brief Type of integers used to store local identifiers
208 * of entities.
209 *
210 * The values this type can take indicate how many entities
211 * can be present on a subdomain.
212 */
214
215/*!
216 * \brief Type of integers used to store unique
217 * (global) identifiers of entities.
218 *
219 * The values this type can take indicate how many entities
220 * can be present on the initial domain.
221 */
223
224/*!
225 * \def ARCANE_INTEGER_MAX
226 * \brief Macro indicating the maximum value that the #Integer type can take
227 */
228
229/*!
230 * \typedef Int64
231 * \brief 64-bit signed integer type.
232 */
233/*!
234 * \typedef Int32
235 * \brief 32-bit signed integer type.
236 */
237/*!
238 * \typedef Int16
239 * \brief 16-bit signed integer type.
240 */
241/*!
242 * \typedef Integer
243 * \brief Type representing an integer
244 *
245 * If the ARCANE_64BIT macro is defined, the Integer type corresponds to an
246 * Int64 integer, otherwise to an Int32 integer.
247 */
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252//! Encapsulation of the C printf function
253extern "C++" ARCANE_UTILS_EXPORT void
254arcanePrintf(const char*, ...);
255
256/*---------------------------------------------------------------------------*/
257/*---------------------------------------------------------------------------*/
258
259/*!
260 * \brief Enters pause mode or throws a fatal error.
261 *
262 * If the code is compiled in \a debug mode (ARCANE_DEBUG is defined) or
263 * in \a check mode (ARCANE_CHECK is defined), it pauses the program
264 * potentially allowing a debugger to connect to it.
265 *
266 * In normal mode, it throws a FatalErrorException with the message
267 * \a msg as an argument.
268 */
269extern "C++" ARCANE_UTILS_EXPORT void
270arcaneDebugPause(const char* msg);
271
272/*---------------------------------------------------------------------------*/
273/*---------------------------------------------------------------------------*/
274
275extern "C++" ARCANE_UTILS_EXPORT void
276_internalArcaneMathError(long double arg_value, const char* func_name);
277
278extern "C++" ARCANE_UTILS_EXPORT void
279_internalArcaneMathError(long double arg_value1, long double arg_value2, const char* func_name);
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283/*!
284 * \brief Signals an invalid argument in a mathematical function.
285 *
286 * After displaying the message, it calls arcaneDebugPause()
287 *
288 * \param arg_value value of the invalid argument.
289 * \param func_name name of the mathematical function.
290 */
291ARCCORE_HOST_DEVICE inline void
292arcaneMathError(long double arg_value, const char* func_name)
293{
294#ifndef ARCCORE_DEVICE_CODE
295 _internalArcaneMathError(arg_value, func_name);
296#else
297 ARCANE_UNUSED(arg_value);
298 ARCANE_UNUSED(func_name);
299#endif
300}
301
302/*!
303 * \brief Signals an invalid argument in a mathematical function.
304 *
305 * After displaying the message, it calls arcaneDebugPause()
306 *
307 * \param arg_value1 value of the first invalid argument.
308 * \param arg_value2 value of the second invalid argument.
309 * \param func_name name of the mathematical function.
310 */
311ARCCORE_HOST_DEVICE inline void
312arcaneMathError(long double arg_value1, long double arg_value2, const char* func_name)
313{
314#ifndef ARCCORE_DEVICE_CODE
315 _internalArcaneMathError(arg_value1, arg_value2, func_name);
316#else
317 ARCANE_UNUSED(arg_value1);
318 ARCANE_UNUSED(arg_value2);
319 ARCANE_UNUSED(func_name);
320#endif
321}
322
323/*---------------------------------------------------------------------------*/
324/*---------------------------------------------------------------------------*/
325
326/*!
327 * \brief Signals an unimplemented function.
328 *
329 * After displaying the message, it calls arcaneDebugPause()
330 *
331 * \param file name of the file containing the function
332 * \param func name of the function
333 * \param line number
334 * \param msg optional message to display (0 if none)
335 */
336extern "C++" ARCANE_UTILS_EXPORT void
337arcaneNotYetImplemented(const char* file, const char* func, unsigned long line, const char* msg);
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
342//! Signals the use of a deprecated function
343extern "C++" ARCANE_UTILS_EXPORT void
344arcaneDeprecated(const char* file, const char* func, unsigned long line, const char* text);
345
346/*---------------------------------------------------------------------------*/
347/*---------------------------------------------------------------------------*/
348
349/*!
350 * \brief Use of an unreferenced object.
351 *
352 * Signals an attempt to use an object that should no longer be
353 * referenced. Displays a message and calls arcaneDebugPause() if requested,
354 * and then throws a FatalErrorException.
355 *
356 * \param ptr address of the object
357 */
358extern "C++" ARCANE_UTILS_EXPORT void
359arcaneNoReferenceError(const void* ptr);
360
361/*!
362 * \brief Use of an unreferenced object.
363 *
364 * Signals an attempt to use an object that should no longer be
365 * referenced. Displays a message and calls arcaneDebugPause() if requested,
366 * and then calls std::terminate().
367 *
368 * \param ptr address of the object
369 */
370extern "C++" ARCANE_UTILS_EXPORT void
372
373/*!
374 * \brief Checks that \a size can be converted into an 'Integer' to serve
375 * as the size of an array. If possible, returns \a size converted to an 'Integer'.
376 * Otherwise, throws an ArgumentException.
377 */
378extern "C++" ARCANE_UTILS_EXPORT Integer
379arcaneCheckArraySize(unsigned long long size);
380
381/*!
382 * \brief Checks that \a size can be converted into an 'Integer' to serve
383 * as the size of an array. If possible, returns \a size converted to an 'Integer'.
384 * Otherwise, throws an ArgumentException.
385 */
386extern "C++" ARCANE_UTILS_EXPORT Integer
387arcaneCheckArraySize(long long size);
388
389/*!
390 * \brief Checks that \a size can be converted into an 'Integer' to serve
391 * as the size of an array. If possible, returns \a size converted to an 'Integer'.
392 * Otherwise, throws an ArgumentException.
393 */
394extern "C++" ARCANE_UTILS_EXPORT Integer
395arcaneCheckArraySize(unsigned long size);
396
397/*!
398 * \brief Checks that \a size can be converted into an 'Integer' to serve
399 * as the size of an array. If possible, returns \a size converted to an 'Integer'.
400 * Otherwise, throws an ArgumentException.
401 */
402extern "C++" ARCANE_UTILS_EXPORT Integer
403arcaneCheckArraySize(long size);
404
405/*!
406 * \brief Checks that \a size can be converted into an 'Integer' to serve
407 * as the size of an array. If possible, returns \a size converted to an 'Integer'.
408 * Otherwise, throws an ArgumentException.
409 */
410extern "C++" ARCANE_UTILS_EXPORT Integer
411arcaneCheckArraySize(unsigned int size);
412
413/*!
414 * \brief Checks that \a size can be converted into an 'Integer' to serve
415 * as the size of an array. If possible, returns \a size converted to an 'Integer'.
416 * Otherwise, throws an ArgumentException.
417 */
418extern "C++" ARCANE_UTILS_EXPORT Integer
419arcaneCheckArraySize(int size);
420
421/*!
422 * \brief Checks that \a ptr is aligned on \a alignment bytes.
423 * If not, throws a BadAlignmentException.
424 */
425extern "C++" ARCANE_UTILS_EXPORT void
426arcaneCheckAlignment(const void* ptr, Integer alignment);
427
428/*!
429 * \brief True if running in check mode.
430 *
431 * This mode is active if the ARCANE_CHECK macro is defined
432 * or if the arcaneSetCheck() method has been set to true.
433 */
434extern "C++" ARCANE_UTILS_EXPORT bool arcaneIsCheck();
435
436/*!
437 * \brief Activates or deactivates verification mode.
438 *
439 * Verification mode is always active if the ARCANE_CHECK macro is defined.
440 * Otherwise, it is possible to activate it using this method. This allows
441 * certain tests to be activated even in optimized mode.
442 */
443extern "C++" ARCANE_UTILS_EXPORT void arcaneSetCheck(bool v);
444
445/*!
446 * \brief True if the ARCANE_DEBUG macro is defined
447 */
448extern "C++" ARCANE_UTILS_EXPORT bool arcaneIsDebug();
449
450/*!
451 * \brief True if arcane is compiled with thread support AND they are active
452 */
453extern "C++" ARCANE_UTILS_EXPORT bool arcaneHasThread();
454
455/*!
456 * \brief Activates or deactivates thread support.
457 *
458 * This function should only be called during application initialization
459 * (or before) and must not be modified afterward.
460 * Thread activation is only possible if a thread implementation
461 * exists on the platform and Arcane was compiled with this support.
462 */
463extern "C++" ARCANE_UTILS_EXPORT void arcaneSetHasThread(bool v);
464
465/*!
466 * \brief Returns the ID of the current thread.
467 *
468 * Always returns 0 if arcaneHasThread() is false.
469 */
470extern "C++" ARCANE_UTILS_EXPORT
471Int64
473
474/*---------------------------------------------------------------------------*/
475/*---------------------------------------------------------------------------*/
476
477#ifdef ARCANE_DEBUG
478extern "C++" ARCANE_UTILS_EXPORT bool _checkDebug(size_t);
479#define ARCANE_DEBUGP(a, b) \
480 if (_checkDebug(a)) { \
481 arcanePrintf b; \
482 }
483#else
484#define ARCANE_DEBUGP(a, b)
485#endif
486
487/*---------------------------------------------------------------------------*/
488/*---------------------------------------------------------------------------*/
489
490#ifdef __GNUG__
491#define ARCANE_NOT_YET_IMPLEMENTED(a) \
492 { \
493 arcaneNotYetImplemented(__FILE__, __PRETTY_FUNCTION__, __LINE__, (a)); \
494 }
495#else
496#define ARCANE_NOT_YET_IMPLEMENTED(a) \
497 { \
498 arcaneNotYetImplemented(__FILE__, "(NoInfo)", __LINE__, (a)); \
499 }
500#endif
501
502#define ARCANE_DEPRECATED ARCCORE_DEPRECATED
503
504#define ARCANE_DEPRECATED_112 ARCANE_DEPRECATED
505#define ARCANE_DEPRECATED_114 ARCANE_DEPRECATED
506#define ARCANE_DEPRECATED_116 ARCANE_DEPRECATED
507#define ARCANE_DEPRECATED_118 ARCANE_DEPRECATED
508#define ARCANE_DEPRECATED_120 ARCANE_DEPRECATED
509#define ARCANE_DEPRECATED_122 ARCANE_DEPRECATED
510#define ARCANE_DEPRECATED_200 ARCANE_DEPRECATED
511#define ARCANE_DEPRECATED_220 ARCANE_DEPRECATED
512#define ARCANE_DEPRECATED_240 ARCANE_DEPRECATED
513#define ARCANE_DEPRECATED_260 ARCANE_DEPRECATED
514#define ARCANE_DEPRECATED_280 ARCANE_DEPRECATED
515#define ARCANE_DEPRECATED_2018 ARCANE_DEPRECATED
516#define ARCANE_DEPRECATED_2018_R(reason) [[deprecated(reason)]]
517
518#ifndef ARCCORE_DEPRECATED_2021
519#define ARCCORE_DEPRECATED_2021(reason) [[deprecated(reason)]]
520#endif
521
522#define ARCANE_DEPRECATED_REASON(reason) [[deprecated(reason)]]
523
524#ifdef ARCANE_NO_DEPRECATED_LONG_TERM
525#define ARCANE_DEPRECATED_LONG_TERM(reason)
526#else
527/*!
528 * \brief Macro for long-term 'deprecated' attribute.
529 *
530 * This macro is used to indicate types or functions
531 * that are obsolete and therefore preferably should not be used, but
532 * will not be removed for several versions.
533 */
534#define ARCANE_DEPRECATED_LONG_TERM(reason) [[deprecated(reason)]]
535#endif
536
537// Define this macro if you wish to remove obsolete methods and types from compilation.
538#define ARCANE_NO_DEPRECATED
539
540// If the macro is defined, do not notify about deprecated methods of old
541// array classes.
542#ifdef ARCANE_NO_NOTIFY_DEPRECATED_ARRAY
543#define ARCANE_DEPRECATED_ARRAY
544#else
545#define ARCANE_DEPRECATED_ARRAY ARCANE_DEPRECATED
546#endif
547
548/*---------------------------------------------------------------------------*/
549/*---------------------------------------------------------------------------*/
550
551// The following macros allow creating an identifier by suffixing the file line number.
552// This allows having a unique identifier for a file and is used, for example,
553// to generate global variable names for service registration.
554// The macro to use is ARCANE_JOIN_WITH_LINE(name).
555#define ARCANE_JOIN_HELPER2(a, b) a##b
556#define ARCANE_JOIN_HELPER(a, b) ARCANE_JOIN_HELPER2(a, b)
557#define ARCANE_JOIN_WITH_LINE(a) ARCANE_JOIN_HELPER(a, __LINE__)
558
559/*---------------------------------------------------------------------------*/
560/*---------------------------------------------------------------------------*/
561// The ARCANE_NORETURN macro uses the C++11 [[noreturn]] attribute to indicate that a function does not return.
562#define ARCANE_NORETURN ARCCORE_NORETURN
563
564//! Macro allowing specification of the C++11 'constexpr' keyword
565#define ARCANE_CONSTEXPR ARCCORE_CONSTEXPR
566
567// C++11 defines a 'noexcept' keyword to indicate that a method does not throw exceptions.
568// Unfortunately, since C++11 support is partial across compilers, this does not work
569// for everyone. In particular, icc 13, 14, and 15 do not support this, nor do
570// Visual Studio 2013 and earlier.
571#define ARCANE_NOEXCEPT ARCCORE_NOEXCEPT
572#define ARCANE_NOEXCEPT_FALSE ARCCORE_NOEXCEPT_FALSE
573
574/*---------------------------------------------------------------------------*/
575/*---------------------------------------------------------------------------*/
576
577// Support for alignment.
578// C++11 uses the alignas keyword to specify alignment.
579// This works with GCC 4.9+ and Visual Studio 2015. It does not work with Visual Studio 2013.
580// Therefore, for Visual Studio, we always use __declspec, which always works.
581// Under Linux, __attribute__ also always works, so we use that. Note that SIMD structures
582// require the 'packed' attribute, which only exists with GCC and Intel. There seems
583// to be no equivalent with MSVC.
584#ifdef _MSC_VER
585//! Macro to guarantee the packing and alignment of a class to \a value bytes
586#define ARCANE_ALIGNAS(value) __declspec(align(value))
587//! Macro to guarantee the alignment of a class to \a value bytes
588#define ARCANE_ALIGNAS_PACKED(value) __declspec(align(value))
589#else
590//! Macro to guarantee the packing and alignment of a class to \a value bytes
591#define ARCANE_ALIGNAS_PACKED(value) __attribute__((aligned(value), packed))
592//! Macro to guarantee the alignment of a class to \a value bytes
593#define ARCANE_ALIGNAS(value) __attribute__((aligned(value)))
594#endif
595
596/*---------------------------------------------------------------------------*/
597/*---------------------------------------------------------------------------*/
598
599#ifdef ARCANE_SWIG
600#ifdef ARCANE_DEPRECATED
601#undef ARCANE_DEPRECATED
602#endif
603#endif
604
605/*---------------------------------------------------------------------------*/
606/*---------------------------------------------------------------------------*/
607
608#if defined(ARCANE_CHECK) || defined(ARCANE_DEBUG)
609#ifndef ARCANE_DEBUG_ASSERT
610#define ARCANE_DEBUG_ASSERT
611#endif
612#endif
613
614/*---------------------------------------------------------------------------*/
615/*---------------------------------------------------------------------------*/
616/*!
617 * \brief Signals the use of a null pointer.
618 *
619 * Signals an attempt to use a null pointer.
620 * Displays a message, calls arcaneDebugPause(), and throws a FatalErrorException.
621 */
622extern "C++" ARCANE_UTILS_EXPORT void
623arcaneNullPointerError [[noreturn]] ();
624
625/*---------------------------------------------------------------------------*/
626/*---------------------------------------------------------------------------*/
627/*!
628 * \brief Signals the use of a null pointer by throwing an exception
629 *
630 * Signals an attempt to use a null pointer.
631 * Throws a FatalErrorException.
632 *
633 * In the exception, displays \a text if not null, otherwise displays \a ptr_name.
634 *
635 * Normally, this method should not be called directly but via the ARCANE_CHECK_POINTER macro.
636 */
637extern "C++" ARCANE_UTILS_EXPORT void
638arcaneThrowNullPointerError [[noreturn]] (const char* ptr_name, const char* text);
639
640/*---------------------------------------------------------------------------*/
641/*---------------------------------------------------------------------------*/
642/*!
643 * \brief Checks that a pointer is not null.
644 */
645static inline void
646arcaneCheckNull(const void* ptr)
647{
648 if (!ptr)
650}
651
652/*---------------------------------------------------------------------------*/
653/*---------------------------------------------------------------------------*/
654/*!
655 * \brief Returns the size with padding for a size \a size.
656 *
657 * The returned value is a multiple of SIMD_PADDING_SIZE and is:
658 * - 0 if \a size is less than or equal to 0.
659 * - \a size if \a size is a multiple of SIMD_PADDING_SIZE.
660 * - the multiple of SIMD_PADDING_SIZE immediately greater than \a size otherwise.
661 */
662extern "C++" ARCANE_UTILS_EXPORT Integer
664
665/*---------------------------------------------------------------------------*/
666/*---------------------------------------------------------------------------*/
667
668/*
669 * Macros used for debugging.
670 */
671#ifdef ARCANE_DEBUG_ASSERT
672extern "C++" ARCANE_UTILS_EXPORT void _doAssert(const char*, const char*, const char*, size_t);
673template <typename T> inline T*
674_checkPointer(T* t, const char* file, const char* func, size_t line)
675{
676 if (!t) {
677 _doAssert("ARCANE_ASSERT", file, func, line);
678 arcanePrintf("Bad Pointer");
679 }
680 return t;
681}
682#ifdef __GNUG__
683#define ARCANE_D_WHERE(a) Arcane::_doAssert(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
684#define ARCANE_DCHECK_POINTER(a) Arcane::_checkPointer((a), __FILE__, __PRETTY_FUNCTION__, __LINE__);
685#else
686#define ARCANE_D_WHERE(a) Arcane::_doAssert(a, __FILE__, "(NoInfo)", __LINE__)
687#define ARCANE_DCHECK_POINTER(a) Arcane::_checkPointer((a),__FILE__,"(NoInfo"),__LINE__);
688#endif
689#define ARCANE_CHECK_PTR(a) \
690 { \
691 if (!(a)) { \
692 Arcane::arcanePrintf("Null value"); \
693 ARCANE_D_WHERE("ARCANE_ASSERT"); \
694 } \
695 }
696
697#define ARCANE_ASSERT(a, b) \
698 { \
699 if (!(a)) { \
700 Arcane::arcanePrintf("Assertion '%s' fails:", #a); \
701 Arcane::arcanePrintf b; \
702 ARCANE_D_WHERE("ARCANE_ASSERT"); \
703 } \
704 }
705#define ARCANE_WARNING(a) \
706 { \
707 Arcane::arcanePrintf a; \
708 ARCANE_D_WHERE("ARCANE_WARNING"); \
709 }
710#else
711#define ARCANE_CHECK_PTR(a)
712#define ARCANE_ASSERT(a, b)
713#define ARCANE_WARNING(a)
714#define ARCANE_DCHECK_POINTER(a) (a);
715#endif
716
717/*---------------------------------------------------------------------------*/
718/*---------------------------------------------------------------------------*/
719/*!
720 * \brief Macro for throwing an exception with formatting.
721 *
722 * \a exception_class is the exception type. The following arguments of
723 * the macro are used to format an error message via the
724 * String::format() method.
725 */
726#define ARCANE_THROW(exception_class, ...) \
727 ARCCORE_THROW(exception_class, __VA_ARGS__)
728
729/*!
730 * \brief Macro for throwing an exception with formatting if \a cond is true.
731 *
732 * \a exception_class is the exception type. The following arguments of
733 * the macro are used to format an error message via the
734 * String::format() method.
735 *
736 * \sa ARCANE_THROW
737 */
738#define ARCANE_THROW_IF(const, exception_class, ...) \
739 ARCCORE_THROW_IF(const, exception_class, __VA_ARGS__)
740
741/*---------------------------------------------------------------------------*/
742/*---------------------------------------------------------------------------*/
743/*!
744 * \brief Macro throwing a FatalErrorException.
745 *
746 * The macro arguments are used to format an error message
747 * via the String::format() method.
748 */
749#define ARCANE_FATAL(...) \
750 ARCCORE_FATAL(__VA_ARGS__)
751
752/*!
753 * \brief Macro throwing a FatalErrorException if \a cond is true
754 *
755 * The macro arguments are used to format an error message
756 * via the String::format() method.
757 *
758 * \sa ARCANE_FATAL
759 */
760#define ARCANE_FATAL_IF(const, ...) \
761 ARCCORE_FATAL_IF(const, __VA_ARGS__)
762
763/*---------------------------------------------------------------------------*/
764/*---------------------------------------------------------------------------*/
765/*!
766 * \brief Checks that a pointer is not null.
767 *
768 * If the pointer is null, it calls arcaneThrowNullPointerError().
769 * Otherwise, it returns the pointer.
770 */
771static inline void*
772arcaneThrowIfNull(void* ptr, const char* ptr_name, const char* text)
773{
774 if (!ptr)
775 arcaneThrowNullPointerError(ptr_name, text);
776 return ptr;
777}
778
779/*---------------------------------------------------------------------------*/
780/*---------------------------------------------------------------------------*/
781/*!
782 * \brief Checks that a pointer is not null.
783 *
784 * If the pointer is null, it calls arcaneThrowNullPointerError().
785 * Otherwise, it returns the pointer.
786 */
787static inline const void*
788arcaneThrowIfNull(const void* ptr, const char* ptr_name, const char* text)
789{
790 if (!ptr)
791 arcaneThrowNullPointerError(ptr_name, text);
792 return ptr;
793}
794
795/*---------------------------------------------------------------------------*/
796/*---------------------------------------------------------------------------*/
797/*!
798 * \brief Checks that a pointer is not null.
799 *
800 * If the pointer is null, it calls arcaneThrowNullPointerError().
801 * Otherwise, it returns the pointer.
802 */
803template <typename T> inline T*
804arcaneThrowIfNull(T* ptr, const char* ptr_name, const char* text)
805{
806 if (!ptr)
807 arcaneThrowNullPointerError(ptr_name, text);
808 return ptr;
809}
810
811/*---------------------------------------------------------------------------*/
812/*---------------------------------------------------------------------------*/
813/*!
814 * \brief Macro returning the pointer \a ptr if it is not null
815 * or throwing an exception if it is null.
816 *
817 * \sa arcaneThrowIfNull().
818 */
819#define ARCANE_CHECK_POINTER(ptr) \
820 arcaneThrowIfNull(ptr, #ptr, nullptr)
821
822/*!
823 * \brief Macro returning the pointer \a ptr if it is not null
824 * or throwing an exception if it is null.
825 *
826 * \sa arcaneThrowIfNull().
827 */
828#define ARCANE_CHECK_POINTER2(ptr, text) \
829 arcaneThrowIfNull(ptr, #ptr, text)
830
831/*---------------------------------------------------------------------------*/
832/*---------------------------------------------------------------------------*/
833/*!
834 * \brief Signals an overflow error.
835 *
836 * Signals an array overflow. Displays a message and calls arcaneDebugPause().
837 *
838 * \param i invalid index
839 * \param max_size number of elements in the array
840 */
841extern "C++" ARCANE_UTILS_EXPORT void
842arcaneRangeError [[noreturn]] (Int64 i, Int64 max_size);
843
844/*!
845 * \brief Checks for a possible array overflow.
846 */
847static inline constexpr ARCCORE_HOST_DEVICE void
848arcaneCheckAt(Int64 i, Int64 max_size)
849{
850#ifndef ARCCORE_DEVICE_CODE
851 if (i < 0 || i >= max_size)
852 arcaneRangeError(i, max_size);
853#else
854 ARCANE_UNUSED(i);
855 ARCANE_UNUSED(max_size);
856#endif
857}
858
859#if defined(ARCANE_CHECK) || defined(ARCANE_DEBUG)
860#define ARCANE_CHECK_AT(a, b) ::Arcane::arcaneCheckAt((a), (b))
861#else
862#define ARCANE_CHECK_AT(a, b)
863#endif
864
865/*---------------------------------------------------------------------------*/
866/*---------------------------------------------------------------------------*/
867
868} // End namespace Arcane
869
870/*---------------------------------------------------------------------------*/
871/*---------------------------------------------------------------------------*/
872
873#endif
Definitions and globals of Arccore.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
void arcaneNoReferenceErrorCallTerminate(const void *ptr)
Use of an unreferenced object.
Definition Misc.cc:167
Int64 arcaneCurrentThread()
Returns the ID of the current thread.
Definition Misc.cc:104
Integer arcaneCheckArraySize(unsigned long long size)
Checks that size can be converted into an 'Integer' to serve as the size of an array....
bool arcaneIsCheck()
True if running in check mode.
Definition Misc.cc:66
bool arcaneHasThread()
True if arcane is compiled with thread support AND they are active.
Definition Misc.cc:88
Int64 UniqueIdType
Type of integers used to store unique (global) identifiers of entities.
std::int64_t Int64
Signed integer type of 64 bits.
void arcaneSetHasThread(bool v)
Activates or deactivates thread support.
Definition Misc.cc:93
void arcaneNullPointerError()
Signals the use of a null pointer.
Int32 Integer
Type representing an integer.
void arcanePrintf(const char *,...)
Encapsulation of the C printf function.
Definition Misc.cc:177
void arcaneNotYetImplemented(const char *file, const char *func, unsigned long line, const char *text)
Signals an unimplemented function.
Integer arcaneSizeWithPadding(Integer size)
Returns the size with padding for a size size.
void arcaneDeprecated(const char *file, const char *func, unsigned long line, const char *text)
Signals the use of a deprecated function.
bool arcaneIsDebug()
True if the ARCANE_DEBUG macro is defined.
Definition Misc.cc:76
void arcaneSetCheck(bool v)
Activates or deactivates verification mode.
Definition Misc.cc:71
void arcaneNoReferenceError(const void *ptr)
Use of an unreferenced object.
Definition Misc.cc:157
bool _checkDebug(unsigned int val)
Definition Misc.cc:238
__host__ __device__ void arcaneMathError(long double arg_value, const char *func_name)
Signals an invalid argument in a mathematical function.
void _doAssert(const char *text, const char *file, const char *func, size_t line)
Definition Misc.cc:220
void arcaneDebugPause(const char *msg)
Enters pause mode or throws a fatal error.
Definition Misc.cc:122
void arcaneCheckAlignment(const void *ptr, Integer alignment)
Checks that ptr is aligned on alignment bytes. If not, throws a BadAlignmentException.
std::int32_t Int32
Signed integer type of 32 bits.
void arcaneThrowNullPointerError(const char *ptr_name, const char *text)
Signals the use of a null pointer by throwing an exception.