Add RawValue support for arrays of arrays

Summary: Adds support for dynamic value that are `std::vector<std::vector<RawValue>>`

Reviewed By: shergin, mdvacca

Differential Revision: D16936932

fbshipit-source-id: fc8d087f9705af9da56ccc1bd9a0537b2bfeb50d
This commit is contained in:
Rick Hanlon
2019-09-06 06:04:17 -07:00
committed by Facebook Github Bot
parent c232b5ae3b
commit 91d59eb20b
2 changed files with 38 additions and 0 deletions
@@ -250,6 +250,19 @@ class RawValue {
return result;
}
template <typename T>
static std::vector<std::vector<T>> castValue(
const folly::dynamic &dynamic,
std::vector<std::vector<T>> *type) noexcept {
assert(dynamic.isArray());
auto result = std::vector<std::vector<T>>{};
result.reserve(dynamic.size());
for (const auto &item : dynamic) {
result.push_back(castValue(item, (std::vector<T> *)nullptr));
}
return result;
}
template <typename T>
static better::map<std::string, T> castValue(
const folly::dynamic &dynamic,
@@ -46,6 +46,31 @@ void fromRawValue(RawValue const &rawValue, std::vector<T> &result) {
result.push_back(itemResult);
}
template <typename T>
void fromRawValue(
RawValue const &rawValue,
std::vector<std::vector<T>> &result) {
if (rawValue.hasType<std::vector<std::vector<RawValue>>>()) {
auto items = (std::vector<std::vector<RawValue>>)rawValue;
auto length = items.size();
result.clear();
result.reserve(length);
for (int i = 0; i < length; i++) {
T itemResult;
fromRawValue(items.at(i), itemResult);
result.push_back(itemResult);
}
return;
}
// The case where `value` is not an array.
result.clear();
result.reserve(1);
T itemResult;
fromRawValue(rawValue, itemResult);
result.push_back(itemResult);
}
template <typename T, typename U = T>
T convertRawProp(
RawProps const &rawProps,