-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from devosoft/mabe-systematics
- Loading branch information
Showing
17 changed files
with
3,297 additions
and
1,150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* This file is part of Empirical, https://github.com/devosoft/Empirical | ||
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md | ||
* date: 2024 | ||
*/ | ||
/** | ||
* @file | ||
* @brief Implementation of emp_optional_throw. | ||
*/ | ||
|
||
#ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE | ||
#define EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
#include "_is_streamable.hpp" | ||
|
||
namespace emp { | ||
|
||
/// Base case for assert_print... | ||
inline void assert_print_opt(std::stringstream &) { ; } | ||
|
||
/// Print out information about the next variable and recurse... | ||
template <typename T, typename... EXTRA> | ||
void assert_print_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { | ||
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) { | ||
ss << name << ": [" << val << "]" << std::endl; | ||
} else ss << name << ": (non-streamable type)" << std::endl; | ||
assert_print_opt(ss, std::forward<EXTRA>(extra)...); | ||
} | ||
|
||
template <typename T, typename... EXTRA> | ||
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { | ||
assert_print_opt(ss, std::forward<EXTRA>(extra)...); | ||
} | ||
|
||
template <typename T> | ||
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val) {;} | ||
|
||
template <typename T, typename... EXTRA> | ||
void assert_print_first_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { | ||
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) { | ||
ss << name << ": [" << val << "]" << std::endl; | ||
} else ss << name << ": (non-streamable type)" << std::endl; | ||
assert_print_second_opt(ss, std::forward<EXTRA>(extra)...); | ||
} | ||
|
||
void assert_print_first_opt(std::stringstream & ss, int placeholder) {;} | ||
|
||
template <typename... EXTRA> | ||
void assert_throw_opt(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) { | ||
std::stringstream ss; | ||
ss << "Internal Error (in " << filename << " line " << line << "): " << expr << ".\n\n Message: " << message << "\n\n"; | ||
assert_print_first_opt(ss, std::forward<EXTRA>(extra)...); | ||
throw(std::runtime_error(ss.str())); | ||
} | ||
} | ||
|
||
#endif // #ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* This file is part of Empirical, https://github.com/devosoft/Empirical | ||
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md | ||
* date: 2024 | ||
*/ | ||
/** | ||
* @file | ||
* @brief A version of emp_assert that throws a runtime error if compiled with -DEMP_OPTIONAL_THROW_ON. | ||
* | ||
* This is useful if you want the option to throw a runtime error outside of debug mode. A common use | ||
* case is wrapping C++ code in Python, since segfaults kill the entire Python interpreter. | ||
*/ | ||
|
||
#ifndef EMP_BASE_OPTIONAL_THROW_HPP_INCLUDE | ||
#define EMP_BASE_OPTIONAL_THROW_HPP_INCLUDE | ||
|
||
#include "assert.hpp" | ||
|
||
/// NDEBUG should trigger its EMP equivalent. | ||
#ifdef NDEBUG | ||
#define EMP_NDEBUG | ||
#endif | ||
|
||
|
||
#if defined( EMP_OPTIONAL_THROW_ON ) | ||
|
||
// #if defined (_MSC_VER ) | ||
|
||
#define emp_optional_throw(TEST, MESSAGE) \ | ||
do { \ | ||
if (!(TEST)) { \ | ||
emp::assert_throw_opt(__FILE__, __LINE__, #TEST, MESSAGE, 0); \ | ||
} \ | ||
} while(0) | ||
|
||
/* #define emp_optional_throw_impl(TEST, MESSAGE) emp_optional_throw_mscv_impl(TEST, MESSAGE) | ||
/ #else | ||
/ #define emp_optional_throw_impl(...) \ | ||
/ do { \ | ||
/ if (!(emp_assert_GET_ARG_1(__VA_ARGS__, ~))) { \ | ||
/ emp::assert_throw( \ | ||
/ __FILE__, __LINE__, \ | ||
/ emp_assert_STRINGIFY( emp_assert_GET_ARG_1(__VA_ARGS__, ~), ), \ | ||
/ emp_assert_STRINGIFY( emp_assert_GET_ARG_2(__VA_ARGS__, ~), ), \ | ||
/ emp_assert_TO_PAIRS(__VA_ARGS__)); \ | ||
/ } \ | ||
/ } while(0) | ||
/ #endif | ||
/ #define emp_optional_throw(...) emp_optional_throw_impl(__VA_ARGS__) | ||
*/ | ||
#elif defined( EMP_NDEBUG ) | ||
|
||
#define emp_optional_throw(...) | ||
|
||
#else | ||
/// Require a specified condition to be true. If it is false, immediately | ||
/// halt execution. Print also extra information on any variables or | ||
/// expressions provided as variadic args. Note: If NDEBUG is defined, | ||
/// emp_assert() will not do anything. Due to macro parsing limitations, extra | ||
/// information will not be printed when compiling with MSVC. | ||
#define emp_optional_throw(...) emp_assert(__VA_ARGS__) | ||
|
||
#endif | ||
|
||
|
||
#endif // #ifndef EMP_BASE_OPTIONAL_THROW_HPP_INCLUDE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.