2018-05-09 05:56:02 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-05-09 05:56:02 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2018-05-16 20:35:33 +00:00
|
|
|
#include <folly/Optional.h>
|
2018-05-09 05:56:02 +00:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2018-05-14 22:43:57 +00:00
|
|
|
inline std::string toString(const std::string &value) { return value; }
|
|
|
|
inline std::string toString(const int &value) { return folly::to<std::string>(value); }
|
|
|
|
inline std::string toString(const bool &value) { return folly::to<std::string>(value); }
|
|
|
|
inline std::string toString(const float &value) { return folly::to<std::string>(value); }
|
|
|
|
inline std::string toString(const double &value) { return folly::to<std::string>(value); }
|
|
|
|
|
2018-05-14 22:43:40 +00:00
|
|
|
template <typename T>
|
|
|
|
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, T value, T defaultValue = {}) {
|
|
|
|
if (value == defaultValue) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_shared<DebugStringConvertibleItem>(name, toString(value));
|
|
|
|
}
|
|
|
|
|
2018-05-14 22:43:42 +00:00
|
|
|
template <typename T>
|
|
|
|
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, folly::Optional<T> value, T defaultValue = {}) {
|
2018-05-16 20:35:33 +00:00
|
|
|
if (!value.hasValue()) {
|
2018-05-14 22:43:42 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-05-14 22:43:57 +00:00
|
|
|
|
2018-05-14 22:43:42 +00:00
|
|
|
return debugStringConvertibleItem(name, value.value_or(defaultValue), defaultValue);
|
|
|
|
}
|
|
|
|
|
2018-05-14 22:43:57 +00:00
|
|
|
inline SharedDebugStringConvertibleList operator+(const SharedDebugStringConvertibleList &lhs, const SharedDebugStringConvertibleList &rhs) {
|
2018-09-10 23:33:48 +00:00
|
|
|
auto result = SharedDebugStringConvertibleList {};
|
2018-05-14 22:43:57 +00:00
|
|
|
std::move(lhs.begin(), lhs.end(), std::back_inserter(result));
|
|
|
|
std::move(rhs.begin(), rhs.end(), std::back_inserter(result));
|
|
|
|
return result;
|
2018-05-09 05:56:02 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 22:43:57 +00:00
|
|
|
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, DebugStringConvertible value, std::string defaultValue) {
|
|
|
|
return debugStringConvertibleItem(name, value.getDebugDescription(), defaultValue);
|
|
|
|
}
|
2018-05-09 05:56:02 +00:00
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|