OpenMC/include/openmc/error.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
1.7 KiB
C
Raw Permalink Normal View History

#ifndef OPENMC_ERROR_H
#define OPENMC_ERROR_H
2018-01-23 22:26:48 -05:00
#include <cstring>
2018-01-31 15:28:36 -05:00
#include <sstream>
#include <string>
2018-01-31 15:28:36 -05:00
#include <fmt/format.h>
#include "openmc/capi.h"
#include "openmc/settings.h"
2018-01-31 15:28:36 -05: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 {
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());
}
[[noreturn]] void fatal_error(const std::string& message, int err = -1);
[[noreturn]] inline void fatal_error(const std::stringstream& message)
{
fatal_error(message.str());
}
[[noreturn]] inline void fatal_error(const char* message)
2018-01-31 15:28:36 -05: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
}
void write_message(const std::string& message, int level = 0);
inline void write_message(const std::stringstream& message, int level)
{
write_message(message.str(), level);
}
template<typename... Params>
void write_message(
int level, const std::string& message, const Params&... fmt_args)
{
if (settings::verbosity >= level) {
write_message(fmt::format(fmt::runtime(message), fmt_args...));
}
}
template<typename... Params>
void write_message(const std::string& message, const Params&... fmt_args)
{
write_message(fmt::format(fmt::runtime(message), fmt_args...));
}
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
#endif // OPENMC_ERROR_H