diff options
Diffstat (limited to 'include/cppu')
-rw-r--r-- | include/cppu/Enterable.hxx | 112 | ||||
-rw-r--r-- | include/cppu/EnvDcp.hxx | 70 | ||||
-rw-r--r-- | include/cppu/EnvGuards.hxx | 107 | ||||
-rw-r--r-- | include/cppu/Map.hxx | 109 | ||||
-rw-r--r-- | include/cppu/cppudllapi.h | 24 | ||||
-rw-r--r-- | include/cppu/helper/purpenv/Environment.hxx | 46 | ||||
-rw-r--r-- | include/cppu/helper/purpenv/Mapping.hxx | 66 | ||||
-rw-r--r-- | include/cppu/macros.hxx | 64 | ||||
-rw-r--r-- | include/cppu/unotype.hxx | 412 |
9 files changed, 1010 insertions, 0 deletions
diff --git a/include/cppu/Enterable.hxx b/include/cppu/Enterable.hxx new file mode 100644 index 0000000000..b5cc789e43 --- /dev/null +++ b/include/cppu/Enterable.hxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_CPPU_ENTERABLE_HXX +#define INCLUDED_CPPU_ENTERABLE_HXX + +#include "uno/Enterable.h" +#include "rtl/ustring.hxx" + +namespace cppu +{ +/** C++ wrapper for binary C Enterable + (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Environment_Stack) + + @see uno_Enterable + @since UDK 3.2.7 +*/ +class Enterable : public uno_Enterable +{ +public: + /* These methods need to be implemented in a derived class. + */ + virtual void v_enter() = 0; + virtual void v_leave() = 0; + virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) = 0; + virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam) = 0; + virtual bool v_isValid (rtl::OUString * pReason) = 0; + + virtual ~Enterable() {} + +public: + inline explicit Enterable(); + + void enter() {m_enter(this);} + void leave() {m_leave(this);} + + void callInto_v(uno_EnvCallee * pCallee, va_list * pParam) {m_callInto_v(this, pCallee, pParam);} + void callOut_v (uno_EnvCallee * pCallee, va_list * pParam) {m_callOut_v (this, pCallee, pParam);} + + inline void callInto(uno_EnvCallee * pCallee, ...); + inline void callOut (uno_EnvCallee * pCallee, ...); + + int isValid (rtl::OUString * pReason) {return m_isValid(this, &pReason->pData);} + +private: + Enterable(Enterable const &) SAL_DELETED_FUNCTION; + Enterable & operator = (Enterable const &) SAL_DELETED_FUNCTION; +}; + +extern "C" inline void Enterable_call_enter (void * context) { static_cast<Enterable *>(context)->v_enter(); } +extern "C" inline void Enterable_call_leave (void * context) { static_cast<Enterable *>(context)->v_leave(); } +extern "C" inline void Enterable_call_callInto_v(void * context, uno_EnvCallee * pCallee, va_list * pParam) + { static_cast<Enterable *>(context)->v_callInto_v(pCallee, pParam); } +extern "C" inline void Enterable_call_callOut_v (void * context, uno_EnvCallee * pCallee, va_list * pParam) + { static_cast<Enterable *>(context)->v_callOut_v(pCallee, pParam); } +extern "C" inline int Enterable_call_isValid (void * context, rtl_uString ** pReason) + {return static_cast<Enterable *>(context)->v_isValid(reinterpret_cast<rtl::OUString *>(pReason));} + + +Enterable::Enterable() +{ + m_enter = Enterable_call_enter; + m_leave = Enterable_call_leave; + m_callInto_v = Enterable_call_callInto_v; + m_callOut_v = Enterable_call_callOut_v; + m_isValid = Enterable_call_isValid; +} + +void Enterable::callInto(uno_EnvCallee * pCallee, ...) +{ + va_list param; + + va_start(param, pCallee); + callInto_v(pCallee, ¶m); + va_end(param); +} + +void Enterable::callOut(uno_EnvCallee * pCallee, ...) +{ + va_list param; + + va_start(param, pCallee); + callOut_v(pCallee, ¶m); + va_end(param); +} + +} + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/EnvDcp.hxx b/include/cppu/EnvDcp.hxx new file mode 100644 index 0000000000..02eb0301d7 --- /dev/null +++ b/include/cppu/EnvDcp.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_CPPU_ENVDCP_HXX +#define INCLUDED_CPPU_ENVDCP_HXX + +#include "rtl/ustring.hxx" +#include "uno/EnvDcp.h" + +namespace cppu +{ +namespace EnvDcp +{ +/** Get the OBI type part of an environment descriptor. + (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Environment_Descriptor) + + @param rEnvDcp the Environment Descriptor + @return the OBI type + @since UDK 3.2.7 +*/ +inline rtl::OUString getTypeName(rtl::OUString const& rEnvDcp) +{ + rtl::OUString typeName; + + uno_EnvDcp_getTypeName(rEnvDcp.pData, &typeName.pData); + + return typeName; +} + +/** Get the purpose part of an environment descriptor. + (http://wiki.openoffice.org/wiki/Uno/Binary/Spec/Environment_Descriptor) + + @param rEnvDcp the Environment Descriptor + @return the purpose + @since UDK 3.2.7 +*/ +inline rtl::OUString getPurpose(rtl::OUString const& rEnvDcp) +{ + rtl::OUString purpose; + + uno_EnvDcp_getPurpose(rEnvDcp.pData, &purpose.pData); + + return purpose; +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/EnvGuards.hxx b/include/cppu/EnvGuards.hxx new file mode 100644 index 0000000000..b8a2d30a86 --- /dev/null +++ b/include/cppu/EnvGuards.hxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_CPPU_ENVGUARDS_HXX +#define INCLUDED_CPPU_ENVGUARDS_HXX + +#include "uno/environment.hxx" + + +namespace cppu +{ + /** Environment Guard + The provided Environment becomes entered in the constructor and left + in the destructor. + (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Environment_Guard) + + @since UDK 3.2.7 + */ + class EnvGuard + { + css::uno::Environment m_env; + + public: + explicit EnvGuard(css::uno::Environment const & env) + { + if (env.is()) + { + m_env = css::uno::Environment::getCurrent(); + env.enter(); + } + } + + ~EnvGuard() + { + m_env.enter(); + } + + /** Checks if the associated environment is non empty. + + @return 0 == empty, 1 == non empty + */ + bool SAL_CALL is() const + { + return m_env.is(); + } + + /** Leaves the associated environment and clears + the reference. + */ + void clear() + { + if (m_env.is()) + { + m_env.enter(); + m_env.clear(); + } + } + }; + + /** Environment Anti-Guard + Any entered Environment becomes left in the constructor and re-entered + in the destructor. + (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Environment_AntiGuard) + + @since UDK 3.2.7 + */ + class AntiEnvGuard + { + css::uno::Environment m_env; + + public: + explicit AntiEnvGuard() + : m_env(css::uno::Environment::getCurrent()) + { + uno_Environment_enter(NULL); + } + + ~AntiEnvGuard() + { + m_env.enter(); + } + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/Map.hxx b/include/cppu/Map.hxx new file mode 100644 index 0000000000..da3af7ec1e --- /dev/null +++ b/include/cppu/Map.hxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_CPPU_MAP_HXX +#define INCLUDED_CPPU_MAP_HXX + +#include "uno/mapping.hxx" + + +namespace cppu +{ + /** Helpers for mapping objects relative to the current environment. + (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Map_Helpers) + */ + + /** Maps an object from the current to an outer Environment, returns mapped object. + + @param pT the object to be mapped + @param outerEnv the target environment + @return the mapped object + @since UDK 3.2.7 + */ + template<class T> inline T * mapOut(T * pT, css::uno::Environment const & outerEnv) + { + css::uno::Mapping curr2outer(css::uno::Environment::getCurrent(), outerEnv); + + return reinterpret_cast<T *>(curr2outer.mapInterface(pT, cppu::UnoType<T>::get())); + } + + + /** Maps an object from an outer Environment to the current, returns mapped object. + + @param pT the object to be mapped + @param outerEnv the source environment + @return the mapped object + @since UDK 3.2.7 + */ + template<class T> inline T * mapIn(T * pT, css::uno::Environment const & outerEnv) + { + css::uno::Mapping outer2curr(outerEnv, css::uno::Environment::getCurrent()); + + return reinterpret_cast<T *>(outer2curr.mapInterface(pT, cppu::UnoType<T>::get())); + } + + + /** Maps an any from the current to an outer Environment, fills passed any. + + @param any the any to be mapped + @param res the target any + @param outerEnv the target environment + @since UDK 3.2.7 + */ + // Problem: any gets assigned to something, acquire/releases may be called in wrong env. + inline void mapOutAny(css::uno::Any const & any, css::uno::Any * res, css::uno::Environment const & outerEnv) + { + css::uno::Mapping curr2outer(css::uno::Environment::getCurrent(), outerEnv); + + uno_any_destruct(res, css::uno::cpp_release); + uno_type_any_constructAndConvert( + res, + const_cast<void *>(any.getValue()), + any.getValueTypeRef(), + curr2outer.get()); + } + + + /** Maps an any from an outer Environment to the current, fills passed any. + + @param any the any to be mapped + @param res the target any + @param outerEnv the source environment + @since UDK 3.2.7 + */ + inline void mapInAny(css::uno::Any const & any, css::uno::Any * res, css::uno::Environment const & outerEnv) + { + css::uno::Mapping outer2curr(outerEnv, css::uno::Environment::getCurrent()); + + uno_any_destruct(res, css::uno::cpp_release); + uno_type_any_constructAndConvert( + res, + const_cast<void *>(any.getValue()), + any.getValueTypeRef(), + outer2curr.get()); + } +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/cppudllapi.h b/include/cppu/cppudllapi.h new file mode 100644 index 0000000000..121b6defc6 --- /dev/null +++ b/include/cppu/cppudllapi.h @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_CPPU_CPPUDLLAPI_H +#define INCLUDED_CPPU_CPPUDLLAPI_H + +#include "sal/types.h" + +#if defined(CPPU_DLLIMPLEMENTATION) +#define CPPU_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define CPPU_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif + +#if defined(PURPENV_DLLIMPLEMENTATION) +#define PURPENV_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define PURPENV_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif + +#endif // INCLUDED_CPPU_CPPUDLLAPI_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/helper/purpenv/Environment.hxx b/include/cppu/helper/purpenv/Environment.hxx new file mode 100644 index 0000000000..0024d34dd6 --- /dev/null +++ b/include/cppu/helper/purpenv/Environment.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_CPPU_HELPER_PURPENV_ENVIRONMENT_HXX +#define INCLUDED_CPPU_HELPER_PURPENV_ENVIRONMENT_HXX + +#include "cppu/cppudllapi.h" +#include "uno/environment.h" + +namespace cppu { class Enterable; } + +namespace cppu { namespace helper { namespace purpenv { + +/** C++ helper for implementing Purpose Environments. + (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Purpose_Bridge_Implementation_Helper) + + @since UDK 3.2.7 +*/ +PURPENV_DLLPUBLIC void Environment_initWithEnterable( + uno_Environment * pEnvironment, cppu::Enterable * pEnterable); + +}}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/helper/purpenv/Mapping.hxx b/include/cppu/helper/purpenv/Mapping.hxx new file mode 100644 index 0000000000..18acf35f49 --- /dev/null +++ b/include/cppu/helper/purpenv/Mapping.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_CPPU_HELPER_PURPENV_MAPPING_HXX +#define INCLUDED_CPPU_HELPER_PURPENV_MAPPING_HXX + +#include "cppu/cppudllapi.h" +#include "typelib/typedescription.h" +#include "uno/any2.h" +#include "uno/environment.h" +#include "uno/mapping.h" + + +namespace cppu { namespace helper { namespace purpenv { + +/** C++ helper for implementing Purpose Environments. + (http://wiki.openoffice.org/wiki/Uno/Cpp/Spec/Purpose_Bridge_Implementation_Helper) + + @since UDK 3.2.7 +*/ + +typedef void ProbeFun( + bool pre, + void * pThis, + void * pContext, + typelib_TypeDescriptionReference * pReturnTypeRef, + typelib_MethodParameter * pParams, + sal_Int32 nParams, + typelib_TypeDescription const * pMemberType, + void * pReturn, + void * pArgs[], + uno_Any ** ppException ); + + +PURPENV_DLLPUBLIC void createMapping(uno_Mapping ** ppMapping, + uno_Environment * pFrom, + uno_Environment * pTo, + ProbeFun * probeFun = NULL, + void * pContext = NULL + ); + +}}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/macros.hxx b/include/cppu/macros.hxx new file mode 100644 index 0000000000..e891e72385 --- /dev/null +++ b/include/cppu/macros.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ +#ifndef INCLUDED_CPPU_MACROS_HXX +#define INCLUDED_CPPU_MACROS_HXX + +#include "sal/types.h" + +/** Namespace name for compiler/ platform, e.g. gcc3, msci + + @deprecated implementation detail, not to be used by client code +*/ +#define CPPU_CURRENT_NAMESPACE CPPU_ENV + +/// @cond INTERNAL + +/** Patching the GCC 3 incompatible alignment change for Linux. + + This macro is appended by cppumaker to every first member of a struct, if + the struct inherits from a base struct and the first member is neither + double nor sal_[u]Int64. (The double/sal_[u]Int64 restriction is due to a + bug in GCC prior to version 3.3, which would cause __alignof__ of such a + struct to become 8 instead of 4 if CPPU_GCC3_ALIGN were added to its first + member.) +*/ +#if defined(__GNUC__) +#define CPPU_GCC3_ALIGN( base_struct ) __attribute__ ((aligned (__alignof__ (base_struct)))) +#else +#define CPPU_GCC3_ALIGN( base_struct ) +#endif + +/** + Exporting the symbols necessary for exception handling on GCC. + + These macros are used in the headers generated by cppumaker for UNO exception + types, to ensure that exception handling does not fail on GCC. +*/ +#define CPPU_GCC_DLLPUBLIC_EXPORT SAL_EXCEPTION_DLLPUBLIC_EXPORT +#define CPPU_GCC_DLLPRIVATE SAL_EXCEPTION_DLLPRIVATE + +/// @endcond + +#endif // INCLUDED_CPPU_MACROS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/cppu/unotype.hxx b/include/cppu/unotype.hxx new file mode 100644 index 0000000000..e794747ba0 --- /dev/null +++ b/include/cppu/unotype.hxx @@ -0,0 +1,412 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_CPPU_UNOTYPE_HXX +#define INCLUDED_CPPU_UNOTYPE_HXX + +#include "sal/config.h" + +#include <cstddef> + +#if defined LIBO_INTERNAL_ONLY +#include <type_traits> +#endif + +#include "sal/types.h" +#include "typelib/typeclass.h" +#include "typelib/typedescription.h" + +namespace com { namespace sun { namespace star { namespace uno { + class Type; + class Any; + class Exception; + template< typename > class Reference; + template< typename > class Sequence; + class XInterface; +} } } } +namespace rtl { class OUString; } + +namespace cppu { + +template< typename > class UnoType; + +/** + A unique C++ type representing the UNO type VOID in cppu::UnoType. + + This type is declared but not defined. Its only use is as a template + argument to cppu::UnoType. + + @since UDK 3.2.2 +*/ +struct UnoVoidType; + +/** + A unique C++ type representing the UNO type UNSIGNED SHORT in cppu::UnoType. + + The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++ + type is needed to unambiguously specify UNO types in cppu::UnoType. + + This type is declared but not defined. Its only use is as a template + argument to cppu::UnoType. + + @since UDK 3.2.2 +*/ +struct UnoUnsignedShortType; + +/** + A unique C++ type representing the UNO type CHAR in cppu::UnoType. + + The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++ + type is needed to unambiguously specify UNO types in cppu::UnoType. + + This type is declared but not defined. Its only use is as a template + argument to cppu::UnoType. + + @since UDK 3.2.2 +*/ +struct UnoCharType; + +/** + A unique C++ type template representing the UNO sequence types in + cppu::UnoType. + + The UNO types UNSIGNED SHORT and CHAR map to the same C++ type, so this C++ + type is needed to unambiguously specify UNO types in cppu::UnoType. + + This type is declared but not defined. Its only use is as a template + argument to cppu::UnoType. + + @since UDK 3.2.2 +*/ +template< typename > struct UnoSequenceType; + +namespace detail { + +inline css::uno::Type const & getTypeFromTypeDescriptionReference( + ::typelib_TypeDescriptionReference * const * tdr) +{ + return *reinterpret_cast< css::uno::Type const * >(tdr); +} + +inline css::uno::Type const & +getTypeFromTypeClass(::typelib_TypeClass tc) { + return getTypeFromTypeDescriptionReference( + ::typelib_static_type_getByTypeClass(tc)); +} + +} + +} + +namespace cppu { namespace detail { + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoVoidType const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER bool const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Bool const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int8 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int16 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT); +} + +inline css::uno::Type const & +cppu_detail_getUnoType( + SAL_UNUSED_PARAMETER ::cppu::UnoUnsignedShortType const *) +{ + return ::cppu::detail::getTypeFromTypeClass( + ::typelib_TypeClass_UNSIGNED_SHORT); +} + +#if defined LIBO_INTERNAL_ONLY + // cf. sal/types.h sal_Unicode +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_uInt16 const *) { + return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_UNSIGNED_SHORT); +} +#endif + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int32 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt32 const *) { + return ::cppu::detail::getTypeFromTypeClass( + ::typelib_TypeClass_UNSIGNED_LONG); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_Int64 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::sal_uInt64 const *) { + return ::cppu::detail::getTypeFromTypeClass( + ::typelib_TypeClass_UNSIGNED_HYPER); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER float const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER double const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::cppu::UnoCharType const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR); +} + +#if defined LIBO_INTERNAL_ONLY + // cf. sal/types.h sal_Unicode +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER sal_Unicode const *) { + return cppu::detail::getTypeFromTypeClass(typelib_TypeClass_CHAR); +} +#endif + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ::rtl::OUString const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::Type const *) +{ + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE); +} + +inline css::uno::Type const & +cppu_detail_getUnoType(SAL_UNUSED_PARAMETER css::uno::Any const *) +{ + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY); +} + +template< typename T > inline css::uno::Type const & +cppu_detail_getUnoType( + SAL_UNUSED_PARAMETER ::cppu::UnoSequenceType< T > const *) +{ + //TODO: depending on memory model, the following might not work reliably + static typelib_TypeDescriptionReference * p = NULL; + if (p == NULL) { + ::typelib_static_sequence_type_init( + &p, ::cppu::UnoType< T >::get().getTypeLibType()); + } + return ::cppu::detail::getTypeFromTypeDescriptionReference(&p); +} + +template< typename T > inline css::uno::Type const & +cppu_detail_getUnoType( + SAL_UNUSED_PARAMETER css::uno::Sequence< T > const *) +{ + return cppu_detail_getUnoType( + static_cast< ::cppu::UnoSequenceType< T > * >(NULL)); +} + +inline css::uno::Type const & cppu_detail_getUnoType( + SAL_UNUSED_PARAMETER css::uno::Exception const *) +{ + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION); +} + +inline css::uno::Type const & cppu_detail_getUnoType( + SAL_UNUSED_PARAMETER css::uno::XInterface const *) +{ + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE); +} + +template< typename T > inline css::uno::Type const & +cppu_detail_getUnoType( + SAL_UNUSED_PARAMETER css::uno::Reference< T > const *) +{ + return ::cppu::UnoType< T >::get(); +} + +} } + +namespace cppu { + +/** + Get the css::uno::Type instance representing a certain UNO type. + + For each C++ type representing a UNO type, the corresponding instantiation of + this template has a public static member function get(). (The template is + specialized for C++ templates representing polymorphic struct type templates + of UNO. In those cases, it does not work to instantiate UnoType with a C++ + type that is derived from a C++ type that represents a UNO type, but does not + itself represent a UNO type. In all other cases, UnoType even works for such + C++ types that are unambiguously derived from one C++ type that represents a + UNO type.) In addition to those C++ types that are mappings of UNO types + (except for sal_uInt16 and sal_Unicode, see below), the following C++ types + are appropriate as template arguments: void, cppu::UnoVoidType, bool, + cppu::UnoUnsignedShortType, cppu::UnoCharType, cppu::UnoSequenceType with any + appropriate template argument (the latter three to unambiguously specify UNO + types, as the UNO types UNSIGNED SHORT and CHAR map to the same C++ type), + and css::uno::Reference with any appropriate template argument. + + @since UDK 3.2.2 +*/ +template< typename T > class UnoType { +public: + static css::uno::Type const & get() { + using namespace ::cppu::detail; +#if defined LIBO_INTERNAL_ONLY + typedef typename std::remove_reference<T>::type T1; + // for certain uses of UnoType<decltype(x)> +#else + typedef T T1; +#endif + return cppu_detail_getUnoType(static_cast< T1 * >(NULL)); + } + +private: + UnoType(UnoType &) SAL_DELETED_FUNCTION; + ~UnoType() SAL_DELETED_FUNCTION; + void operator =(UnoType &) SAL_DELETED_FUNCTION; +}; + +template<> css::uno::Type inline const & UnoType<void>::get() { + return cppu::UnoType<cppu::UnoVoidType>::get(); +} + +/** + A working replacement for getCppuType (see there). + + There are three overloads of this function that together form the replacement + of getCppuType. The replacement has exactly the same semantics as + getCppuType, in that it returns correct results for the UNO type UNSIGNED + SHORT but not for the UNO type CHAR. + + @since UDK 3.2.2 +*/ +template< typename T > inline css::uno::Type const & +getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *) { + return ::cppu::UnoType< T >::get(); +} + +/** + A working replacement for getCppuType (see there). + + There are three overloads of this function that together form the replacement + of getCppuType. The replacement has exactly the same semantics as + getCppuType, in that it returns correct results for the UNO type UNSIGNED + SHORT but not for the UNO type CHAR. + + @since UDK 3.2.2 +*/ +inline css::uno::Type const & +getTypeFavourUnsigned(SAL_UNUSED_PARAMETER ::sal_uInt16 const *) { + return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get(); +} + +/** + A working replacement for getCppuType (see there). + + There are three overloads of this function that together form the replacement + of getCppuType. The replacement has exactly the same semantics as + getCppuType, in that it returns correct results for the UNO type UNSIGNED + SHORT but not for the UNO type CHAR. + + @since UDK 3.2.2 +*/ +template< typename T > inline css::uno::Type const & +getTypeFavourUnsigned(css::uno::Sequence< T > const *); + // defined in com/sun/star/uno/Sequence.hxx + +/// @cond INTERNAL + +/** + A working replacement for getCppuType (see there). + + There are three overloads of this function that together form the replacement + of the getCppuType template. The replacement has exactly the same semantics + as the getCppuType template, in that it returns correct results for the UNO + type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also + returns the intended results for sequence types. + + @since UDK 3.2.3 +*/ +template< typename T > inline css::uno::Type const & +getTypeFavourChar(SAL_UNUSED_PARAMETER T const *) { + return ::cppu::UnoType< T >::get(); +} + +/** + A working replacement for getCppuType (see there). + + There are three overloads of this function that together form the replacement + of the getCppuType template. The replacement has exactly the same semantics + as the getCppuType template, in that it returns correct results for the UNO + type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also + returns the intended results for sequence types. + + @since UDK 3.2.3 +*/ +inline css::uno::Type const & +getTypeFavourChar(SAL_UNUSED_PARAMETER ::sal_Unicode const *) { + return ::cppu::UnoType< ::cppu::UnoCharType >::get(); +} + +/** + A working replacement for getCppuType (see there). + + There are three overloads of this function that together form the replacement + of the getCppuType template. The replacement has exactly the same semantics + as the getCppuType template, in that it returns correct results for the UNO + type CHAR but not for the UNO type UNSIGNED SHORT. Additionally, it also + returns the intended results for sequence types. + + @since UDK 3.2.3 +*/ +template< typename T > inline css::uno::Type const & +getTypeFavourChar(css::uno::Sequence< T > const *); + // defined in com/sun/star/uno/Sequence.hxx + +/// @endcond + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |