summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-06-07 10:43:48 +0200
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-06-07 12:09:22 +0200
commitd155febef6a3d9b469f78ed4c5e70730032e3d38 (patch)
tree6c12dab4a52c32a032cdec29980cf9870e9585e4 /static
parentea2ecd04dd70e228f0ffdc6830b69c837eab8d67 (diff)
Embind: Add some type-inquiry functions to uno_Type and uno_Any
...that proved useful in experiments wrapping a JS Proxy around the Embind representation of C++ UNO objects. Change-Id: Ia4018ec8dee2c222fb76ba8e2f529f4845f0134c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168518 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/source/unoembindhelpers/PrimaryBindings.cxx21
1 files changed, 21 insertions, 0 deletions
diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx
index 9f9a5cf588d5..a8c7acab9250 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -16,6 +16,7 @@
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/uno/Type.hxx>
+#include <com/sun/star/uno/TypeClass.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/exc_hlp.hxx>
@@ -26,6 +27,7 @@
#include <sal/log.hxx>
#include <sfx2/viewsh.hxx>
#include <static/unoembindhelpers/PrimaryBindings.hxx>
+#include <typelib/typeclass.h>
#include <typelib/typedescription.h>
#include <typelib/typedescription.hxx>
#include <uno/data.h>
@@ -297,6 +299,24 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
+[](std::u16string const& name) {
return css::uno::Type(css::uno::TypeClass_INTERFACE, OUString(name));
})
+ .function("getTypeClass", +[](css::uno::Type const& self) { return self.getTypeClass(); })
+ .function(
+ "getSequenceComponentType",
+ +[](css::uno::Type const& self) {
+ if (self.getTypeClass() != css::uno::TypeClass_SEQUENCE)
+ {
+ throw std::invalid_argument("bad non-sequence type");
+ }
+ css::uno::TypeDescription desc;
+ self.getDescription(reinterpret_cast<typelib_TypeDescription**>(&desc));
+ if (!desc.is())
+ {
+ throw std::invalid_argument("bad sequence type");
+ }
+ assert(desc.get()->eTypeClass == typelib_TypeClass_SEQUENCE);
+ return css::uno::Type(
+ reinterpret_cast<typelib_IndirectTypeDescription const*>(desc.get())->pType);
+ })
.function("toString", +[](css::uno::Type const& self) {
auto const name = self.getTypeName();
return std::u16string(name.getStr(), name.getLength());
@@ -305,6 +325,7 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
// Any
class_<Any>("uno_Any")
.constructor(&constructAny)
+ .function("getType", &css::uno::Any::getValueType)
.function("get", +[](css::uno::Any const& self) {
switch (self.getValueType().getTypeClass())
{