Skip to content

Commit

Permalink
Fabric: toString methods were moved into DebugStringConvertible w…
Browse files Browse the repository at this point in the history
…ith an implementation in .cpp file

Summary:
They need to be in DebugStringConvertible because it depends on they (and because `debugStringConvertibleUtils` depends on `DebugStringConvertible`).
We also moved they implementation to cpp file to avoid leaking Folly's features to consumer namespace.

Reviewed By: mdvacca

Differential Revision: D14715080

fbshipit-source-id: 7277e17b39a14a2d7ba7e5a9b44a70178feb1045
  • Loading branch information
shergin authored and facebook-github-bot committed Apr 4, 2019
1 parent 97e064b commit cabc9d1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
25 changes: 25 additions & 0 deletions ReactCommon/fabric/debug/DebugStringConvertible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include "DebugStringConvertible.h"

#include <folly/Conv.h>
#include <folly/Format.h>

namespace facebook {
namespace react {

Expand Down Expand Up @@ -107,6 +110,28 @@ SharedDebugStringConvertibleList DebugStringConvertible::getDebugProps() const {
return SharedDebugStringConvertibleList();
}

/*
* `toString`-family implementation.
*/
std::string toString(std::string const &value) {
return value;
}
std::string toString(int const &value) {
return folly::to<std::string>(value);
}
std::string toString(bool const &value) {
return folly::to<std::string>(value);
}
std::string toString(float const &value) {
return folly::to<std::string>(value);
}
std::string toString(double const &value) {
return folly::to<std::string>(value);
}
std::string toString(void const *value) {
return folly::sformat("0x{0:016x}", reinterpret_cast<size_t>(value));
}

#endif

} // namespace react
Expand Down
14 changes: 14 additions & 0 deletions ReactCommon/fabric/debug/DebugStringConvertible.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,19 @@ class DebugStringConvertible {};

#endif

#if RN_DEBUG_STRING_CONVERTIBLE

/*
* Set of particular-format-opinionated functions that convert base types to `std::string`; practically incapsulate `folly:to<>` and `folly::format`.
*/
std::string toString(std::string const &value);
std::string toString(int const &value);
std::string toString(bool const &value);
std::string toString(float const &value);
std::string toString(double const &value);
std::string toString(void const *value);

#endif

} // namespace react
} // namespace facebook
18 changes: 0 additions & 18 deletions ReactCommon/fabric/debug/debugStringConvertibleUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <string>
#include <vector>

#include <folly/Conv.h>
#include <folly/Optional.h>
#include <react/debug/DebugStringConvertible.h>
#include <react/debug/DebugStringConvertibleItem.h>

Expand All @@ -22,22 +20,6 @@ namespace react {

#if RN_DEBUG_STRING_CONVERTIBLE

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);
}

template <typename T>
inline SharedDebugStringConvertible
debugStringConvertibleItem(std::string name, T value, T defaultValue = {}) {
Expand Down

0 comments on commit cabc9d1

Please sign in to comment.