diff options
author | 2022-03-08 18:38:25 +0100 | |
---|---|---|
committer | 2022-03-08 09:38:25 -0800 | |
commit | 0a64c2b8a42d766e5a893fcab2d4573b33cca74f (patch) | |
tree | 16f5979ff152251fc443f2e5ee67f929d6534228 /Source/Utils/TextMsg.H | |
parent | 7425721ccced342615c054ea8147fbdc484d6620 (diff) | |
download | WarpX-0a64c2b8a42d766e5a893fcab2d4573b33cca74f.tar.gz WarpX-0a64c2b8a42d766e5a893fcab2d4573b33cca74f.tar.zst WarpX-0a64c2b8a42d766e5a893fcab2d4573b33cca74f.zip |
Make error and info messages visually uniform (#2939)
* initial work to add msg formatter
* wip
* replace AMREX_ALWAYS_ASSERT_WITH_MESSAGE with WarpX equivalent
Diffstat (limited to 'Source/Utils/TextMsg.H')
-rw-r--r-- | Source/Utils/TextMsg.H | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Source/Utils/TextMsg.H b/Source/Utils/TextMsg.H new file mode 100644 index 000000000..c7c7a8225 --- /dev/null +++ b/Source/Utils/TextMsg.H @@ -0,0 +1,55 @@ +/* Copyright 2022 Luca Fedeli + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_TEXT_MSG_H_ +#define WARPX_TEXT_MSG_H_ + +#include <string> + +#define WARPX_ALWAYS_ASSERT_WITH_MESSAGE(EX,MSG) (EX)?((void)0):Utils::TextMsg::Assert( # EX , __FILE__, __LINE__ , MSG) + +namespace Utils +{ +namespace TextMsg +{ + /** \brief This function formats a text message as an error message, + * adding the '### ERROR: ' prefix and (by default) performing text wrapping + * + * @param[in] msg the string to be formatterd + * @param[in] do_text_wrapping if true, the message is automatically + * + * @return the formatted message + */ + std::string Err(const std::string& msg, const bool do_text_wrapping = true); + + /** \brief This function formats a text message as an info message, + * adding the '### INFO: ' prefix and (by default) performing text wrapping + * + * @param[in] msg the string to be formatterd + * @param[in] do_text_wrapping if true, the message is automatically + * + * @return the formatted message + */ + std::string Info(const std::string& msg, const bool do_text_wrapping = true); + + /** \brief This function formats a text message as a warning message, + * adding the '### WARN: ' prefix and (by default) performing text wrapping. + * Warning: this format is not used by the WarningLogger, which has an internal, + * dedicated, formatter. + * + * @param[in] msg the string to be formatterd + * @param[in] do_text_wrapping if true, the message is automatically + * + * @return the formatted message + */ + std::string Warn(const std::string& msg, const bool do_text_wrapping = true); + + void Assert(const char* ex, const char* file, const int line, const std::string& msg); +} +} + +#endif //WARPX_TEXT_MSG_H_ |