From 32e306c750ec7ed88172eac230ce5350d83d06df Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Mon, 25 Jul 2016 13:59:39 +0200 Subject: [PATCH] [android] #352 - android-conversion from runtime styling --- .../src/feature/android_conversion.hpp | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/platform/android/src/feature/android_conversion.hpp b/platform/android/src/feature/android_conversion.hpp index e69de29bb2d..5128cce51f9 100644 --- a/platform/android/src/feature/android_conversion.hpp +++ b/platform/android/src/feature/android_conversion.hpp @@ -0,0 +1,95 @@ +#pragma once + +#include "value.hpp" + +#include +#include +#include +#include + +#include + +namespace mbgl { +namespace style { +namespace conversion { + + +//XXX +#pragma GCC diagnostic ignored "-Wunused-parameter" + +inline bool isUndefined(const mbgl::android::Value& value) { + return value.isNull(); +} + +inline bool isArray(const mbgl::android::Value& value) { + return value.isArray(); +} + +inline bool isObject(const mbgl::android::Value& value) { + return value.isObject(); +} + +inline std::size_t arrayLength(const mbgl::android::Value& value) { + return value.getLength();; +} + +inline mbgl::android::Value arrayMember(const mbgl::android::Value& value, std::size_t i) { + return value.get(i); +} + +inline optional objectMember(const mbgl::android::Value& value, const char* key) { + mbgl::android::Value member = value.get(key); + + if (!member.isNull()) { + return member; + } else { + return {}; + } +} + +template +optional eachMember(const mbgl::android::Value& value, Fn&& fn) { + //TODO + mbgl::Log::Warning(mbgl::Event::Android, "eachMember not implemented"); + return {}; +} + +inline optional toBool(const mbgl::android::Value& value) { + if (value.isBool()) { + return value.toBool(); + } else { + return {}; + } +} + +inline optional toNumber(const mbgl::android::Value& value) { + if (value.isNumber()) { + return value.toNumber(); + } else { + return {}; + } +} + +inline optional toString(const mbgl::android::Value& value) { + if (value.isString()) { + return value.toString(); + } else { + return {}; + } +} + +inline optional toValue(const mbgl::android::Value& value) { + if (value.isBool()) { + return { value.toBool() }; + } else if (value.isString()) { + return { value.toString() }; + } else if (value.isNumber()) { + return { value.toNumber() }; + } else { + return {}; + } +} + +} // namespace conversion +} // namespace style +} // namespace mbgl \ No newline at end of file