23#include <typelib/typedescription.hxx>
26using com::sun::star::uno::TypeClass;
27using com::sun::star::uno::Type;
28using com::sun::star::uno::RuntimeException;
29using com::sun::star::uno::Any;
30using com::sun::star::uno::TypeDescription;
36 const char * ret =
nullptr;
39 case css::uno::TypeClass_VOID:
41 case css::uno::TypeClass_CHAR:
43 case css::uno::TypeClass_BOOLEAN:
44 ret =
"BOOLEAN";
break;
45 case css::uno::TypeClass_BYTE:
47 case css::uno::TypeClass_SHORT:
49 case css::uno::TypeClass_UNSIGNED_SHORT:
50 ret =
"UNSIGNED_SHORT";
break;
51 case css::uno::TypeClass_LONG:
53 case css::uno::TypeClass_UNSIGNED_LONG:
54 ret =
"UNSIGNED_LONG";
break;
55 case css::uno::TypeClass_HYPER:
57 case css::uno::TypeClass_UNSIGNED_HYPER:
58 ret =
"UNSIGNED_HYPER";
break;
59 case css::uno::TypeClass_FLOAT:
61 case css::uno::TypeClass_DOUBLE:
62 ret =
"DOUBLE";
break;
63 case css::uno::TypeClass_STRING:
64 ret =
"STRING";
break;
65 case css::uno::TypeClass_TYPE:
67 case css::uno::TypeClass_ANY:
69 case css::uno::TypeClass_ENUM:
71 case css::uno::TypeClass_STRUCT:
72 ret =
"STRUCT";
break;
73 case css::uno::TypeClass_EXCEPTION:
74 ret =
"EXCEPTION";
break;
75 case css::uno::TypeClass_SEQUENCE:
76 ret =
"SEQUENCE";
break;
77 case css::uno::TypeClass_INTERFACE:
78 ret =
"INTERFACE";
break;
79 case css::uno::TypeClass_TYPEDEF:
80 ret =
"TYPEDEF";
break;
81 case css::uno::TypeClass_SERVICE:
82 ret =
"SERVICE";
break;
83 case css::uno::TypeClass_MODULE:
84 ret =
"MODULE";
break;
85 case css::uno::TypeClass_INTERFACE_METHOD:
86 ret =
"INTERFACE_METHOD";
break;
87 case css::uno::TypeClass_INTERFACE_ATTRIBUTE:
88 ret =
"INTERFACE_ATTRIBUTE";
break;
90 ret =
"UNKNOWN";
break;
117 return getClass( r ,
"ByteSequence" );
128 PyRef value( PyObject_GetAttrString( obj,
"value" ), SAL_NO_ACQUIRE );
129 if( ! PyUnicode_Check(
value.get() ) )
132 "attribute value of uno.Char is not a unicode string" );
135 if( PyUnicode_GetLength(
value.get() ) < 1 )
138 "uno.Char contains an empty unicode string");
148 PyRef typeName( PyObject_GetAttrString( obj,
"typeName" ), SAL_NO_ACQUIRE);
149 PyRef value( PyObject_GetAttrString( obj,
"value" ), SAL_NO_ACQUIRE);
150 if( !PyUnicode_Check(
typeName.get() ) || ! PyUnicode_Check(
value.get() ) )
153 "attributes typeName and/or value of uno.Enum are not strings" );
156 OUString strTypeName( OUString::createFromAscii( PyUnicode_AsUTF8(
typeName.get() ) ) );
157 char const *stringValue = PyUnicode_AsUTF8(
value.get() );
159 TypeDescription desc( strTypeName );
165 if(desc.get()->eTypeClass != typelib_TypeClass_ENUM )
168 OUString::createFromAscii(
typeClassToString(
static_cast<css::uno::TypeClass
>(desc.get()->eTypeClass))) +
174 typelib_EnumTypeDescription *pEnumDesc =
reinterpret_cast<typelib_EnumTypeDescription*
>(desc.get());
176 for(
i = 0;
i < pEnumDesc->nEnumValues ;
i ++ )
178 if( OUString::unacquired(&pEnumDesc->ppEnumNames[
i]).equalsAscii( stringValue ) )
183 if(
i == pEnumDesc->nEnumValues )
185 throw RuntimeException(
"value " + OUString::createFromAscii( stringValue ) +
186 "is unknown in enum " +
187 OUString::createFromAscii( PyUnicode_AsUTF8(
typeName.get() ) ) );
189 ret =
Any( &pEnumDesc->pEnumValues[
i], desc.get()->pWeakRef );
197 PyRef pyName( PyObject_GetAttrString( o,
"typeName" ), SAL_NO_ACQUIRE);
198 if( !PyUnicode_Check( pyName.
get() ) )
201 "type object does not have typeName property" );
204 PyRef pyTC( PyObject_GetAttrString( o,
"typeClass" ), SAL_NO_ACQUIRE );
207 OUString
name( OUString::createFromAscii( PyUnicode_AsUTF8( pyName.
get() ) ) );
208 TypeDescription desc(
name );
213 css::uno::TypeClass tc = *o3tl::doAccess<css::uno::TypeClass>(enumValue);
214 if(
static_cast<css::uno::TypeClass
>(desc.get()->eTypeClass) != tc )
217 OUString::createFromAscii(
typeClassToString(
static_cast<TypeClass
>(desc.get()->eTypeClass)) ) +
218 ", but type got construct with typeclass " +
221 return desc.get()->pWeakRef;
229 OString buf = OString::Concat(
"couldn't access uno.") + clazz;
230 PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
233 PyRef instance( PyObject_CallObject(
code.get(),
args.get() ), SAL_NO_ACQUIRE);
234 Py_XINCREF( instance.
get() );
235 return instance.
get();
243 PyTuple_SetItem(
args.get() , 0 , PyUnicode_FromString( enumBase ) );
244 PyTuple_SetItem(
args.get() , 1 , PyUnicode_FromString( enumValue ) );
255 PyTuple_SetItem(
args.get() , 0 , PyUnicode_FromString(
typeName ) );
259 PyTuple_SetItem(
args.get() , 1 , typeClass);
268 static_assert(
sizeof(
sal_Unicode) ==
sizeof(Py_UCS2),
"unexpected size");
269 PyTuple_SetItem(
args.get() , 0 , PyUnicode_FromKindAndData( PyUnicode_2BYTE_KIND, &val ,1) );
275 const css::uno::Sequence< sal_Int8 > &byteSequence,
const Runtime &r )
278 PyBytes_FromStringAndSize(
reinterpret_cast<char const *
>(byteSequence.getConstArray()), byteSequence.getLength()),
Helper class for keeping references to python objects.
PyObject * get() const noexcept
PyObject * getAcquired() const
The pyuno::Runtime class keeps the internal state of the python UNO bridge for the currently in use p...
RuntimeImpl * getImpl() const
Returns the internal handle.
static PyObject * callCtor(const Runtime &r, const char *clazz, const PyRef &args)
PyObject * PyUNO_Type_new(const char *typeName, css::uno::TypeClass t, const Runtime &r)
PyRef getCharClass(const Runtime &)
PyObject * PyUNO_ByteSequence_new(const css::uno::Sequence< sal_Int8 > &, const Runtime &r)
PyObject * PyUNO_char_new(sal_Unicode c, const Runtime &r)
const char * typeClassToString(css::uno::TypeClass t)
sal_Unicode PyChar2Unicode(PyObject *o)
PyObject * PyUNO_Enum_new(const char *enumBase, const char *enumValue, const Runtime &r)
PyRef getTypeClass(const Runtime &)
PyRef getEnumClass(const Runtime &)
css::uno::Type PyType2Type(PyObject *o)
PyRef getByteSequenceClass(const Runtime &)
@ NOT_NULL
definition of a no acquire enum for ctors
PyRef getClass(const OUString &name, const Runtime &runtime)
css::uno::Any PyEnum2Enum(PyObject *obj)
PyRef getAnyClass(const Runtime &)
PyRef const & getUnoModule()
PyObject_HEAD struct RuntimeCargo * cargo