void foo(const Any& arg) { const Type& t = arg.getValueType(); if (t == cppu::UnoType< XReference >::get()) { Reference<XReference> myref = *reinterpret_cast<const Reference<XReference>*>(arg.getValue()); ... } }Page 137, entire section "Mapping of Type":
The UNO type type
is mapped to
com::sun::star::uno::Type
. It holds the name of a type and the
com.sun.star.uno.TypeClass
. The type allows you to obtain a
com::sun::star::uno::TypeDescription
that contains all the
information defined in the IDL. For a given UNO type, a corresponding
com::sun::star::uno::Type
instance can be obtained through the
cppu::UnoType
class template:
// Get the UNO type long: com::sun::star::uno::Type longType = cppu::UnoType< sal_Int32 >::get(); // Get the UNO type char: com::sun::star::uno::Type charTpye = cppu::UnoType< cppu::UnoCharType >::get(); // Get the UNO type string: com::sun::star::uno::Type stringType = cppu::UnoType< rtl::OUString >::get(); // Get the UNO interface type com.sun.star.container.XEnumeration: com::sun::star::uno::Type enumerationType = cppu::UnoType< com::sun::star::container::XEnumeration >::get();Some C++ types that represent UNO types cannot be used as C++ template arguments, or ambiguously represent more than one UNO type, so there are special C++ types
cppu::UnoVoidType
,
cppu::UnoUnsignedShortType
, cppu::UnoCharType
, and
cppu::UnoSequenceType
that can be used as arguments for
cppu::UnoType
in those cases.
The overloaded getCppuType
function was an older mechanism to
obtain com::sun::star::uno::Type
instances. It is deprecated now
(certain uses of getCppuType
in template code would not work as
intended), and cppu::UnoType
should be used instead.
Page 138, third code snippet:
Any foo() { sal_Int32 i = 2; if( ... ) i = ...; return Any( &i, cppu::UnoType< sal_Int32 >::get() ); }Page 139, first paragraph after the bulleted list:
On some platforms, the C++ typedef types sal_uInt16
(representing the UNO type unsigned short
) and
sal_Unicode
(representing the UNO type char
) are
synonyms for the same fundamental C++ type. This could lead to problems when
either of those types is used as a type argument of a polymorphic struct type.
The chosen solution is to generally forbid the (deprecated) UNO types
unsigned short
, unsigned long
, and unsigned
hyper
as type arguments of polymorphic struct types.
Any automObject; // pVariant is a VARIANT* and contains the value that is going to be converted automObject.setValue((void*) &pVariant, cppu::UnoType< sal_uInt32 >::get());