vcpkg/toolsrc/include/vcpkg_Checks.h

53 lines
2.0 KiB
C
Raw Normal View History

2016-09-19 11:50:08 +08:00
#pragma once
#include "vcpkg_Strings.h"
2017-03-14 08:14:00 +08:00
#include "LineInfo.h"
2017-03-14 07:04:29 +08:00
2017-01-06 04:47:08 +08:00
namespace vcpkg::Checks
2016-09-19 11:50:08 +08:00
{
__declspec(noreturn) void unreachable(const LineInfo& line_info);
2016-09-19 11:50:08 +08:00
// Part of the reason these exist is to not include extra headers in this one to avoid circular #includes.
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessage);
2016-09-19 11:50:08 +08:00
template <class...Args>
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Args&... errorMessageArgs)
2016-09-19 11:50:08 +08:00
{
exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
2016-09-19 11:50:08 +08:00
}
_declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessage);
2016-09-19 11:50:08 +08:00
template <class...Args>
_declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Args&... errorMessageArgs)
2016-09-19 11:50:08 +08:00
{
throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
2016-09-19 11:50:08 +08:00
}
void check_throw(const LineInfo& line_info, bool expression, const char* errorMessage);
2016-09-19 11:50:08 +08:00
template <class...Args>
void check_throw(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs)
2016-09-19 11:50:08 +08:00
{
if (!expression)
{
// Only create the string if the expression is false
throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
2016-09-19 11:50:08 +08:00
}
}
void check_exit(const LineInfo& line_info, bool expression);
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessage);
2016-09-19 11:50:08 +08:00
template <class...Args>
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs)
2016-09-19 11:50:08 +08:00
{
if (!expression)
{
// Only create the string if the expression is false
exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
2016-09-19 11:50:08 +08:00
}
}
2017-01-06 04:47:08 +08:00
}