1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_CPPU_UNOTYPE_HXX
25 #define INCLUDED_CPPU_UNOTYPE_HXX
27 #include "sal/config.h"
31 #if defined LIBO_INTERNAL_ONLY
32 #include <type_traits>
35 #include "sal/types.h"
36 #include "typelib/typeclass.h"
37 #include "typelib/typedescription.h"
39 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
43 template< typename
> class Reference
;
44 template< typename
> class Sequence
;
47 namespace rtl
{ class OUString
; }
51 template< typename
> class UnoType
;
54 A unique C++ type representing the UNO type VOID in cppu::UnoType.
56 This type is declared but not defined. Its only use is as a template
57 argument to cppu::UnoType.
64 A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType.
66 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
67 type is needed to unambiguously specify UNO types in cppu::UnoType.
69 This type is declared but not defined. Its only use is as a template
70 argument to cppu::UnoType.
74 struct UnoUnsignedShortType
;
77 A unique C++ type representing the UNO type CHAR in cppu::UnoType.
79 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
80 type is needed to unambiguously specify UNO types in cppu::UnoType.
82 This type is declared but not defined. Its only use is as a template
83 argument to cppu::UnoType.
90 A unique C++ type template representing the UNO sequence types in
93 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
94 type is needed to unambiguously specify UNO types in cppu::UnoType.
96 This type is declared but not defined. Its only use is as a template
97 argument to cppu::UnoType.
101 template< typename
> struct UnoSequenceType
;
105 inline css::uno::Type
const & getTypeFromTypeDescriptionReference(
106 ::typelib_TypeDescriptionReference
* const * tdr
)
108 return *reinterpret_cast< css::uno::Type
const * >(tdr
);
111 inline css::uno::Type
const &
112 getTypeFromTypeClass(::typelib_TypeClass tc
) {
113 return getTypeFromTypeDescriptionReference(
114 ::typelib_static_type_getByTypeClass(tc
));
121 namespace cppu
{ namespace detail
{
123 inline css::uno::Type
const &
124 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType
const *) {
125 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID
);
128 inline css::uno::Type
const &
129 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER
bool const *) {
130 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN
);
133 inline css::uno::Type
const &
134 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Bool
const *) {
135 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN
);
138 inline css::uno::Type
const &
139 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8
const *) {
140 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE
);
143 inline css::uno::Type
const &
144 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16
const *) {
145 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT
);
148 inline css::uno::Type
const &
149 cppu_detail_getUnoType(
150 SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType
const *)
152 return ::cppu::detail::getTypeFromTypeClass(
153 ::typelib_TypeClass_UNSIGNED_SHORT
);
156 #if defined LIBO_INTERNAL_ONLY
157 // cf. sal/types.h sal_Unicode
158 inline css::uno::Type
const &
159 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_uInt16
const *) {
160 return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_UNSIGNED_SHORT
);
164 inline css::uno::Type
const &
165 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32
const *) {
166 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG
);
169 inline css::uno::Type
const &
170 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt32
const *) {
171 return ::cppu::detail::getTypeFromTypeClass(
172 ::typelib_TypeClass_UNSIGNED_LONG
);
175 inline css::uno::Type
const &
176 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64
const *) {
177 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER
);
180 inline css::uno::Type
const &
181 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt64
const *) {
182 return ::cppu::detail::getTypeFromTypeClass(
183 ::typelib_TypeClass_UNSIGNED_HYPER
);
186 inline css::uno::Type
const &
187 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER
float const *) {
188 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT
);
191 inline css::uno::Type
const &
192 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER
double const *) {
193 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE
);
196 inline css::uno::Type
const &
197 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType
const *) {
198 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR
);
201 #if defined LIBO_INTERNAL_ONLY
202 // cf. sal/types.h sal_Unicode
203 inline css::uno::Type
const &
204 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Unicode
const *) {
205 return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_CHAR
);
209 inline css::uno::Type
const &
210 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString
const *) {
211 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING
);
214 inline css::uno::Type
const &
215 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER
css::uno::Type
const *)
217 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE
);
220 inline css::uno::Type
const &
221 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER
css::uno::Any
const *)
223 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY
);
226 template< typename T
> inline css::uno::Type
const &
227 cppu_detail_getUnoType(
228 SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType
< T
> const *)
230 //TODO: depending on memory model, the following might not work reliably
231 static typelib_TypeDescriptionReference
* p
= NULL
;
233 ::typelib_static_sequence_type_init(
234 &p
, ::cppu::UnoType
< T
>::get().getTypeLibType());
236 return ::cppu::detail::getTypeFromTypeDescriptionReference(&p
);
239 template< typename T
> inline css::uno::Type
const &
240 cppu_detail_getUnoType(
241 SAL_UNUSED_PARAMETER
css::uno::Sequence
< T
> const *)
243 return cppu_detail_getUnoType(
244 static_cast< ::cppu::UnoSequenceType
< T
> * >(NULL
));
247 inline css::uno::Type
const & cppu_detail_getUnoType(
248 SAL_UNUSED_PARAMETER
css::uno::Exception
const *)
250 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION
);
253 inline css::uno::Type
const & cppu_detail_getUnoType(
254 SAL_UNUSED_PARAMETER
css::uno::XInterface
const *)
256 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE
);
259 template< typename T
> inline css::uno::Type
const &
260 cppu_detail_getUnoType(
261 SAL_UNUSED_PARAMETER
css::uno::Reference
< T
> const *)
263 return ::cppu::UnoType
< T
>::get();
271 Get the css::uno::Type instance representing a certain UNO type.
273 For each C++ type representing a UNO type, the corresponding instantiation of
274 this template has a public static member function get(). (The template is
275 specialized for C++ templates representing polymorphic struct type templates
276 of UNO. In those cases, it does not work to instantiate UnoType with a C++
277 type that is derived from a C++ type that represents a UNO type, but does not
278 itself represent a UNO type. In all other cases, UnoType even works for such
279 C++ types that are unambiguously derived from one C++ type that represents a
280 UNO type.) In addition to those C++ types that are mappings of UNO types
281 (except for sal_uInt16 and sal_Unicode, see below), the following C++ types
282 are appropriate as template arguments: void, cppu::UnoVoidType, bool,
283 cppu::UnoUnsignedShortType, cppu::UnoCharType, cppu::UnoSequenceType with any
284 appropriate template argument (the latter three to unambiguously specify UNO
285 types, as the UNO types UNSIGNED SHORT and CHAR map to the same C++ type),
286 and css::uno::Reference with any appropriate template argument.
290 template< typename T
> class UnoType
{
292 static css::uno::Type
const & get() {
293 using namespace ::cppu::detail
;
294 #if defined LIBO_INTERNAL_ONLY
295 typedef typename
std::remove_reference
<T
>::type T1
;
296 // for certain uses of UnoType<decltype(x)>
300 return cppu_detail_getUnoType(static_cast< T1
* >(NULL
));
304 UnoType(UnoType
&) SAL_DELETED_FUNCTION
;
305 ~UnoType() SAL_DELETED_FUNCTION
;
306 void operator =(UnoType
&) SAL_DELETED_FUNCTION
;
309 template<> css::uno::Type
inline const & UnoType
<void>::get() {
310 return cppu::UnoType
<cppu::UnoVoidType
>::get();
314 A working replacement for getCppuType (see there).
316 There are three overloads of this function that together form the replacement
317 of getCppuType. The replacement has exactly the same semantics as
318 getCppuType, in that it returns correct results for the UNO type UNSIGNED
319 SHORT but not for the UNO type CHAR.
323 template< typename T
> inline css::uno::Type
const &
324 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T
const *) {
325 return ::cppu::UnoType
< T
>::get();
329 A working replacement for getCppuType (see there).
331 There are three overloads of this function that together form the replacement
332 of getCppuType. The replacement has exactly the same semantics as
333 getCppuType, in that it returns correct results for the UNO type UNSIGNED
334 SHORT but not for the UNO type CHAR.
338 inline css::uno::Type
const &
339 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16
const *) {
340 return ::cppu::UnoType
< ::cppu::UnoUnsignedShortType
>::get();
344 A working replacement for getCppuType (see there).
346 There are three overloads of this function that together form the replacement
347 of getCppuType. The replacement has exactly the same semantics as
348 getCppuType, in that it returns correct results for the UNO type UNSIGNED
349 SHORT but not for the UNO type CHAR.
353 template< typename T
> inline css::uno::Type
const &
354 getTypeFavourUnsigned(css::uno::Sequence
< T
> const *);
355 // defined in com/sun/star/uno/Sequence.hxx
360 A working replacement for getCppuType (see there).
362 There are three overloads of this function that together form the replacement
363 of the getCppuType template. The replacement has exactly the same semantics
364 as the getCppuType template, in that it returns correct results for the UNO
365 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
366 returns the intended results for sequence types.
370 template< typename T
> inline css::uno::Type
const &
371 getTypeFavourChar(SAL_UNUSED_PARAMETER T
const *) {
372 return ::cppu::UnoType
< T
>::get();
376 A working replacement for getCppuType (see there).
378 There are three overloads of this function that together form the replacement
379 of the getCppuType template. The replacement has exactly the same semantics
380 as the getCppuType template, in that it returns correct results for the UNO
381 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
382 returns the intended results for sequence types.
386 inline css::uno::Type
const &
387 getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode
const *) {
388 return ::cppu::UnoType
< ::cppu::UnoCharType
>::get();
392 A working replacement for getCppuType (see there).
394 There are three overloads of this function that together form the replacement
395 of the getCppuType template. The replacement has exactly the same semantics
396 as the getCppuType template, in that it returns correct results for the UNO
397 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
398 returns the intended results for sequence types.
402 template< typename T
> inline css::uno::Type
const &
403 getTypeFavourChar(css::uno::Sequence
< T
> const *);
404 // defined in com/sun/star/uno/Sequence.hxx
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */