This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] #352 - android-conversion from runtime styling
- Loading branch information
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#pragma once | ||
|
||
#include "value.hpp" | ||
|
||
#include <mbgl/platform/log.hpp> | ||
#include <mbgl/style/conversion.hpp> | ||
#include <mbgl/util/feature.hpp> | ||
#include <mbgl/util/optional.hpp> | ||
|
||
#include <jni/jni.hpp> | ||
|
||
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<mbgl::android::Value> objectMember(const mbgl::android::Value& value, const char* key) { | ||
mbgl::android::Value member = value.get(key); | ||
|
||
if (!member.isNull()) { | ||
return member; | ||
} else { | ||
return {}; | ||
} | ||
} | ||
|
||
template <class Fn> | ||
optional<Error> eachMember(const mbgl::android::Value& value, Fn&& fn) { | ||
//TODO | ||
mbgl::Log::Warning(mbgl::Event::Android, "eachMember not implemented"); | ||
return {}; | ||
} | ||
|
||
inline optional<bool> toBool(const mbgl::android::Value& value) { | ||
if (value.isBool()) { | ||
return value.toBool(); | ||
} else { | ||
return {}; | ||
} | ||
} | ||
|
||
inline optional<float> toNumber(const mbgl::android::Value& value) { | ||
if (value.isNumber()) { | ||
return value.toNumber(); | ||
} else { | ||
return {}; | ||
} | ||
} | ||
|
||
inline optional<std::string> toString(const mbgl::android::Value& value) { | ||
if (value.isString()) { | ||
return value.toString(); | ||
} else { | ||
return {}; | ||
} | ||
} | ||
|
||
inline optional<Value> 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 |