From 8428368d79118f1d0e09615c5d2b92065b8838d4 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 1 Mar 2024 12:49:40 +0100 Subject: Improve Embing'ing of UNO Any somewhat Change-Id: I82e38ac815765b62601076cf61745fe9889451b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164358 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- static/source/unoembindhelpers/PrimaryBindings.cxx | 141 ++++++++++++++------- 1 file changed, 95 insertions(+), 46 deletions(-) (limited to 'static') diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx index 50048a97ada6..5b76b549cb13 100644 --- a/static/source/unoembindhelpers/PrimaryBindings.cxx +++ b/static/source/unoembindhelpers/PrimaryBindings.cxx @@ -12,9 +12,12 @@ #include #include +#include #include #include #include +#include +#include #include #include #include @@ -25,6 +28,7 @@ #include #include +#include #include #include @@ -179,52 +183,97 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings) }); // Any - class_("Any").constructor(+[](const val& rObject, const TypeClass& rUnoType) -> Any { - switch (rUnoType) - { - case TypeClass_VOID: - break; - case TypeClass_CHAR: - return Any{ rObject.as() }; - case TypeClass_BOOLEAN: - return Any{ rObject.as() }; - case TypeClass_BYTE: - return Any{ rObject.as() }; - case TypeClass_SHORT: - return Any{ rObject.as() }; - case TypeClass_UNSIGNED_SHORT: - return Any{ rObject.as() }; - case TypeClass_LONG: - return Any{ rObject.as() }; - case TypeClass_UNSIGNED_LONG: - return Any{ rObject.as() }; - case TypeClass_HYPER: - return Any{ rObject.as() }; - case TypeClass_UNSIGNED_HYPER: - return Any{ rObject.as() }; - case TypeClass_FLOAT: - return Any{ rObject.as() }; - case TypeClass_DOUBLE: - return Any{ rObject.as() }; - case TypeClass_STRING: - return Any{ OUString(rObject.as()) }; - case TypeClass_TYPE: - case TypeClass_ANY: - case TypeClass_ENUM: - case TypeClass_STRUCT: - case TypeClass_EXCEPTION: - case TypeClass_SEQUENCE: - case TypeClass_INTERFACE: - case TypeClass_TYPEDEF: - case TypeClass_SERVICE: - case TypeClass_MODULE: - case TypeClass_INTERFACE_METHOD: - case TypeClass_INTERFACE_ATTRIBUTE: - default: - break; - } - return {}; - }); + class_("Any") + .constructor(+[](const val& rObject, const TypeClass& rUnoType) -> Any { + switch (rUnoType) + { + case TypeClass_VOID: + return {}; + case TypeClass_BOOLEAN: + return Any{ rObject.as() }; + case TypeClass_BYTE: + return Any{ rObject.as() }; + case TypeClass_SHORT: + return Any{ rObject.as() }; + case TypeClass_UNSIGNED_SHORT: + return Any{ rObject.as() }; + case TypeClass_LONG: + return Any{ rObject.as() }; + case TypeClass_UNSIGNED_LONG: + return Any{ rObject.as() }; + case TypeClass_HYPER: + return Any{ rObject.as() }; + case TypeClass_UNSIGNED_HYPER: + return Any{ rObject.as() }; + case TypeClass_FLOAT: + return Any{ rObject.as() }; + case TypeClass_DOUBLE: + return Any{ rObject.as() }; + case TypeClass_CHAR: + return Any{ rObject.as() }; + case TypeClass_STRING: + return Any{ OUString(rObject.as()) }; + case TypeClass_TYPE: + return {}; //TODO + case TypeClass_SEQUENCE: + return {}; //TODO + case TypeClass_ENUM: + return {}; //TODO + case TypeClass_STRUCT: + return {}; //TODO + case TypeClass_EXCEPTION: + return {}; //TODO + case TypeClass_INTERFACE: + return {}; //TODO + default: + throw std::invalid_argument("bad type class"); + } + }) + .function("get", +[](css::uno::Any const& self) { + switch (self.getValueType().getTypeClass()) + { + case css::uno::TypeClass_VOID: + return emscripten::val::undefined(); + case css::uno::TypeClass_BOOLEAN: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_BYTE: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_SHORT: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_UNSIGNED_SHORT: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_LONG: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_UNSIGNED_LONG: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_HYPER: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_UNSIGNED_HYPER: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_FLOAT: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_DOUBLE: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_CHAR: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_STRING: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_TYPE: + return emscripten::val(*o3tl::forceAccess(self)); + case css::uno::TypeClass_SEQUENCE: + return emscripten::val::undefined(); //TODO + case css::uno::TypeClass_ENUM: + return emscripten::val::undefined(); //TODO + case css::uno::TypeClass_STRUCT: + return emscripten::val::undefined(); //TODO + case css::uno::TypeClass_EXCEPTION: + return emscripten::val::undefined(); //TODO + case css::uno::TypeClass_INTERFACE: + return emscripten::val::undefined(); //TODO + default: + O3TL_UNREACHABLE; + }; + }); registerInOutParam("uno_InOutParam_boolean"); registerInOutParam("uno_InOutParam_byte"); -- cgit