Files
yoga/yoga/debug/AssertFatal.cpp
Nick Gerleman 70954bbda5 C++ style enums 5/N: LogLevel (#1387)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1387

X-link: https://github.com/facebook/react-native/pull/39447

This converts usages of YGLogLevel to LogLevel

Reviewed By: rozele

Differential Revision: D49270695

fbshipit-source-id: 2ba5b4f2b0af93fef89dbbb2ce54c2f486670aac
2023-09-14 23:06:34 -07:00

51 lines
1.1 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <stdexcept>
#include <yoga/debug/AssertFatal.h>
#include <yoga/debug/Log.h>
namespace facebook::yoga {
[[noreturn]] void fatalWithMessage(const char* message) {
#if defined(__cpp_exceptions)
throw std::logic_error(message);
#else
std::terminate();
#endif
}
void assertFatal(const bool condition, const char* message) {
if (!condition) {
yoga::log(LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
void assertFatalWithNode(
const yoga::Node* const node,
const bool condition,
const char* message) {
if (!condition) {
yoga::log(node, LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
void assertFatalWithConfig(
const yoga::Config* const config,
const bool condition,
const char* message) {
if (!condition) {
yoga::log(config, LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
} // namespace facebook::yoga