2018-08-20 14:40:32 -05:00
|
|
|
#ifndef OPENMC_ERROR_H
|
|
|
|
|
#define OPENMC_ERROR_H
|
2018-01-23 12:37:28 -05:00
|
|
|
|
2018-01-23 22:26:48 -05:00
|
|
|
#include <cstring>
|
2018-01-31 15:28:36 -05:00
|
|
|
#include <sstream>
|
2018-01-23 12:37:28 -05:00
|
|
|
#include <string>
|
2018-01-31 15:28:36 -05:00
|
|
|
|
2020-08-02 22:10:59 -04:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
2018-08-20 14:40:32 -05:00
|
|
|
#include "openmc/capi.h"
|
2020-08-02 22:10:59 -04:00
|
|
|
#include "openmc/settings.h"
|
2018-01-31 15:28:36 -05:00
|
|
|
|
2021-03-05 14:59:48 -06:00
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
2019-03-26 16:16:06 -05:00
|
|
|
#define UNREACHABLE() __builtin_unreachable()
|
|
|
|
|
#else
|
|
|
|
|
#define UNREACHABLE() (void)0
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-01-31 15:28:36 -05:00
|
|
|
namespace openmc {
|
2018-01-23 12:37:28 -05:00
|
|
|
|
2018-07-23 09:50:18 -05:00
|
|
|
inline void set_errmsg(const char* message)
|
|
|
|
|
{
|
|
|
|
|
std::strcpy(openmc_err_msg, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void set_errmsg(const std::string& message)
|
|
|
|
|
{
|
|
|
|
|
std::strcpy(openmc_err_msg, message.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void set_errmsg(const std::stringstream& message)
|
|
|
|
|
{
|
|
|
|
|
std::strcpy(openmc_err_msg, message.str().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 22:53:53 -06:00
|
|
|
[[noreturn]] void fatal_error(const std::string& message, int err = -1);
|
2018-01-23 12:37:28 -05:00
|
|
|
|
2019-02-05 22:53:53 -06:00
|
|
|
[[noreturn]] inline void fatal_error(const std::stringstream& message)
|
2018-01-23 12:37:28 -05:00
|
|
|
{
|
2019-02-05 22:53:53 -06:00
|
|
|
fatal_error(message.str());
|
2018-01-23 12:37:28 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-05 22:53:53 -06:00
|
|
|
[[noreturn]] inline void fatal_error(const char* message)
|
2018-01-31 15:28:36 -05:00
|
|
|
{
|
2019-06-05 11:26:39 -04:00
|
|
|
fatal_error(std::string {message, std::strlen(message)});
|
2018-04-29 19:09:22 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-05 22:14:08 -06:00
|
|
|
void warning(const std::string& message);
|
2018-04-29 19:09:22 -05:00
|
|
|
|
|
|
|
|
inline void warning(const std::stringstream& message)
|
|
|
|
|
{
|
|
|
|
|
warning(message.str());
|
2018-01-31 15:28:36 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-07 10:05:43 -06:00
|
|
|
void write_message(const std::string& message, int level = 0);
|
2018-06-17 10:58:28 -04:00
|
|
|
|
|
|
|
|
inline void write_message(const std::stringstream& message, int level)
|
|
|
|
|
{
|
|
|
|
|
write_message(message.str(), level);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-02 22:10:59 -04:00
|
|
|
template<typename... Params>
|
|
|
|
|
void write_message(
|
|
|
|
|
int level, const std::string& message, const Params&... fmt_args)
|
|
|
|
|
{
|
|
|
|
|
if (settings::verbosity >= level) {
|
2026-07-07 15:58:19 +01:00
|
|
|
write_message(fmt::format(fmt::runtime(message), fmt_args...));
|
2020-08-02 22:10:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename... Params>
|
|
|
|
|
void write_message(const std::string& message, const Params&... fmt_args)
|
|
|
|
|
{
|
2026-07-07 15:58:19 +01:00
|
|
|
write_message(fmt::format(fmt::runtime(message), fmt_args...));
|
2020-08-02 22:10:59 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-10 07:50:30 -05:00
|
|
|
#ifdef OPENMC_MPI
|
|
|
|
|
extern "C" void abort_mpi(int code);
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-01-31 15:28:36 -05:00
|
|
|
} // namespace openmc
|
2018-08-20 14:40:32 -05:00
|
|
|
#endif // OPENMC_ERROR_H
|