mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Fabric: New nice way to deal with DebugStringConvertible items
Summary: No macros in product code. (Not all callsites are converted yet.) Reviewed By: mdvacca Differential Revision: D7797561 fbshipit-source-id: da899421bf99669a0e0a2b83df6004daf14355c2
This commit is contained in:
committed by
Facebook Github Bot
parent
d9ff1769aa
commit
6e537b000b
53
ReactCommon/fabric/debug/debugStringConvertibleUtils.h
Normal file
53
ReactCommon/fabric/debug/debugStringConvertibleUtils.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <fabric/debug/DebugStringConvertible.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
#include <folly/Conv.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
SharedDebugStringConvertibleList operator+(const SharedDebugStringConvertibleList &lhs, const SharedDebugStringConvertibleList &rhs);
|
||||
SharedDebugStringConvertible debugStringConvertibleItem(std::string name, DebugStringConvertible value, std::string defaultValue = "");
|
||||
|
||||
#define IS_EQUAL(a, b) ((a) == (b))
|
||||
#define IS_EQUAL_FLOAT(a, b) ((isnan(a) == isnan(b)) || ((a) == (b)))
|
||||
|
||||
#define DEBUG_STRING_CONVERTIBLE_TEMPLATE(type, converter) \
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(type, converter, {}, IS_EQUAL)
|
||||
|
||||
#define DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(type, converter, defaults, comparator) \
|
||||
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, type value, type defaultValue = defaults) { \
|
||||
if (comparator(value, defaultValue)) { \
|
||||
return nullptr; \
|
||||
} \
|
||||
return std::make_shared<DebugStringConvertibleItem>(name, converter(value)); \
|
||||
} \
|
||||
\
|
||||
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, folly::Optional<type> value, type defaultValue = defaults) { \
|
||||
if (value.has_value()) { \
|
||||
return nullptr; \
|
||||
} \
|
||||
return debugStringConvertibleItem(name, value.value_or(defaultValue), defaultValue); \
|
||||
}
|
||||
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE(std::string, )
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE(int, folly::to<std::string>)
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE(bool, folly::to<std::string>)
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(float, folly::to<std::string>, std::numeric_limits<float>::quiet_NaN(), IS_EQUAL_FLOAT)
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE_EX(double, folly::to<std::string>, std::numeric_limits<float>::quiet_NaN(), IS_EQUAL_FLOAT)
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user