bump product version to 4.1.6.2
[LibreOffice.git] / include / cppu / unotype.hxx
blob2861bdb2c9227f637be199c686642b7007f7575b
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"
24 #include "com/sun/star/uno/Type.h"
25 #include "sal/types.h"
26 #include "typelib/typeclass.h"
27 #include "typelib/typedescription.h"
29 namespace com { namespace sun { namespace star { namespace uno {
30 class Any;
31 class Exception;
32 template< typename > class Reference;
33 template< typename > class Sequence;
34 class XInterface;
35 } } } }
36 namespace rtl { class OUString; }
38 namespace cppu {
40 template< typename > class UnoType;
42 /**
43 A unique C++ type representing the UNO type VOID in cppu::UnoType.
45 This type is declared but not defined. Its only use is as a template
46 argument to cppu::UnoType.
48 @since UDK 3.2.2
50 struct UnoVoidType;
52 /**
53 A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType.
55 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
56 type is needed to unambiguously specify UNO types in cppu::UnoType.
58 This type is declared but not defined. Its only use is as a template
59 argument to cppu::UnoType.
61 @since UDK 3.2.2
63 struct UnoUnsignedShortType;
65 /**
66 A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType.
68 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
69 type is needed to unambiguously specify UNO types in cppu::UnoType.
71 This type is declared but not defined. Its only use is as a template
72 argument to cppu::UnoType.
74 @since UDK 3.2.2
76 struct UnoCharType;
78 /**
79 A unique C++ type template representing the UNO sequence types in
80 cppu::UnoType.
82 The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++
83 type is needed to unambiguously specify UNO types in cppu::UnoType.
85 This type is declared but not defined. Its only use is as a template
86 argument to cppu::UnoType.
88 @since UDK 3.2.2
90 template< typename > struct UnoSequenceType;
92 namespace detail {
94 inline ::com::sun::star::uno::Type const & getTypeFromTypeDescriptionReference(
95 ::typelib_TypeDescriptionReference * const * tdr)
97 return *reinterpret_cast< ::com::sun::star::uno::Type const * >(tdr);
100 inline ::com::sun::star::uno::Type const &
101 getTypeFromTypeClass(::typelib_TypeClass tc) {
102 return getTypeFromTypeDescriptionReference(
103 ::typelib_static_type_getByTypeClass(tc));
110 namespace cppu { namespace detail {
112 inline ::com::sun::star::uno::Type const &
113 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *) {
114 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID);
117 inline ::com::sun::star::uno::Type const &
118 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER bool const *) {
119 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
122 inline ::com::sun::star::uno::Type const &
123 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Bool const *) {
124 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN);
127 inline ::com::sun::star::uno::Type const &
128 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8 const *) {
129 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE);
132 inline ::com::sun::star::uno::Type const &
133 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16 const *) {
134 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT);
137 inline ::com::sun::star::uno::Type const &
138 cppu_detail_getUnoType(
139 SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType const *)
141 return ::cppu::detail::getTypeFromTypeClass(
142 ::typelib_TypeClass_UNSIGNED_SHORT);
145 inline ::com::sun::star::uno::Type const &
146 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) {
147 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG);
150 inline ::com::sun::star::uno::Type const &
151 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt32 const *) {
152 return ::cppu::detail::getTypeFromTypeClass(
153 ::typelib_TypeClass_UNSIGNED_LONG);
156 inline ::com::sun::star::uno::Type const &
157 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64 const *) {
158 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER);
161 inline ::com::sun::star::uno::Type const &
162 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt64 const *) {
163 return ::cppu::detail::getTypeFromTypeClass(
164 ::typelib_TypeClass_UNSIGNED_HYPER);
167 inline ::com::sun::star::uno::Type const &
168 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER float const *) {
169 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT);
172 inline ::com::sun::star::uno::Type const &
173 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER double const *) {
174 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE);
177 inline ::com::sun::star::uno::Type const &
178 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) {
179 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR);
182 inline ::com::sun::star::uno::Type const &
183 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) {
184 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING);
187 inline ::com::sun::star::uno::Type const &
188 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Type const *)
190 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE);
193 inline ::com::sun::star::uno::Type const &
194 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Any const *)
196 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY);
199 template< typename T > inline ::com::sun::star::uno::Type const &
200 cppu_detail_getUnoType(
201 SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType< T > const *)
203 //TODO: depending on memory model, the following might not work reliably
204 static typelib_TypeDescriptionReference * p = 0;
205 if (p == 0) {
206 ::typelib_static_sequence_type_init(
207 &p, ::cppu::UnoType< T >::get().getTypeLibType());
209 return ::cppu::detail::getTypeFromTypeDescriptionReference(&p);
212 template< typename T > inline ::com::sun::star::uno::Type const &
213 cppu_detail_getUnoType(
214 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
216 return cppu_detail_getUnoType(
217 static_cast< ::cppu::UnoSequenceType< T > * >(0));
220 inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType(
221 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Exception const *)
223 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION);
226 inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType(
227 SAL_UNUSED_PARAMETER ::com::sun::star::uno::XInterface const *)
229 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE);
232 template< typename T > inline ::com::sun::star::uno::Type const &
233 cppu_detail_getUnoType(
234 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Reference< T > const *)
236 return ::cppu::UnoType< T >::get();
241 namespace cppu {
244 Get the com::sun::star::uno::Type instance representing a certain UNO type.
246 For each C++ type representing a UNO type, the corresponding instantiation of
247 this template has a public static member function get(). (The template is
248 specialized for C++ templates representing polymorphic struct type templates
249 of UNO. In those cases, it does not work to instantiate UnoType with a C++
250 type that is derived from a C++ type that represents a UNO type, but does not
251 itself represent a UNO type. In all other cases, UnoType even works for such
252 C++ types that are unambiguously derived from one C++ type that represents a
253 UNO type.) In addition to those C++ types that are mappings of UNO types
254 (except for sal_uInt16 and sal_Unicode, see below), the following C++ types
255 are appropriate as template arguments: cppu::UnoVoidType, bool,
256 cppu::UnoUnsignedShortType, cppu::UnoCharType, cppu::UnoSequenceType with any
257 appropriate template argument (the latter three to unambiguously specify UNO
258 types, as the UNO types UNSIGNED SHORT and CHAR map to the same C++ type),
259 and com::sun::star::uno::Reference with any appropriate template argument.
261 @since UDK 3.2.2
263 template< typename T > class UnoType {
264 public:
265 static inline ::com::sun::star::uno::Type const & get() {
266 using namespace ::cppu::detail;
267 return cppu_detail_getUnoType(static_cast< T * >(0));
270 private:
271 UnoType(UnoType &); // not defined
272 ~UnoType(); // not defined
273 void operator =(UnoType &); // not defined
277 A working replacement for getCppuType (see there).
279 There are three overloads of this function that together form the replacement
280 of getCppuType. The replacement has exactly the same semantics as
281 getCppuType, in that it returns correct results for the UNO type UNSIGNED
282 SHORT but not for the UNO type CHAR.
284 @since UDK 3.2.2
286 template< typename T > inline ::com::sun::star::uno::Type const &
287 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *) {
288 return ::cppu::UnoType< T >::get();
292 A working replacement for getCppuType (see there).
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.
299 @since UDK 3.2.2
301 inline ::com::sun::star::uno::Type const &
302 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16 const *) {
303 return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get();
307 A working replacement for getCppuType (see there).
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.
314 @since UDK 3.2.2
316 template< typename T > inline ::com::sun::star::uno::Type const &
317 getTypeFavourUnsigned(::com::sun::star::uno::Sequence< T > const *);
318 // defined in com/sun/star/uno/Sequence.hxx
320 /// @cond INTERNAL
323 A working replacement for getCppuType (see there).
325 There are three overloads of this function that together form the replacement
326 of the getCppuType template. The replacement has exactly the same semantics
327 as the getCppuType template, in that it returns correct results for the UNO
328 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
329 returns the intended results for sequence types.
331 @since UDK 3.2.3
333 template< typename T > inline ::com::sun::star::uno::Type const &
334 getTypeFavourChar(SAL_UNUSED_PARAMETER T const *) {
335 return ::cppu::UnoType< T >::get();
339 A working replacement for getCppuType (see there).
341 There are three overloads of this function that together form the replacement
342 of the getCppuType template. The replacement has exactly the same semantics
343 as the getCppuType template, in that it returns correct results for the UNO
344 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
345 returns the intended results for sequence types.
347 @since UDK 3.2.3
349 inline ::com::sun::star::uno::Type const &
350 getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode const *) {
351 return ::cppu::UnoType< ::cppu::UnoCharType >::get();
355 A working replacement for getCppuType (see there).
357 There are three overloads of this function that together form the replacement
358 of the getCppuType template. The replacement has exactly the same semantics
359 as the getCppuType template, in that it returns correct results for the UNO
360 type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also
361 returns the intended results for sequence types.
363 @since UDK 3.2.3
365 template< typename T > inline ::com::sun::star::uno::Type const &
366 getTypeFavourChar(::com::sun::star::uno::Sequence< T > const *);
367 // defined in com/sun/star/uno/Sequence.hxx
369 /// @endcond
373 #endif
375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */