Add Embing'ing of UNO Any getter for enums
...which taps into the internals of emscripten::val, which is based on std::type_info identifiers, so we need an additional statically-built mapping between UNO (enum, for now) types and std::type_info Change-Id: I9fc1ff33fe31a1e1052504905de446ed2193e014 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164359 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
This commit is contained in:
@@ -14,11 +14,14 @@
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
#include <com/sun/star/uno/Reference.hxx>
|
||||
#include <com/sun/star/uno/Sequence.hxx>
|
||||
#include <com/sun/star/uno/Type.hxx>
|
||||
#include <cppu/unotype.hxx>
|
||||
#include <sal/types.h>
|
||||
|
||||
template <typename T> struct emscripten::smart_ptr_trait<css::uno::Reference<T>>
|
||||
@@ -33,6 +36,11 @@ template <typename T> struct emscripten::smart_ptr_trait<css::uno::Reference<T>>
|
||||
|
||||
namespace unoembindhelpers
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
void registerUnoType(css::uno::Type const& type, std::type_info const* id);
|
||||
}
|
||||
|
||||
enum class uno_Reference
|
||||
{
|
||||
FromAny
|
||||
@@ -76,6 +84,11 @@ void checkSequenceAccess(css::uno::Sequence<T> const& sequence, sal_Int32 index)
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> void registerUnoType()
|
||||
{
|
||||
detail::registerUnoType(cppu::UnoType<T>::get(), &typeid(T));
|
||||
}
|
||||
|
||||
template <typename T> void registerSequence(char const* name)
|
||||
{
|
||||
emscripten::class_<css::uno::Sequence<T>>(name)
|
||||
|
@@ -849,6 +849,7 @@ SAL_IMPLEMENT_MAIN()
|
||||
<< mem.name << ")";
|
||||
}
|
||||
cppOut << ";\n";
|
||||
cppOut << " ::unoembindhelpers::registerUnoType<" << cppName(enm) << ">();\n";
|
||||
dumpRegisterFunctionEpilog(cppOut, n);
|
||||
}
|
||||
std::set<OUString> sequences;
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
#include <utility>
|
||||
|
||||
using namespace emscripten;
|
||||
using namespace css::uno;
|
||||
@@ -166,6 +167,31 @@ Reference<css::frame::XModel> getCurrentModelFromViewSh()
|
||||
}
|
||||
return pSh->GetCurrentDocument();
|
||||
}
|
||||
|
||||
struct LessType
|
||||
{
|
||||
bool operator()(css::uno::Type const& type1, css::uno::Type const& type2) const
|
||||
{
|
||||
return type1.getTypeLibType() < type2.getTypeLibType();
|
||||
}
|
||||
};
|
||||
|
||||
std::map<css::uno::Type, std::type_info const*, LessType> unoTypes;
|
||||
|
||||
std::type_info const* getTypeId(css::uno::Type const& type)
|
||||
{
|
||||
auto const i = unoTypes.find(type);
|
||||
if (i == unoTypes.end())
|
||||
{
|
||||
throw std::runtime_error("unregistered UNO type");
|
||||
}
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
|
||||
namespace unoembindhelpers::detail
|
||||
{
|
||||
void registerUnoType(css::uno::Type const& type, std::type_info const* id) { unoTypes[type] = id; }
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(PrimaryBindings)
|
||||
@@ -263,7 +289,12 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
|
||||
case css::uno::TypeClass_SEQUENCE:
|
||||
return emscripten::val::undefined(); //TODO
|
||||
case css::uno::TypeClass_ENUM:
|
||||
return emscripten::val::undefined(); //TODO
|
||||
{
|
||||
emscripten::internal::WireTypePack argv(
|
||||
std::move(*static_cast<sal_Int32 const*>(self.getValue())));
|
||||
return emscripten::val::take_ownership(
|
||||
_emval_take_value(getTypeId(self.getValueType()), argv));
|
||||
}
|
||||
case css::uno::TypeClass_STRUCT:
|
||||
return emscripten::val::undefined(); //TODO
|
||||
case css::uno::TypeClass_EXCEPTION:
|
||||
|
@@ -265,7 +265,7 @@ Module.addOnPostRun(function() {
|
||||
{
|
||||
let v = test.getAnyEnum();
|
||||
console.log(v);
|
||||
//TODO: console.assert(v.get() === uno.org.libreoffice.embindtest.Enum.E_2);
|
||||
console.assert(v.get() === uno.org.libreoffice.embindtest.Enum.E_2);
|
||||
console.assert(test.isAnyEnum(v));
|
||||
v.delete();
|
||||
//TODO: let a = new Module.Any(
|
||||
|
Reference in New Issue
Block a user