tdf#124162: Crash when trying to accept changes
[LibreOffice.git] / include / cppu / unotype.hxx
blobf040159ce1e652557580468612f33553d3373702
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_CPPU_UNOTYPE_HXX
21 #define INCLUDED_CPPU_UNOTYPE_HXX
23 #include "sal/config.h"
25 #include <cstddef>
27 #if defined LIBO_INTERNAL_ONLY
28 #include <type_traits>
29 #endif
31 #include "sal/types.h"
32 #include "typelib/typeclass.h"
33 #include "typelib/typedescription.h"
35 namespace com { namespace sun { namespace star { namespace uno {
36 class Type;
37 class Any;
38 class Exception;
39 template< typename > class Reference;
40 template< typename > class Sequence;
41 class XInterface;
42 } } } }
43 namespace rtl { class OUString; }
45 namespace cppu {
47 template< typename > class UnoType;
49 /**
50 A unique C++ type representing the UNO type VOID in cppu::UnoType.
52 This type is declared but not defined. Its only use is as a template
53 argument to cppu::UnoType.
55 @since UDK 3.2.2
57 struct UnoVoidType;
59 /**
60 A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType.
62 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
63 type is needed to unambiguously specify UNO types in cppu::UnoType.
65 This type is declared but not defined. Its only use is as a template
66 argument to cppu::UnoType.
68 @since UDK 3.2.2
70 struct UnoUnsignedShortType;
72 /**
73 A unique C++ type representing the UNO type CHAR in cppu::UnoType.
75 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
76 type is needed to unambiguously specify UNO types in cppu::UnoType.
78 This type is declared but not defined. Its only use is as a template
79 argument to cppu::UnoType.
81 @since UDK 3.2.2
83 struct UnoCharType;
85 /**
86 A unique C++ type template representing the UNO sequence types in
87 cppu::UnoType.
89 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
90 type is needed to unambiguously specify UNO types in cppu::UnoType.
92 This type is declared but not defined. Its only use is as a template
93 argument to cppu::UnoType.
95 @since UDK 3.2.2
97 template< typename > struct UnoSequenceType;
99 namespace detail {
101 inline css::uno::Type const & getTypeFromTypeDescriptionReference(
102 ::typelib_TypeDescriptionReference * const * tdr)
104 return *reinterpret_cast< css::uno::Type const * >(tdr);
107 inline css::uno::Type const &
108 getTypeFromTypeClass(::typelib_TypeClass tc) {
109 return getTypeFromTypeDescriptionReference(
110 ::typelib_static_type_getByTypeClass(tc));
117 namespace cppu { namespace detail {
119 inline css::uno::Type const &
120 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *) {
121 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID);
124 inline css::uno::Type const &
125 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER bool const *) {
126 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
129 inline css::uno::Type const &
130 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Bool const *) {
131 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
134 inline css::uno::Type const &
135 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8 const *) {
136 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE);
139 inline css::uno::Type const &
140 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16 const *) {
141 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT);
144 inline css::uno::Type const &
145 cppu_detail_getUnoType(
146 SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType const *)
148 return ::cppu::detail::getTypeFromTypeClass(
149 ::typelib_TypeClass_UNSIGNED_SHORT);
152 #if defined LIBO_INTERNAL_ONLY
153 // cf. sal/types.h sal_Unicode
154 inline css::uno::Type const &
155 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_uInt16 const *) {
156 return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_UNSIGNED_SHORT);
158 #endif
160 inline css::uno::Type const &
161 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) {
162 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG);
165 inline css::uno::Type const &
166 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt32 const *) {
167 return ::cppu::detail::getTypeFromTypeClass(
168 ::typelib_TypeClass_UNSIGNED_LONG);
171 inline css::uno::Type const &
172 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64 const *) {
173 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER);
176 inline css::uno::Type const &
177 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt64 const *) {
178 return ::cppu::detail::getTypeFromTypeClass(
179 ::typelib_TypeClass_UNSIGNED_HYPER);
182 inline css::uno::Type const &
183 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER float const *) {
184 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT);
187 inline css::uno::Type const &
188 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER double const *) {
189 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE);
192 inline css::uno::Type const &
193 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) {
194 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR);
197 #if defined LIBO_INTERNAL_ONLY
198 // cf. sal/types.h sal_Unicode
199 inline css::uno::Type const &
200 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Unicode const *) {
201 return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_CHAR);
203 #endif
205 inline css::uno::Type const &
206 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) {
207 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING);
210 inline css::uno::Type const &
211 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::Type const *)
213 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE);
216 inline css::uno::Type const &
217 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::Any const *)
219 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY);
222 template< typename T > inline css::uno::Type const &
223 cppu_detail_getUnoType(
224 SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType< T > const *)
226 //TODO: depending on memory model, the following might not work reliably
227 static typelib_TypeDescriptionReference * p = NULL;
228 if (p == NULL) {
229 ::typelib_static_sequence_type_init(
230 &p, ::cppu::UnoType< T >::get().getTypeLibType());
232 return ::cppu::detail::getTypeFromTypeDescriptionReference(&p);
235 template< typename T > inline css::uno::Type const &
236 cppu_detail_getUnoType(
237 SAL_UNUSED_PARAMETER css::uno::Sequence< T > const *)
239 return cppu_detail_getUnoType(
240 static_cast< ::cppu::UnoSequenceType< T > * >(0));
243 inline css::uno::Type const & cppu_detail_getUnoType(
244 SAL_UNUSED_PARAMETER css::uno::Exception const *)
246 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION);
249 inline css::uno::Type const & cppu_detail_getUnoType(
250 SAL_UNUSED_PARAMETER css::uno::XInterface const *)
252 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE);
255 template< typename T > inline css::uno::Type const &
256 cppu_detail_getUnoType(
257 SAL_UNUSED_PARAMETER css::uno::Reference< T > const *)
259 return ::cppu::UnoType< T >::get();
264 namespace cppu {
267 Get the css::uno::Type instance representing a certain UNO type.
269 For each C++ type representing a UNO type, the corresponding instantiation of
270 this template has a public static member function get(). (The template is
271 specialized for C++ templates representing polymorphic struct type templates
272 of UNO. In those cases, it does not work to instantiate UnoType with a C++
273 type that is derived from a C++ type that represents a UNO type, but does not
274 itself represent a UNO type. In all other cases, UnoType even works for such
275 C++ types that are unambiguously derived from one C++ type that represents a
276 UNO type.) In addition to those C++ types that are mappings of UNO types
277 (except for sal_uInt16 and sal_Unicode, see below), the following C++ types
278 are appropriate as template arguments: void, cppu::UnoVoidType, bool,
279 cppu::UnoUnsignedShortType, cppu::UnoCharType, cppu::UnoSequenceType with any
280 appropriate template argument (the latter three to unambiguously specify UNO
281 types, as the UNO types UNSIGNED SHORT and CHAR map to the same C++ type),
282 and css::uno::Reference with any appropriate template argument.
284 @since UDK 3.2.2
286 template< typename T > class UnoType {
287 public:
288 static css::uno::Type const & get() {
289 using namespace ::cppu::detail;
290 #if defined LIBO_INTERNAL_ONLY
291 typedef typename std::remove_reference<T>::type T1;
292 // for certain uses of UnoType<decltype(x)>
293 #else
294 typedef T T1;
295 #endif
296 return cppu_detail_getUnoType(static_cast< T1 * >(0));
299 private:
300 UnoType(UnoType &) SAL_DELETED_FUNCTION;
301 ~UnoType() SAL_DELETED_FUNCTION;
302 void operator =(UnoType &) SAL_DELETED_FUNCTION;
305 template<> css::uno::Type inline const & UnoType<void>::get() {
306 return cppu::UnoType<cppu::UnoVoidType>::get();
310 A working replacement for getCppuType (see there).
312 There are three overloads of this function that together form the replacement
313 of getCppuType. The replacement has exactly the same semantics as
314 getCppuType, in that it returns correct results for the UNO type UNSIGNED
315 SHORT but not for the UNO type CHAR.
317 @since UDK 3.2.2
319 template< typename T > inline css::uno::Type const &
320 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *) {
321 return ::cppu::UnoType< T >::get();
325 A working replacement for getCppuType (see there).
327 There are three overloads of this function that together form the replacement
328 of getCppuType. The replacement has exactly the same semantics as
329 getCppuType, in that it returns correct results for the UNO type UNSIGNED
330 SHORT but not for the UNO type CHAR.
332 @since UDK 3.2.2
334 inline css::uno::Type const &
335 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16 const *) {
336 return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get();
340 A working replacement for getCppuType (see there).
342 There are three overloads of this function that together form the replacement
343 of getCppuType. The replacement has exactly the same semantics as
344 getCppuType, in that it returns correct results for the UNO type UNSIGNED
345 SHORT but not for the UNO type CHAR.
347 @since UDK 3.2.2
349 template< typename T > inline css::uno::Type const &
350 getTypeFavourUnsigned(css::uno::Sequence< T > const *);
351 // defined in com/sun/star/uno/Sequence.hxx
353 /// @cond INTERNAL
356 A working replacement for getCppuType (see there).
358 There are three overloads of this function that together form the replacement
359 of the getCppuType template. The replacement has exactly the same semantics
360 as the getCppuType template, in that it returns correct results for the UNO
361 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
362 returns the intended results for sequence types.
364 @since UDK 3.2.3
366 template< typename T > inline css::uno::Type const &
367 getTypeFavourChar(SAL_UNUSED_PARAMETER T const *) {
368 return ::cppu::UnoType< T >::get();
372 A working replacement for getCppuType (see there).
374 There are three overloads of this function that together form the replacement
375 of the getCppuType template. The replacement has exactly the same semantics
376 as the getCppuType template, in that it returns correct results for the UNO
377 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
378 returns the intended results for sequence types.
380 @since UDK 3.2.3
382 inline css::uno::Type const &
383 getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode const *) {
384 return ::cppu::UnoType< ::cppu::UnoCharType >::get();
388 A working replacement for getCppuType (see there).
390 There are three overloads of this function that together form the replacement
391 of the getCppuType template. The replacement has exactly the same semantics
392 as the getCppuType template, in that it returns correct results for the UNO
393 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
394 returns the intended results for sequence types.
396 @since UDK 3.2.3
398 template< typename T > inline css::uno::Type const &
399 getTypeFavourChar(css::uno::Sequence< T > const *);
400 // defined in com/sun/star/uno/Sequence.hxx
402 /// @endcond
406 #endif
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */