LibreOffice: cppu/unotype.hxx Source File

LibreOffice LibreOffice 6.4 SDK C/C++ API Reference

unotype.hxx
Go to the documentation of this file.
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 #include <cstddef>
26
27 #if defined LIBO_INTERNAL_ONLY
28 #include <type_traits>
29 #endif
30
31 #include "sal/types.h"
32 #include "typelib/typeclass.h"
33 #include "typelib/typedescription.h"
34
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; }
44
45 namespace cppu {
46
47 template< typename > class UnoType;
48
57 struct UnoVoidType;
58
70 struct UnoUnsignedShortType;
71
83 struct UnoCharType;
84
97 template< typename > struct UnoSequenceType;
98
99 namespace detail {
100
101 inline css::uno::Type const & getTypeFromTypeDescriptionReference(
102 ::typelib_TypeDescriptionReference * const * tdr)
103 {
104 return *reinterpret_cast< css::uno::Type const * >(tdr);
105 }
106
107 inline css::uno::Type const &
108 getTypeFromTypeClass(::typelib_TypeClass tc) {
109 return getTypeFromTypeDescriptionReference(
110 ::typelib_static_type_getByTypeClass(tc));
111 }
112
113 }
114
115 }
116
117 namespace cppu { namespace detail {
118
119 inline css::uno::Type const &
120 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *) {
121 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID);
122 }
123
124 inline css::uno::Type const &
125 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER bool const *) {
126 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
127 }
128
129 inline css::uno::Type const &
130 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Bool const *) {
131 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
132 }
133
134 inline css::uno::Type const &
135 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8 const *) {
136 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE);
137 }
138
139 inline css::uno::Type const &
140 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16 const *) {
141 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT);
142 }
143
144 inline css::uno::Type const &
145 cppu_detail_getUnoType(
146 SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType const *)
147 {
148 return ::cppu::detail::getTypeFromTypeClass(
149 ::typelib_TypeClass_UNSIGNED_SHORT);
150 }
151
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);
157 }
158 #endif
159
160 inline css::uno::Type const &
161 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) {
162 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG);
163 }
164
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);
169 }
170
171 inline css::uno::Type const &
172 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64 const *) {
173 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER);
174 }
175
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);
180 }
181
182 inline css::uno::Type const &
183 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER float const *) {
184 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT);
185 }
186
187 inline css::uno::Type const &
188 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER double const *) {
189 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE);
190 }
191
192 inline css::uno::Type const &
193 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) {
194 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR);
195 }
196
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);
202 }
203 #endif
204
205 inline css::uno::Type const &
206 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) {
207 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING);
208 }
209
210 inline css::uno::Type const &
211 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::Type const *)
212 {
213 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE);
214 }
215
216 inline css::uno::Type const &
217 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::Any const *)
218 {
219 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY);
220 }
221
222 template< typename T > inline css::uno::Type const &
223 cppu_detail_getUnoType(
224 SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType< T > const *)
225 {
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());
231 }
232 return ::cppu::detail::getTypeFromTypeDescriptionReference(&p);
233 }
234
235 template< typename T > inline css::uno::Type const &
236 cppu_detail_getUnoType(
237 SAL_UNUSED_PARAMETER css::uno::Sequence< T > const *)
238 {
239 return cppu_detail_getUnoType(
240 static_cast< ::cppu::UnoSequenceType< T > * >(0));
241 }
242
243 inline css::uno::Type const & cppu_detail_getUnoType(
244 SAL_UNUSED_PARAMETER css::uno::Exception const *)
245 {
246 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION);
247 }
248
249 inline css::uno::Type const & cppu_detail_getUnoType(
250 SAL_UNUSED_PARAMETER css::uno::XInterface const *)
251 {
252 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE);
253 }
254
255 template< typename T > inline css::uno::Type const &
256 cppu_detail_getUnoType(
257 SAL_UNUSED_PARAMETER css::uno::Reference< T > const *)
258 {
259 return ::cppu::UnoType< T >::get();
260 }
261
262 } }
263
264 namespace cppu {
265
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));
297 }
298
299 private:
300 UnoType(UnoType &) SAL_DELETED_FUNCTION;
301 ~UnoType() SAL_DELETED_FUNCTION;
302 void operator =(UnoType &) SAL_DELETED_FUNCTION;
303 };
304
305 template<> css::uno::Type inline const & UnoType<void>::get() {
306 return cppu::UnoType<cppu::UnoVoidType>::get();
307 }
308
319 template< typename T > inline css::uno::Type const &
320 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *) {
321 return ::cppu::UnoType< T >::get();
322 }
323
334 inline css::uno::Type const &
335 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16 const *) {
336 return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get();
337 }
338
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
352
354
366 template< typename T > inline css::uno::Type const &
367 getTypeFavourChar(SAL_UNUSED_PARAMETER T const *) {
368 return ::cppu::UnoType< T >::get();
369 }
370
382 inline css::uno::Type const &
383 getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode const *) {
384 return ::cppu::UnoType< ::cppu::UnoCharType >::get();
385 }
386
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
401
403
404 }
405
406 #endif
407
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star
Definition: types.h:377
typelib_static_sequence_type_init
CPPU_DLLPUBLIC void typelib_static_sequence_type_init(typelib_TypeDescriptionReference **ppRef, typelib_TypeDescriptionReference *pElementType) SAL_THROW_EXTERN_C()
Inits static sequence type reference.
SAL_UNUSED_PARAMETER
#define SAL_UNUSED_PARAMETER
Annotate unused but required C++ function parameters.
Definition: types.h:559
typelib_TypeClass_SHORT
@ typelib_TypeClass_SHORT
type class of short
Definition: typeclass.h:37
typelib_TypeClass_UNSIGNED_HYPER
@ typelib_TypeClass_UNSIGNED_HYPER
type class of unsigned hyper
Definition: typeclass.h:47
cppu::UnoType::get
static css::uno::Type const & get()
Definition: unotype.hxx:288
cppu::getTypeFavourUnsigned
css::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:320
cppu
Definition: Enterable.hxx:27
typelib_TypeClass_LONG
@ typelib_TypeClass_LONG
type class of long
Definition: typeclass.h:41
typelib_TypeClass_EXCEPTION
@ typelib_TypeClass_EXCEPTION
type class of exception
Definition: typeclass.h:70
com::sun::star::uno::Sequence
Template C++ class representing an IDL sequence.
Definition: unotype.hxx:40
typelib_TypeClass_VOID
@ typelib_TypeClass_VOID
type class of void
Definition: typeclass.h:29
typelib_TypeClass_UNSIGNED_LONG
@ typelib_TypeClass_UNSIGNED_LONG
type class of unsigned long
Definition: typeclass.h:43
typelib_TypeClass_DOUBLE
@ typelib_TypeClass_DOUBLE
type class of double
Definition: typeclass.h:51
typelib_TypeClass_ANY
@ typelib_TypeClass_ANY
type class of any
Definition: typeclass.h:57
cppu::detail::getTypeFromTypeClass
css::uno::Type const & getTypeFromTypeClass(::typelib_TypeClass tc)
Definition: unotype.hxx:108
typelib_TypeClass_FLOAT
@ typelib_TypeClass_FLOAT
type class of float
Definition: typeclass.h:49
sal_Bool
unsigned char sal_Bool
Definition: types.h:38
config.h
typelib_TypeClass
enum _typelib_TypeClass typelib_TypeClass
This type class enum is binary compatible with the IDL enum com.sun.star.uno.TypeClass.
typelib_TypeClass_BOOLEAN
@ typelib_TypeClass_BOOLEAN
type class of boolean
Definition: typeclass.h:33
typelib_static_type_getByTypeClass
CPPU_DLLPUBLIC typelib_TypeDescriptionReference ** typelib_static_type_getByTypeClass(typelib_TypeClass eTypeClass) SAL_THROW_EXTERN_C()
Gets static type reference of standard types by type class.
cppu::UnoSequenceType
A unique C++ type template representing the UNO sequence types in cppu::UnoType.
Definition: unotype.hxx:97
types.h
typelib_TypeClass_INTERFACE
@ typelib_TypeClass_INTERFACE
type class of interface
Definition: typeclass.h:79
rtl
Definition: bootstrap.hxx:30
com
Definition: types.h:377
typelib_TypeClass_TYPE
@ typelib_TypeClass_TYPE
type class of type
Definition: typeclass.h:55
cppu::UnoType
Get the css::uno::Type instance representing a certain UNO type.
Definition: unotype.hxx:47
typelib_TypeClass_HYPER
@ typelib_TypeClass_HYPER
type class of hyper
Definition: typeclass.h:45
cppu::getTypeFavourChar
::com::sun::star::uno::Type const & getTypeFavourChar(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
Definition: Sequence.hxx:308
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:39
sal_Unicode
sal_uInt16 sal_Unicode
Definition: types.h:141
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
typelib_TypeClass_UNSIGNED_SHORT
@ typelib_TypeClass_UNSIGNED_SHORT
type class of unsigned short
Definition: typeclass.h:39
cppu::detail
Definition: unotype.hxx:99
typelib_TypeClass_BYTE
@ typelib_TypeClass_BYTE
type class of byte
Definition: typeclass.h:35
typelib_TypeClass_STRING
@ typelib_TypeClass_STRING
type class of string
Definition: typeclass.h:53
typelib_TypeDescriptionReference
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
typelib_TypeClass_CHAR
@ typelib_TypeClass_CHAR
type class of char
Definition: typeclass.h:31
typeclass.h
sal_Int8
signed char sal_Int8
Definition: types.h:43
cppu::detail::cppu_detail_getUnoType
css::uno::Type const & cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *)
Definition: unotype.hxx:120
cppu::detail::cppu_detail_getUnoType
css::uno::Type const & cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::Reference< T > const *)
Definition: unotype.hxx:256
typedescription.h
cppu::detail::getTypeFromTypeDescriptionReference
css::uno::Type const & getTypeFromTypeDescriptionReference(::typelib_TypeDescriptionReference *const *tdr)
Definition: unotype.hxx:101