Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_CPPU_UNOTYPE_HXX
21 : #define INCLUDED_CPPU_UNOTYPE_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #if defined LIBO_INTERNAL_ONLY
26 : #include <type_traits>
27 : #endif
28 :
29 : #include <sal/types.h>
30 : #include <typelib/typeclass.h>
31 : #include <typelib/typedescription.h>
32 :
33 : namespace com { namespace sun { namespace star { namespace uno {
34 : class Type;
35 : class Any;
36 : class Exception;
37 : template< typename > class Reference;
38 : template< typename > class Sequence;
39 : class XInterface;
40 : } } } }
41 : namespace rtl { class OUString; }
42 :
43 : namespace cppu {
44 :
45 : template< typename > class UnoType;
46 :
47 : /**
48 : A unique C++ type representing the UNO type VOID in cppu::UnoType.
49 :
50 : This type is declared but not defined. Its only use is as a template
51 : argument to cppu::UnoType.
52 :
53 : @since UDK 3.2.2
54 : */
55 : struct UnoVoidType;
56 :
57 : /**
58 : A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType.
59 :
60 : The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
61 : type is needed to unambiguously specify UNO types in cppu::UnoType.
62 :
63 : This type is declared but not defined. Its only use is as a template
64 : argument to cppu::UnoType.
65 :
66 : @since UDK 3.2.2
67 : */
68 : struct UnoUnsignedShortType;
69 :
70 : /**
71 : A unique C++ type representing the UNO type CHAR in cppu::UnoType.
72 :
73 : The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
74 : type is needed to unambiguously specify UNO types in cppu::UnoType.
75 :
76 : This type is declared but not defined. Its only use is as a template
77 : argument to cppu::UnoType.
78 :
79 : @since UDK 3.2.2
80 : */
81 : struct UnoCharType;
82 :
83 : /**
84 : A unique C++ type template representing the UNO sequence types in
85 : cppu::UnoType.
86 :
87 : The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
88 : type is needed to unambiguously specify UNO types in cppu::UnoType.
89 :
90 : This type is declared but not defined. Its only use is as a template
91 : argument to cppu::UnoType.
92 :
93 : @since UDK 3.2.2
94 : */
95 : template< typename > struct UnoSequenceType;
96 :
97 : namespace detail {
98 :
99 1387448216 : inline ::com::sun::star::uno::Type const & getTypeFromTypeDescriptionReference(
100 : ::typelib_TypeDescriptionReference * const * tdr)
101 : {
102 1387448216 : return *reinterpret_cast< ::com::sun::star::uno::Type const * >(tdr);
103 : }
104 :
105 : inline ::com::sun::star::uno::Type const &
106 428251640 : getTypeFromTypeClass(::typelib_TypeClass tc) {
107 : return getTypeFromTypeDescriptionReference(
108 428251640 : ::typelib_static_type_getByTypeClass(tc));
109 : }
110 :
111 : }
112 :
113 : }
114 :
115 : namespace cppu { namespace detail {
116 :
117 : inline ::com::sun::star::uno::Type const &
118 274716 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *) {
119 274716 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID);
120 : }
121 :
122 : inline ::com::sun::star::uno::Type const &
123 200696324 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER bool const *) {
124 200696324 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
125 : }
126 :
127 : inline ::com::sun::star::uno::Type const &
128 866940 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Bool const *) {
129 866940 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
130 : }
131 :
132 : inline ::com::sun::star::uno::Type const &
133 24576 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8 const *) {
134 24576 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE);
135 : }
136 :
137 : inline ::com::sun::star::uno::Type const &
138 1239823 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16 const *) {
139 1239823 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT);
140 : }
141 :
142 : inline ::com::sun::star::uno::Type const &
143 97764 : cppu_detail_getUnoType(
144 : SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType const *)
145 : {
146 : return ::cppu::detail::getTypeFromTypeClass(
147 97764 : ::typelib_TypeClass_UNSIGNED_SHORT);
148 : }
149 :
150 : inline ::com::sun::star::uno::Type const &
151 2631261 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) {
152 2631261 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG);
153 : }
154 :
155 : inline ::com::sun::star::uno::Type const &
156 153613 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt32 const *) {
157 : return ::cppu::detail::getTypeFromTypeClass(
158 153613 : ::typelib_TypeClass_UNSIGNED_LONG);
159 : }
160 :
161 : inline ::com::sun::star::uno::Type const &
162 167436 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64 const *) {
163 167436 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER);
164 : }
165 :
166 : inline ::com::sun::star::uno::Type const &
167 18106 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt64 const *) {
168 : return ::cppu::detail::getTypeFromTypeClass(
169 18106 : ::typelib_TypeClass_UNSIGNED_HYPER);
170 : }
171 :
172 : inline ::com::sun::star::uno::Type const &
173 121058 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER float const *) {
174 121058 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT);
175 : }
176 :
177 : inline ::com::sun::star::uno::Type const &
178 1340750 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER double const *) {
179 1340750 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE);
180 : }
181 :
182 : inline ::com::sun::star::uno::Type const &
183 35 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) {
184 35 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR);
185 : }
186 :
187 : inline ::com::sun::star::uno::Type const &
188 34300007 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) {
189 34300007 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING);
190 : }
191 :
192 : inline ::com::sun::star::uno::Type const &
193 651 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Type const *)
194 : {
195 651 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE);
196 : }
197 :
198 : inline ::com::sun::star::uno::Type const &
199 5211752 : cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Any const *)
200 : {
201 5211752 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY);
202 : }
203 :
204 : template< typename T > inline ::com::sun::star::uno::Type const &
205 427985 : cppu_detail_getUnoType(
206 : SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType< T > const *)
207 : {
208 : //TODO: depending on memory model, the following might not work reliably
209 : static typelib_TypeDescriptionReference * p = 0;
210 427985 : if (p == 0) {
211 3276 : ::typelib_static_sequence_type_init(
212 3276 : &p, ::cppu::UnoType< T >::get().getTypeLibType());
213 : }
214 427985 : return ::cppu::detail::getTypeFromTypeDescriptionReference(&p);
215 : }
216 :
217 : template< typename T > inline ::com::sun::star::uno::Type const &
218 425532 : cppu_detail_getUnoType(
219 : SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
220 : {
221 : return cppu_detail_getUnoType(
222 425532 : static_cast< ::cppu::UnoSequenceType< T > * >(0));
223 : }
224 :
225 45883 : inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType(
226 : SAL_UNUSED_PARAMETER ::com::sun::star::uno::Exception const *)
227 : {
228 45883 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION);
229 : }
230 :
231 181060945 : inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType(
232 : SAL_UNUSED_PARAMETER ::com::sun::star::uno::XInterface const *)
233 : {
234 181060945 : return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE);
235 : }
236 :
237 : template< typename T > inline ::com::sun::star::uno::Type const &
238 310286464 : cppu_detail_getUnoType(
239 : SAL_UNUSED_PARAMETER ::com::sun::star::uno::Reference< T > const *)
240 : {
241 310286464 : return ::cppu::UnoType< T >::get();
242 : }
243 :
244 : } }
245 :
246 : namespace cppu {
247 :
248 : /**
249 : Get the com::sun::star::uno::Type instance representing a certain UNO type.
250 :
251 : For each C++ type representing a UNO type, the corresponding instantiation of
252 : this template has a public static member function get(). (The template is
253 : specialized for C++ templates representing polymorphic struct type templates
254 : of UNO. In those cases, it does not work to instantiate UnoType with a C++
255 : type that is derived from a C++ type that represents a UNO type, but does not
256 : itself represent a UNO type. In all other cases, UnoType even works for such
257 : C++ types that are unambiguously derived from one C++ type that represents a
258 : UNO type.) In addition to those C++ types that are mappings of UNO types
259 : (except for sal_uInt16 and sal_Unicode, see below), the following C++ types
260 : are appropriate as template arguments: void, cppu::UnoVoidType, bool,
261 : cppu::UnoUnsignedShortType, cppu::UnoCharType, cppu::UnoSequenceType with any
262 : appropriate template argument (the latter three to unambiguously specify UNO
263 : types, as the UNO types UNSIGNED SHORT and CHAR map to the same C++ type),
264 : and com::sun::star::uno::Reference with any appropriate template argument.
265 :
266 : @since UDK 3.2.2
267 : */
268 : template< typename T > class UnoType {
269 : public:
270 4702610831 : static inline ::com::sun::star::uno::Type const & get() {
271 : using namespace ::cppu::detail;
272 : #if defined LIBO_INTERNAL_ONLY
273 : typedef typename std::remove_reference<T>::type T1;
274 : // for certain uses of UnoType<decltype(x)>
275 : #else
276 : typedef T T1;
277 : #endif
278 4702610831 : return cppu_detail_getUnoType(static_cast< T1 * >(0));
279 : }
280 :
281 : private:
282 : UnoType(UnoType &) SAL_DELETED_FUNCTION;
283 : ~UnoType() SAL_DELETED_FUNCTION;
284 : void operator =(UnoType &) SAL_DELETED_FUNCTION;
285 : };
286 :
287 274711 : template<> css::uno::Type inline const & UnoType<void>::get() {
288 274711 : return cppu::UnoType<cppu::UnoVoidType>::get();
289 : }
290 :
291 : /**
292 : A working replacement for getCppuType (see there).
293 :
294 : There are three overloads of this function that together form the replacement
295 : of getCppuType. The replacement has exactly the same semantics as
296 : getCppuType, in that it returns correct results for the UNO type UNSIGNED
297 : SHORT but not for the UNO type CHAR.
298 :
299 : @since UDK 3.2.2
300 : */
301 : template< typename T > inline ::com::sun::star::uno::Type const &
302 440068583 : getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *) {
303 440068583 : return ::cppu::UnoType< T >::get();
304 : }
305 :
306 : /**
307 : A working replacement for getCppuType (see there).
308 :
309 : There are three overloads of this function that together form the replacement
310 : of getCppuType. The replacement has exactly the same semantics as
311 : getCppuType, in that it returns correct results for the UNO type UNSIGNED
312 : SHORT but not for the UNO type CHAR.
313 :
314 : @since UDK 3.2.2
315 : */
316 : inline ::com::sun::star::uno::Type const &
317 72563 : getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16 const *) {
318 72563 : return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get();
319 : }
320 :
321 : /**
322 : A working replacement for getCppuType (see there).
323 :
324 : There are three overloads of this function that together form the replacement
325 : of getCppuType. The replacement has exactly the same semantics as
326 : getCppuType, in that it returns correct results for the UNO type UNSIGNED
327 : SHORT but not for the UNO type CHAR.
328 :
329 : @since UDK 3.2.2
330 : */
331 : template< typename T > inline ::com::sun::star::uno::Type const &
332 : getTypeFavourUnsigned(::com::sun::star::uno::Sequence< T > const *);
333 : // defined in com/sun/star/uno/Sequence.hxx
334 :
335 : /// @cond INTERNAL
336 :
337 : /**
338 : A working replacement for getCppuType (see there).
339 :
340 : There are three overloads of this function that together form the replacement
341 : of the getCppuType template. The replacement has exactly the same semantics
342 : as the getCppuType template, in that it returns correct results for the UNO
343 : type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
344 : returns the intended results for sequence types.
345 :
346 : @since UDK 3.2.3
347 : */
348 : template< typename T > inline ::com::sun::star::uno::Type const &
349 571 : getTypeFavourChar(SAL_UNUSED_PARAMETER T const *) {
350 571 : return ::cppu::UnoType< T >::get();
351 : }
352 :
353 : /**
354 : A working replacement for getCppuType (see there).
355 :
356 : There are three overloads of this function that together form the replacement
357 : of the getCppuType template. The replacement has exactly the same semantics
358 : as the getCppuType template, in that it returns correct results for the UNO
359 : type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
360 : returns the intended results for sequence types.
361 :
362 : @since UDK 3.2.3
363 : */
364 : inline ::com::sun::star::uno::Type const &
365 16 : getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode const *) {
366 16 : return ::cppu::UnoType< ::cppu::UnoCharType >::get();
367 : }
368 :
369 : /**
370 : A working replacement for getCppuType (see there).
371 :
372 : There are three overloads of this function that together form the replacement
373 : of the getCppuType template. The replacement has exactly the same semantics
374 : as the getCppuType template, in that it returns correct results for the UNO
375 : type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
376 : returns the intended results for sequence types.
377 :
378 : @since UDK 3.2.3
379 : */
380 : template< typename T > inline ::com::sun::star::uno::Type const &
381 : getTypeFavourChar(::com::sun::star::uno::Sequence< T > const *);
382 : // defined in com/sun/star/uno/Sequence.hxx
383 :
384 : /// @endcond
385 :
386 : }
387 :
388 : #endif
389 :
390 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|