00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /* 00003 * This file is part of the LibreOffice project. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this 00007 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 00008 * 00009 * This file incorporates work covered by the following license notice: 00010 * 00011 * Licensed to the Apache Software Foundation (ASF) under one or more 00012 * contributor license agreements. See the NOTICE file distributed 00013 * with this work for additional information regarding copyright 00014 * ownership. The ASF licenses this file to you under the Apache 00015 * License, Version 2.0 (the "License"); you may not use this file 00016 * except in compliance with the License. You may obtain a copy of 00017 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 00018 */ 00019 00020 #ifndef INCLUDED_CPPU_UNOTYPE_HXX 00021 #define INCLUDED_CPPU_UNOTYPE_HXX 00022 00023 #include "sal/config.h" 00024 #include "com/sun/star/uno/Type.h" 00025 #include "sal/types.h" 00026 #include "typelib/typeclass.h" 00027 #include "typelib/typedescription.h" 00028 00029 namespace com { namespace sun { namespace star { namespace uno { 00030 class Any; 00031 class Exception; 00032 template< typename > class Reference; 00033 template< typename > class Sequence; 00034 class XInterface; 00035 } } } } 00036 namespace rtl { class OUString; } 00037 00038 namespace cppu { 00039 00040 template< typename > class UnoType; 00041 00050 struct UnoVoidType; 00051 00063 struct UnoUnsignedShortType; 00064 00076 struct UnoCharType; 00077 00090 template< typename > struct UnoSequenceType; 00091 00092 namespace detail { 00093 00094 inline ::com::sun::star::uno::Type const & getTypeFromTypeDescriptionReference( 00095 ::typelib_TypeDescriptionReference * const * tdr) 00096 { 00097 return *reinterpret_cast< ::com::sun::star::uno::Type const * >(tdr); 00098 } 00099 00100 inline ::com::sun::star::uno::Type const & 00101 getTypeFromTypeClass(::typelib_TypeClass tc) { 00102 return getTypeFromTypeDescriptionReference( 00103 ::typelib_static_type_getByTypeClass(tc)); 00104 } 00105 00106 } 00107 00108 } 00109 00110 namespace cppu { namespace detail { 00111 00112 inline ::com::sun::star::uno::Type const & 00113 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *) { 00114 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID); 00115 } 00116 00117 inline ::com::sun::star::uno::Type const & 00118 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER bool const *) { 00119 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN); 00120 } 00121 00122 inline ::com::sun::star::uno::Type const & 00123 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Bool const *) { 00124 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN); 00125 } 00126 00127 inline ::com::sun::star::uno::Type const & 00128 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8 const *) { 00129 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE); 00130 } 00131 00132 inline ::com::sun::star::uno::Type const & 00133 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16 const *) { 00134 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT); 00135 } 00136 00137 inline ::com::sun::star::uno::Type const & 00138 cppu_detail_getUnoType( 00139 SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType const *) 00140 { 00141 return ::cppu::detail::getTypeFromTypeClass( 00142 ::typelib_TypeClass_UNSIGNED_SHORT); 00143 } 00144 00145 inline ::com::sun::star::uno::Type const & 00146 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) { 00147 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG); 00148 } 00149 00150 inline ::com::sun::star::uno::Type const & 00151 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt32 const *) { 00152 return ::cppu::detail::getTypeFromTypeClass( 00153 ::typelib_TypeClass_UNSIGNED_LONG); 00154 } 00155 00156 inline ::com::sun::star::uno::Type const & 00157 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64 const *) { 00158 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER); 00159 } 00160 00161 inline ::com::sun::star::uno::Type const & 00162 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt64 const *) { 00163 return ::cppu::detail::getTypeFromTypeClass( 00164 ::typelib_TypeClass_UNSIGNED_HYPER); 00165 } 00166 00167 inline ::com::sun::star::uno::Type const & 00168 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER float const *) { 00169 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT); 00170 } 00171 00172 inline ::com::sun::star::uno::Type const & 00173 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER double const *) { 00174 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE); 00175 } 00176 00177 inline ::com::sun::star::uno::Type const & 00178 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) { 00179 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR); 00180 } 00181 00182 inline ::com::sun::star::uno::Type const & 00183 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) { 00184 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING); 00185 } 00186 00187 inline ::com::sun::star::uno::Type const & 00188 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Type const *) 00189 { 00190 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE); 00191 } 00192 00193 inline ::com::sun::star::uno::Type const & 00194 cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::com::sun::star::uno::Any const *) 00195 { 00196 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY); 00197 } 00198 00199 template< typename T > inline ::com::sun::star::uno::Type const & 00200 cppu_detail_getUnoType( 00201 SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType< T > const *) 00202 { 00203 //TODO: depending on memory model, the following might not work reliably 00204 static typelib_TypeDescriptionReference * p = 0; 00205 if (p == 0) { 00206 ::typelib_static_sequence_type_init( 00207 &p, ::cppu::UnoType< T >::get().getTypeLibType()); 00208 } 00209 return ::cppu::detail::getTypeFromTypeDescriptionReference(&p); 00210 } 00211 00212 template< typename T > inline ::com::sun::star::uno::Type const & 00213 cppu_detail_getUnoType( 00214 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *) 00215 { 00216 return cppu_detail_getUnoType( 00217 static_cast< ::cppu::UnoSequenceType< T > * >(0)); 00218 } 00219 00220 inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType( 00221 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Exception const *) 00222 { 00223 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION); 00224 } 00225 00226 inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType( 00227 SAL_UNUSED_PARAMETER ::com::sun::star::uno::XInterface const *) 00228 { 00229 return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE); 00230 } 00231 00232 template< typename T > inline ::com::sun::star::uno::Type const & 00233 cppu_detail_getUnoType( 00234 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Reference< T > const *) 00235 { 00236 return ::cppu::UnoType< T >::get(); 00237 } 00238 00239 } } 00240 00241 namespace cppu { 00242 00263 template< typename T > class UnoType { 00264 public: 00265 static inline ::com::sun::star::uno::Type const & get() { 00266 using namespace ::cppu::detail; 00267 return cppu_detail_getUnoType(static_cast< T * >(0)); 00268 } 00269 00270 private: 00271 UnoType(UnoType &); // not defined 00272 ~UnoType(); // not defined 00273 void operator =(UnoType &); // not defined 00274 }; 00275 00286 template< typename T > inline ::com::sun::star::uno::Type const & 00287 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *) { 00288 return ::cppu::UnoType< T >::get(); 00289 } 00290 00301 inline ::com::sun::star::uno::Type const & 00302 getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16 const *) { 00303 return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get(); 00304 } 00305 00316 template< typename T > inline ::com::sun::star::uno::Type const & 00317 getTypeFavourUnsigned(::com::sun::star::uno::Sequence< T > const *); 00318 // defined in com/sun/star/uno/Sequence.hxx 00319 00321 00333 template< typename T > inline ::com::sun::star::uno::Type const & 00334 getTypeFavourChar(SAL_UNUSED_PARAMETER T const *) { 00335 return ::cppu::UnoType< T >::get(); 00336 } 00337 00349 inline ::com::sun::star::uno::Type const & 00350 getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode const *) { 00351 return ::cppu::UnoType< ::cppu::UnoCharType >::get(); 00352 } 00353 00365 template< typename T > inline ::com::sun::star::uno::Type const & 00366 getTypeFavourChar(::com::sun::star::uno::Sequence< T > const *); 00367 // defined in com/sun/star/uno/Sequence.hxx 00368 00370 00371 } 00372 00373 #endif 00374 00375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */