|
|
@ -28,58 +28,21 @@ namespace Exiv2::Internal {
|
|
|
|
* type exception_t
|
|
|
|
* type exception_t
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @tparam exception_t Exception type that is thrown, must provide a
|
|
|
|
* @tparam exception_t Exception type that is thrown, must provide a
|
|
|
|
* constructor that accepts a single argument to which arg1 is forwarded.
|
|
|
|
* constructor that accepts a single argument to which args are forwarded.
|
|
|
|
*
|
|
|
|
|
|
|
|
* @todo once we have C++>=11 use variadic templates and std::forward to remove
|
|
|
|
|
|
|
|
* all overloads of enforce
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename exception_t, typename T>
|
|
|
|
|
|
|
|
inline void enforce(bool condition, const T& arg1) {
|
|
|
|
|
|
|
|
if (!condition) {
|
|
|
|
|
|
|
|
throw exception_t(arg1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
* @brief Ensure that condition is true, otherwise throw an Exiv2::Error with
|
|
|
|
|
|
|
|
* the given error_code.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline void enforce(bool condition, Exiv2::ErrorCode err_code) {
|
|
|
|
|
|
|
|
if (!condition) {
|
|
|
|
|
|
|
|
throw Exiv2::Error(err_code);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
* @brief Ensure that condition is true, otherwise throw an Exiv2::Error with
|
|
|
|
|
|
|
|
* the given error_code & arg1.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
|
|
|
inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1) {
|
|
|
|
|
|
|
|
if (!condition) {
|
|
|
|
|
|
|
|
throw Exiv2::Error(err_code, arg1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
* @brief Ensure that condition is true, otherwise throw an Exiv2::Error with
|
|
|
|
|
|
|
|
* the given error_code, arg1 & arg2.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template <typename T, typename U>
|
|
|
|
template <typename exception_t, typename... T>
|
|
|
|
inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2) {
|
|
|
|
constexpr void enforce(bool condition, T&&... args) {
|
|
|
|
if (!condition) {
|
|
|
|
if (!condition) {
|
|
|
|
throw Exiv2::Error(err_code, arg1, arg2);
|
|
|
|
throw exception_t(std::forward<T>(args)...);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
* @brief Ensure that condition is true, otherwise throw an Exiv2::Error with
|
|
|
|
* @brief Ensure that condition is true, otherwise throw an Exiv2::Error with
|
|
|
|
* the given error_code, arg1, arg2 & arg3.
|
|
|
|
* the given error_code & arguments.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template <typename T, typename U, typename V>
|
|
|
|
template <typename... T>
|
|
|
|
inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2, const V& arg3) {
|
|
|
|
constexpr void enforce(bool condition, Exiv2::ErrorCode err_code, T&&... args) {
|
|
|
|
if (!condition) {
|
|
|
|
enforce<Exiv2::Error>(condition, err_code, std::forward<T>(args)...);
|
|
|
|
throw Exiv2::Error(err_code, arg1, arg2, arg3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace Exiv2::Internal
|
|
|
|
} // namespace Exiv2::Internal
|
|
|
|