Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / include / xbt / asserts.hpp
index bb43097..ab9de25 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2016-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -6,12 +6,7 @@
 #ifndef SIMGRID_XBT_ASSERTS_HPP
 #define SIMGRID_XBT_ASSERTS_HPP
 
-#include <exception>
 #include <simgrid/Exception.hpp>
-#include <xbt/log.h>
-
-namespace simgrid {
-namespace xbt {
 
 /**
  * @brief Those are the SimGrid version of the good ol' assert macro.
@@ -21,24 +16,20 @@ namespace xbt {
  * If the statement evaluates to false, then a simgrid::AsertionError is thrown.
  * This is identical to the xbt_assert macro, except that an exception is thrown instead of calling abort().
  *
- * Unlike the standard assert, s4u_enforce is never disabled, even if the macro NDEBUG is defined at compile time.
+ * Unlike the standard assert, xbt_enforce is never disabled, even if the macro NDEBUG is defined at compile time.
  * Note however that this macro should *not* be used with a condition that has side effects, since the exception can be
  * caught and ignored.
  */
 /** @brief The condition which failed will be displayed.
     @hideinitializer  */
-#define s4u_enforce(...) \
-  _XBT_IF_ONE_ARG(_s4u_enforce_ARG1, _s4u_enforce_ARGN, __VA_ARGS__)(__VA_ARGS__)
-#define _s4u_enforce_ARG1(cond) _s4u_enforce_ARGN((cond), "Assertion %s failed", #cond)
-#define _s4u_enforce_ARGN(cond, ...)                                                                                   \
+#define xbt_enforce(...) \
+  _XBT_IF_ONE_ARG(_xbt_enforce_ARG1, _xbt_enforce_ARGN, __VA_ARGS__)(__VA_ARGS__)
+#define _xbt_enforce_ARG1(cond) _xbt_enforce_ARGN((cond), "Assertion %s failed", #cond)
+#define _xbt_enforce_ARGN(cond, ...)                                                                                   \
   do {                                                                                                                 \
-    if (!(cond)) {                                                                                                     \
-      throw simgrid::AssertionError(__VA_ARGS__);                                                                 \
+    if (not(cond)) {                                                                                                   \
+      throw simgrid::AssertionError(XBT_THROW_POINT, xbt::string_printf(__VA_ARGS__));                                 \
     }                                                                                                                  \
   } while (0)
 
-
-} // namespace xbt
-} // namespace simgrid
-
 #endif