diff options
Diffstat (limited to 'cppu/inc')
43 files changed, 9233 insertions, 0 deletions
diff --git a/cppu/inc/com/sun/star/uno/Any.h b/cppu/inc/com/sun/star/uno/Any.h new file mode 100644 index 000000000000..eb29273c16aa --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Any.h @@ -0,0 +1,386 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_ANY_H_ +#define _COM_SUN_STAR_UNO_ANY_H_ + +#include <uno/any2.h> +#include <typelib/typedescription.h> +#include <com/sun/star/uno/Type.h> +#include "cppu/unotype.hxx" +#include <rtl/alloc.h> + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ class representing an IDL any. + This class is used to transport any type defined in IDL. The class inherits from the + binary C representation of uno_Any. + You can insert a value by either using the <<= operators or the template function makeAny(). + No any can hold an any. You can extract values from an any by using the >>= operators which + return true if the any contains an assignable value (no data loss), e.g. the any contains a + short and you >>= it into a long variable. +*/ +class Any : public uno_Any +{ +public: + // these are here to force memory de/allocation to sal lib. + /** @internal */ + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) + { return ::rtl_allocateMemory( nSize ); } + /** @internal */ + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) + { ::rtl_freeMemory( pMem ); } + /** @internal */ + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) + { return pMem; } + /** @internal */ + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) + {} + + /** Default constructor: Any holds no value; its type is void. + */ + inline Any() SAL_THROW( () ); + + /** Templated ctor. Sets a copy of the given value. + + @param value value of the Any + */ + template <typename T> + explicit inline Any( T const & value ); + /// Ctor support for C++ bool. + explicit inline Any( bool value ); + + /** Copy constructor: Sets value of the given any. + + @param rAny another any + */ + inline Any( const Any & rAny ) SAL_THROW( () ); + + /** Constructor: Sets a copy of the given data. + + @param pData_ value + @param rType type of value + */ + inline Any( const void * pData_, const Type & rType ) SAL_THROW( () ); + + /** Constructor: Sets a copy of the given data. + + @param pData_ value + @param pTypeDescr type of value + */ + inline Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ); + + /** Constructor: Sets a copy of the given data. + + @param pData_ value + @param pType type of value + */ + inline Any( const void * pData_, typelib_TypeDescriptionReference * pType ) SAL_THROW( () ); + + /** Destructor: Destructs any content and frees memory. + */ + inline ~Any() SAL_THROW( () ); + + /** Assignment operator: Sets the value of the given any. + + @param rAny another any (right side) + @return this any + */ + inline Any & SAL_CALL operator = ( const Any & rAny ) SAL_THROW( () ); + + /** Gets the type of the set value. + + @return a Type object of the set value + */ + inline const Type & SAL_CALL getValueType() const SAL_THROW( () ) + { return * reinterpret_cast< const Type * >( &pType ); } + /** Gets the type of the set value. + + @return the UNacquired type description reference of the set value + */ + inline typelib_TypeDescriptionReference * SAL_CALL getValueTypeRef() const SAL_THROW( () ) + { return pType; } + + /** Gets the type description of the set value. Provides ownership of the type description! + Call an explicit typelib_typedescription_release() to release afterwards. + + @param a pointer to type description pointer + */ + inline void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const SAL_THROW( () ) + { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); } + + /** Gets the type class of the set value. + + @return the type class of the set value + */ + inline TypeClass SAL_CALL getValueTypeClass() const SAL_THROW( () ) + { return (TypeClass)pType->eTypeClass; } + + /** Gets the type name of the set value. + + @return the type name of the set value + */ + inline ::rtl::OUString SAL_CALL getValueTypeName() const SAL_THROW( () ); + + /** Tests if any contains a value. + + @return true if any has a value, false otherwise + */ + inline sal_Bool SAL_CALL hasValue() const SAL_THROW( () ) + { return (typelib_TypeClass_VOID != pType->eTypeClass); } + + /** Gets a pointer to the set value. + + @return a pointer to the set value + */ + inline const void * SAL_CALL getValue() const SAL_THROW( () ) + { return pData; } + +#if ! defined(EXCEPTIONS_OFF) + /** Provides a value of specified type, so you can easily write e.g. + <pre> + sal_Int32 myVal = myAny.get<sal_Int32>(); + </pre> + Widening conversion without data loss is taken into account. + Throws a + <type scope="com::sun::star::uno">RuntimeException</type> + if the specified type cannot be provided. + + @return value of specified type + @exception <type scope="com::sun::star::uno">RuntimeException</type> + in case the specified type cannot be provided + */ + template <typename T> + inline T get() const; +#endif // ! defined(EXCEPTIONS_OFF) + + /** Sets a value. If the any already contains a value, that value will be destructed + and its memory freed. + + @param pData_ pointer to value + @param rType type of value + */ + inline void SAL_CALL setValue( const void * pData_, const Type & rType ) SAL_THROW( () ); + /** Sets a value. If the any already contains a value, that value will be destructed + and its memory freed. + + @param pData_ pointer to value + @param pType type of value + */ + inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescriptionReference * pType ) SAL_THROW( () ); + /** Sets a value. If the any already contains a value, that value will be destructed + and its memory freed. + + @param pData_ pointer to value + @param pTypeDescr type description of value + */ + inline void SAL_CALL setValue( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ); + + /** Clears this any. If the any already contains a value, that value will be destructed + and its memory freed. After this has been called, the any does not contain a value. + */ + inline void SAL_CALL clear() SAL_THROW( () ); + + /** Tests whether this any is extractable to a value of given type. + Widening conversion without data loss is taken into account. + + @param rType destination type + @return true if this any is extractable to value of given type (e.g. using >>= operator) + */ + inline sal_Bool SAL_CALL isExtractableTo( const Type & rType ) const SAL_THROW( () ); + + /** Tests whether this any can provide a value of specified type. + Widening conversion without data loss is taken into account. + + @return true if this any can provide a value of specified type + (e.g. using >>= operator) + */ + template <typename T> + inline bool has() const; + + /** Equality operator: compares two anys. + The values need not be of equal type, e.g. a short integer is compared to a long integer. + + @param rAny another any (right side) + @return true if both any contains equal values + */ + inline sal_Bool SAL_CALL operator == ( const Any & rAny ) const SAL_THROW( () ); + /** Unequality operator: compares two anys. + The values need not be of equal type, e.g. a short integer is compared to a long integer. + + @param rAny another any (right side) + @return true if both any contains unequal values + */ + inline sal_Bool SAL_CALL operator != ( const Any & rAny ) const SAL_THROW( () ); + +private: + // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16) + explicit Any( sal_uInt16 ); +#if defined(_MSC_VER) + // Omitting the following private declarations leads to an internal compiler + // error on MSVC (version 1310). + // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16) +#if ! defined(EXCEPTIONS_OFF) + template <> + sal_uInt16 get<sal_uInt16>() const; +#endif // ! defined(EXCEPTIONS_OFF) + template <> + bool has<sal_uInt16>() const; +#endif // defined(_MSC_VER) +}; + +/** Template function to generically construct an any from a C++ value. + + @tplparam C value type + @param value a value + @return an any +*/ +template< class C > +inline Any SAL_CALL makeAny( const C & value ) SAL_THROW( () ); + +// additionally specialized for C++ bool +template<> +inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW( () ); + +class BaseReference; +class Type; + +/** Template binary <<= operator to set the value of an any. + + @tplparam C value type + @param rAny destination any (left side) + @param value source value (right side) +*/ +template< class C > +inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW( () ); + +// additionally for C++ bool: +inline void SAL_CALL operator <<= ( Any & rAny, bool const & value ) + SAL_THROW( () ); + +/** Template binary >>= operator to assign a value from an any. + If the any does not contain a value that can be assigned without data loss, then this + operation will fail returning false. + + @tplparam C value type + @param rAny source any (left side) + @param value destination value (right side) + @return true if assignment was possible without data loss +*/ +template< class C > +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW( () ); + +/** Template equality operator: compares set value of left side any to right side value. + The values need not be of equal type, e.g. a short integer is compared to a long integer. + This operator can be implemented as template member function, if all supported compilers + can cope with template member functions. + + @tplparam C value type + @param rAny another any (left side) + @param value a value (right side) + @return true if values are equal, false otherwise +*/ +template< class C > +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW( () ); +/** Template unequality operator: compares set value of left side any to right side value. + The values need not be of equal type, e.g. a short integer is compared to a long integer. + This operator can be implemented as template member function, if all supported compilers + can cope with template member functions. + + @tplparam C value type + @param rAny another any (left side) + @param value a value (right side) + @return true if values are unequal, false otherwise +*/ +template< class C > +inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW( () ); + +// additional specialized >>= and == operators +// bool +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Bool & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW( () ); +template<> +inline sal_Bool SAL_CALL operator >>= ( Any const & rAny, bool & value ) + SAL_THROW( () ); +template<> +inline sal_Bool SAL_CALL operator == ( Any const & rAny, bool const & value ) + SAL_THROW( () ); +// byte +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int8 & value ) SAL_THROW( () ); +// short +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW( () ); +// long +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW( () ); +// hyper +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW( () ); +// float +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW( () ); +// double +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW( () ); +// string +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW( () ); +// type +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW( () ); +// any +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW( () ); +// interface +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW( () ); + +} +} +} +} + +/** Gets the meta type of IDL type any. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type any +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Any * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::com::sun::star::uno::Any >::get(); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/Any.hxx b/cppu/inc/com/sun/star/uno/Any.hxx new file mode 100644 index 000000000000..8ea8c437dde2 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Any.hxx @@ -0,0 +1,583 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#define _COM_SUN_STAR_UNO_ANY_HXX_ + +#include <com/sun/star/uno/Any.h> +#include <uno/data.h> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/genfunc.hxx> +#include "cppu/unotype.hxx" + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +//__________________________________________________________________________________________________ +inline Any::Any() SAL_THROW( () ) +{ + ::uno_any_construct( this, 0, 0, (uno_AcquireFunc)cpp_acquire ); +} + +//______________________________________________________________________________ +template <typename T> +inline Any::Any( T const & value ) +{ + ::uno_type_any_construct( + this, const_cast<T *>(&value), + ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(), + (uno_AcquireFunc) cpp_acquire ); +} +//______________________________________________________________________________ +inline Any::Any( bool value ) +{ + sal_Bool b = value; + ::uno_type_any_construct( + this, &b, ::getCppuBooleanType().getTypeLibType(), + (uno_AcquireFunc) cpp_acquire ); +} + +//__________________________________________________________________________________________________ +inline Any::Any( const Any & rAny ) SAL_THROW( () ) +{ + ::uno_type_any_construct( this, rAny.pData, rAny.pType, (uno_AcquireFunc)cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::Any( const void * pData_, const Type & rType ) SAL_THROW( () ) +{ + ::uno_type_any_construct( + this, const_cast< void * >( pData_ ), rType.getTypeLibType(), + (uno_AcquireFunc)cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ) +{ + ::uno_any_construct( + this, const_cast< void * >( pData_ ), pTypeDescr, (uno_AcquireFunc)cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW( () ) +{ + ::uno_type_any_construct( + this, const_cast< void * >( pData_ ), pType_, (uno_AcquireFunc)cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::~Any() SAL_THROW( () ) +{ + ::uno_any_destruct( + this, (uno_ReleaseFunc)cpp_release ); +} +//__________________________________________________________________________________________________ +inline Any & Any::operator = ( const Any & rAny ) SAL_THROW( () ) +{ + if (this != &rAny) + { + ::uno_type_any_assign( + this, rAny.pData, rAny.pType, + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); + } + return *this; +} +//__________________________________________________________________________________________________ +inline ::rtl::OUString Any::getValueTypeName() const SAL_THROW( () ) +{ + return ::rtl::OUString( pType->pTypeName ); +} +//__________________________________________________________________________________________________ +inline void Any::setValue( const void * pData_, const Type & rType ) SAL_THROW( () ) +{ + ::uno_type_any_assign( + this, const_cast< void * >( pData_ ), rType.getTypeLibType(), + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); +} +//__________________________________________________________________________________________________ +inline void Any::setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW( () ) +{ + ::uno_type_any_assign( + this, const_cast< void * >( pData_ ), pType_, + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); +} +//__________________________________________________________________________________________________ +inline void Any::setValue( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ) +{ + ::uno_any_assign( + this, const_cast< void * >( pData_ ), pTypeDescr, + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); +} +//__________________________________________________________________________________________________ +inline void Any::clear() SAL_THROW( () ) +{ + ::uno_any_clear( + this, (uno_ReleaseFunc)cpp_release ); +} +//__________________________________________________________________________________________________ +inline sal_Bool Any::isExtractableTo( const Type & rType ) const SAL_THROW( () ) +{ + return ::uno_type_isAssignableFromData( + rType.getTypeLibType(), pData, pType, + (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ); +} + +//______________________________________________________________________________ +template <typename T> +inline bool Any::has() const +{ + Type const & rType = ::cppu::getTypeFavourUnsigned(static_cast< T * >(0)); + return ::uno_type_isAssignableFromData( + rType.getTypeLibType(), pData, pType, + (uno_QueryInterfaceFunc) cpp_queryInterface, + (uno_ReleaseFunc) cpp_release ); +} +#if ! defined(__SUNPRO_CC) +// not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16) +template <> +bool Any::has<sal_uInt16>() const; +#endif // ! defined(__SUNPRO_CC) + +//__________________________________________________________________________________________________ +inline sal_Bool Any::operator == ( const Any & rAny ) const SAL_THROW( () ) +{ + return ::uno_type_equalData( + pData, pType, rAny.pData, rAny.pType, + (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ); +} +//__________________________________________________________________________________________________ +inline sal_Bool Any::operator != ( const Any & rAny ) const SAL_THROW( () ) +{ + return (! ::uno_type_equalData( + pData, pType, rAny.pData, rAny.pType, + (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release )); +} + +//__________________________________________________________________________________________________ +template< class C > +inline Any SAL_CALL makeAny( const C & value ) SAL_THROW( () ) +{ + return Any( &value, ::cppu::getTypeFavourUnsigned(&value) ); +} + +// additionally specialized for C++ bool +//______________________________________________________________________________ +template<> +inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW( () ) +{ + const sal_Bool b = value; + return Any( &b, ::getCppuBooleanType() ); +} + +//__________________________________________________________________________________________________ +template< class C > +inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW( () ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned(&value); + ::uno_type_any_assign( + &rAny, const_cast< C * >( &value ), rType.getTypeLibType(), + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); +} + +// additionally for C++ bool: +//______________________________________________________________________________ +inline void SAL_CALL operator <<= ( Any & rAny, bool const & value ) + SAL_THROW( () ) +{ + sal_Bool b = value; + ::uno_type_any_assign( + &rAny, &b, ::getCppuBooleanType().getTypeLibType(), + (uno_AcquireFunc) cpp_acquire, (uno_ReleaseFunc) cpp_release ); +} + +//__________________________________________________________________________________________________ +template< class C > +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW( () ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned(&value); + return ::uno_type_assignData( + &value, rType.getTypeLibType(), + rAny.pData, rAny.pType, + (uno_QueryInterfaceFunc)cpp_queryInterface, + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); +} + +// bool +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) SAL_THROW( () ) +{ + if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass) + { + value = (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW( () ) +{ + return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass && + (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False)); +} + +//______________________________________________________________________________ +template<> +inline sal_Bool SAL_CALL operator >>= ( Any const & rAny, bool & value ) + SAL_THROW( () ) +{ + if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN) + { + value = *reinterpret_cast< sal_Bool const * >( + rAny.pData ) != sal_False; + return true; + } + return false; +} + +//______________________________________________________________________________ +template<> +inline sal_Bool SAL_CALL operator == ( Any const & rAny, bool const & value ) + SAL_THROW( () ) +{ + return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN && + (value == + (*reinterpret_cast< sal_Bool const * >( rAny.pData ) + != sal_False))); +} + +// byte +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) SAL_THROW( () ) +{ + if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass) + { + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + } + return sal_False; +} +// short +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +// long +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +// hyper +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + value = * reinterpret_cast< const sal_Int64 * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + value = * reinterpret_cast< const sal_uInt64 * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +// float +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_FLOAT: + value = * reinterpret_cast< const float * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +// double +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW( () ) +{ + switch (rAny.pType->eTypeClass) + { + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_FLOAT: + value = * reinterpret_cast< const float * >( rAny.pData ); + return sal_True; + case typelib_TypeClass_DOUBLE: + value = * reinterpret_cast< const double * >( rAny.pData ); + return sal_True; + default: + return sal_False; + } +} +// string +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW( () ) +{ + if (typelib_TypeClass_STRING == rAny.pType->eTypeClass) + { + value = * reinterpret_cast< const ::rtl::OUString * >( rAny.pData ); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW( () ) +{ + return (typelib_TypeClass_STRING == rAny.pType->eTypeClass && + value.equals( * reinterpret_cast< const ::rtl::OUString * >( rAny.pData ) )); +} +// type +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW( () ) +{ + if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass) + { + value = * reinterpret_cast< const Type * >( rAny.pData ); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW( () ) +{ + return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass && + value.equals( * reinterpret_cast< const Type * >( rAny.pData ) )); +} +// any +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW( () ) +{ + if (&rAny != &value) + { + ::uno_type_any_assign( + &value, rAny.pData, rAny.pType, + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); + } + return sal_True; +} +// interface +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW( () ) +{ + if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass) + { + return reinterpret_cast< const BaseReference * >( rAny.pData )->operator == ( value ); + } + return sal_False; +} + +// operator to compare to an any. +//__________________________________________________________________________________________________ +template< class C > +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW( () ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned(&value); + return ::uno_type_equalData( + rAny.pData, rAny.pType, + const_cast< C * >( &value ), rType.getTypeLibType(), + (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ); +} +// operator to compare to an any. may use specialized operators ==. +//__________________________________________________________________________________________________ +template< class C > +inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW( () ) +{ + return (! operator == ( rAny, value )); +} + +#if ! defined(EXCEPTIONS_OFF) +extern "C" rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg( + uno_Any const * pAny, typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C(); + +//______________________________________________________________________________ +template <typename T> +T Any::get() const +{ + T value = T(); + if (! (*this >>= value)) { + throw RuntimeException( + ::rtl::OUString( + cppu_Any_extraction_failure_msg( + this, + ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ), + SAL_NO_ACQUIRE ), + Reference<XInterface>() ); + } + return value; +} +// not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16) +template <> +sal_uInt16 Any::get<sal_uInt16>() const; +#endif // ! defined(EXCEPTIONS_OFF) + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/Reference.h b/cppu/inc/com/sun/star/uno/Reference.h new file mode 100644 index 000000000000..071cadcfde7b --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Reference.h @@ -0,0 +1,536 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#define _COM_SUN_STAR_UNO_REFERENCE_H_ + +#include <rtl/alloc.h> + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +class RuntimeException; +class XInterface; +class Type; +class Any; + +/** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface. + Deprecated, please use SAL_NO_ACQUIRE. + @deprecated +*/ +enum UnoReference_NoAcquire +{ + /** This enum value can be used for creating a reference granting a given interface, + i.e. transferring ownership to it. + */ + UNO_REF_NO_ACQUIRE +}; + +/** This base class serves as a base class for all template reference classes and + has been introduced due to compiler problems with templated operators ==, =!. +*/ +class BaseReference +{ +protected: + /** the interface pointer + */ + XInterface * _pInterface; + + /** Queries given interface for type rType. + + @param pInterface interface pointer + @param rType interface type + @return interface of demanded type (may be null) + */ + inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ); +#ifndef EXCEPTIONS_OFF + /** Queries given interface for type rType. + Throws a RuntimeException if the demanded interface cannot be queried. + + @param pInterface interface pointer + @param rType interface type + @return interface of demanded type + */ + inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ); +#endif + +public: + /** Gets interface pointer. This call does not acquire the interface. + + @return UNacquired interface pointer + */ + inline XInterface * SAL_CALL get() const SAL_THROW( () ) + { return _pInterface; } + + /** Checks if reference is null. + + @return true if reference acquires an interface, i.e. true if it is not null + */ + inline sal_Bool SAL_CALL is() const SAL_THROW( () ) + { return (0 != _pInterface); } + + /** Equality operator: compares two interfaces + Checks if both references are null or refer to the same object. + + @param rRef another interface + @return true if both references are null or refer to the same object, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( XInterface * pInterface ) const SAL_THROW( () ); + /** Unequality operator: compares two interfaces + Checks if both references are null or refer to the same object. + + @param rRef another interface + @return false if both references are null or refer to the same object, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( XInterface * pInterface ) const SAL_THROW( () ); + + /** Equality operator: compares two interfaces + Checks if both references are null or refer to the same object. + + @param rRef another reference + @return true if both references are null or refer to the same object, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( const BaseReference & rRef ) const SAL_THROW( () ); + /** Unequality operator: compares two interfaces + Checks if both references are null or refer to the same object. + + @param rRef another reference + @return false if both references are null or refer to the same object, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( const BaseReference & rRef ) const SAL_THROW( () ); + + /** Needed by some STL containers. + + @param rRef another reference + @return true, if this reference is less than rRef + */ + inline sal_Bool SAL_CALL operator < ( const BaseReference & rRef ) const SAL_THROW( () ); +}; + +/** Enum defining UNO_QUERY and UNO_REF_QUERY for implicit interface query. +*/ +enum UnoReference_Query +{ + /** This enum value can be used for implicit interface query. + */ + UNO_QUERY, + /** This enum value can be used for implicit interface query. + */ + UNO_REF_QUERY +}; +#ifndef EXCEPTIONS_OFF +/** Enum defining UNO_QUERY_THROW and UNO_REF_QUERY_THROW for implicit interface query. + If the demanded interface is unavailable, then a RuntimeException is thrown. +*/ +enum UnoReference_QueryThrow +{ + /** This enum value can be used for implicit interface query. + */ + UNO_QUERY_THROW, + /** This enum value can be used for implicit interface query. + */ + UNO_REF_QUERY_THROW +}; +/** Enum defining UNO_SET_THROW for throwing if attempts are made to assign a <NULL/> + interface + + @since UDK 3.2.8 +*/ +enum UnoReference_SetThrow +{ + UNO_SET_THROW +}; +#endif + +/** Template reference class for interface type derived from BaseReference. + A special constructor given the UNO_QUERY or UNO_REF_QUERY identifier queries interfaces + for reference type. +*/ +template< class interface_type > +class Reference : public BaseReference +{ + /** Queries given interface for type interface_type. + + @param pInterface interface pointer + @return interface of demanded type (may be null) + */ + inline static XInterface * SAL_CALL iquery( XInterface * pInterface ) + SAL_THROW( (RuntimeException) ); +#ifndef EXCEPTIONS_OFF + /** Queries given interface for type interface_type. + Throws a RuntimeException if the demanded interface cannot be queried. + + @param pInterface interface pointer + @return interface of demanded type + */ + inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface ) + SAL_THROW( (RuntimeException) ); + /** Returns the given interface if it is not <NULL/>, throws a RuntimeException otherwise. + + @param pInterface interface pointer + @return pInterface + */ + inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface ) + SAL_THROW( (RuntimeException) ); +#endif + + /** Cast from an "interface pointer" (e.g., BaseReference::_pInterface) to a + pointer to this interface_type. + + To work around ambiguities in the case of multiple-inheritance interface + types (which inherit XInterface more than once), use reinterpret_cast + (resp. a sequence of two static_casts, to avoid warnings about + reinterpret_cast used between related classes) to switch from a pointer + to XInterface to a pointer to this derived interface_type. In + principle, this is not guaranteed to work. In practice, it seems to + work on all supported platforms. + */ + static inline interface_type * castFromXInterface(XInterface * p) { + return static_cast< interface_type * >(static_cast< void * >(p)); + } + + /** Cast from a pointer to this interface_type to an "interface pointer" + (e.g., BaseReference::_pInterface). + + To work around ambiguities in the case of multiple-inheritance interface + types (which inherit XInterface more than once), use reinterpret_cast + (resp. a sequence of two static_casts, to avoid warnings about + reinterpret_cast used between related classes) to switch from a pointer + to this derived interface_type to a pointer to XInterface. In + principle, this is not guaranteed to work. In practice, it seems to + work on all supported platforms. + */ + static inline XInterface * castToXInterface(interface_type * p) { + return static_cast< XInterface * >(static_cast< void * >(p)); + } + +public: + // these are here to force memory de/allocation to sal lib. + /** @internal */ + inline static void * SAL_CALL operator new ( ::size_t nSize ) SAL_THROW( () ) + { return ::rtl_allocateMemory( nSize ); } + /** @internal */ + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) + { ::rtl_freeMemory( pMem ); } + /** @internal */ + inline static void * SAL_CALL operator new ( ::size_t, void * pMem ) SAL_THROW( () ) + { return pMem; } + /** @internal */ + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) + {} + + /** Destructor: Releases interface if set. + */ + inline ~Reference() SAL_THROW( () ); + + /** Default Constructor: Sets null reference. + */ + inline Reference() SAL_THROW( () ); + + /** Copy constructor: Copies interface reference. + + @param rRef another reference + */ + inline Reference( const Reference< interface_type > & rRef ) SAL_THROW( () ); + /** Constructor: Sets given interface pointer. + + @param pInterface an interface pointer + */ + inline Reference( interface_type * pInterface ) SAL_THROW( () ); + + /** Constructor: Sets given interface pointer without acquiring it. + + @param pInterface another reference + @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors + */ + inline Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ); + /** Constructor: Sets given interface pointer without acquiring it. + Deprecated, please use SAL_NO_ACQUIRE version. + + @deprecated + @param pInterface another reference + @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors + */ + inline Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW( () ); + + /** Constructor: Queries given interface for reference interface type (interface_type). + + @param rRef another reference + @param dummy UNO_QUERY or UNO_REF_QUERY to force obvious distinction to other constructors + */ + inline Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) ); + /** Constructor: Queries given interface for reference interface type (interface_type). + + @param pInterface an interface pointer + @param dummy UNO_QUERY to force obvious distinction to other constructors + */ + inline Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) ); + /** Constructor: Queries given any for reference interface type (interface_type). + + @param rAny an any + @param dummy UNO_QUERY to force obvious distinction to other constructors + */ + inline Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) ); +#ifndef EXCEPTIONS_OFF + /** Constructor: Queries given interface for reference interface type (interface_type). + Throws a RuntimeException if the demanded interface cannot be queried. + + @param rRef another reference + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to other constructors + */ + inline Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + /** Constructor: Queries given interface for reference interface type (interface_type). + Throws a RuntimeException if the demanded interface cannot be queried. + + @param pInterface an interface pointer + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to other constructors + */ + inline Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + /** Constructor: Queries given any for reference interface type (interface_type). + Throws a RuntimeException if the demanded interface cannot be queried. + + @param rAny an any + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to other constructors + */ + inline Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException + if the source interface is <NULL/>. + + @param rRef another interface reference of the same type + @param dummy UNO_SET_THROW to distinguish from default copy constructor + + @since UDK 3.2.8 + */ + inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ); + /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException + if the source interface is <NULL/>. + + @param pInterface an interface pointer + @param dummy UNO_SET_THROW to distinguish from default assignment constructor + + @since UDK 3.2.8 + */ + inline Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ); +#endif + + /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and + any interface must be derived from com.sun.star.uno.XInterface. + This a useful direct cast possibility. + */ + inline SAL_CALL operator const Reference< XInterface > & () const SAL_THROW( () ) + { return * reinterpret_cast< const Reference< XInterface > * >( this ); } + + /** Dereference operator: Used to call interface methods. + + @return UNacquired interface pointer + */ + inline interface_type * SAL_CALL operator -> () const SAL_THROW( () ) + { return castFromXInterface(_pInterface); } + + /** Gets interface pointer. This call does not acquire the interface. + + @return UNacquired interface pointer + */ + inline interface_type * SAL_CALL get() const SAL_THROW( () ) + { return castFromXInterface(_pInterface); } + + /** Clears reference, i.e. releases interface. Reference is null after clear() call. + */ + inline void SAL_CALL clear() SAL_THROW( () ); + + /** Sets the given interface. An interface already set will be released. + + @param rRef another reference + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( const Reference< interface_type > & rRef ) SAL_THROW( () ); + /** Sets the given interface. An interface already set will be released. + + @param pInterface another interface + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( interface_type * pInterface ) SAL_THROW( () ); + + /** Sets interface pointer without acquiring it. An interface already set will be released. + + @param pInterface an interface pointer + @param dummy SAL_NO_ACQUIRE to force obvious distinction to set methods + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ); + /** Sets interface pointer without acquiring it. An interface already set will be released. + Deprecated, please use SAL_NO_ACQUIRE version. + + @deprecated + @param pInterface an interface pointer + @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to set methods + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW( () ); + + /** Queries given interface for reference interface type (interface_type) and sets it. + An interface already set will be released. + + @param pInterface an interface pointer + @param dummy UNO_QUERY or UNO_REF_QUERY to force obvious distinction to set methods + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) ); + /** Queries given interface for reference interface type (interface_type) and sets it. + An interface already set will be released. + + @param rRef another reference + @param dummy UNO_QUERY or UNO_REF_QUERY to force obvious distinction to set methods + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) ); + + /** Queries given any for reference interface type (interface_type) + and sets it. An interface already set will be released. + + @param rAny + an Any containing an interface + @param dummy + UNO_QUERY or UNO_REF_QUERY to force obvious distinction + to set methods + @return + true, if non-null interface was set + */ + inline bool set( Any const & rAny, UnoReference_Query ); + +#ifndef EXCEPTIONS_OFF + /** Queries given interface for reference interface type (interface_type) and sets it. + An interface already set will be released. + Throws a RuntimeException if the demanded interface cannot be set. + + @param pInterface an interface pointer + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to set methods + */ + inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + /** Queries given interface for reference interface type (interface_type) and sets it. + An interface already set will be released. + Throws a RuntimeException if the demanded interface cannot be set. + + @param rRef another reference + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to set methods + */ + inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + + /** Queries given any for reference interface type (interface_type) and + sets it. An interface already set will be released. + Throws a RuntimeException if the demanded interface cannot be set. + + @param rAny + an Any containing an interface + @param dummy + UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious + distinction to set methods + */ + inline void set( Any const & rAny, UnoReference_QueryThrow ); + /** sets the given interface + An interface already set will be released. + Throws a RuntimeException if the source interface is <NULL/>. + + @param pInterface an interface pointer + @param dummy UNO_SET_THROW to force obvious distinction to other set methods + + @since UDK 3.2.8 + */ + inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ); + /** sets the given interface + An interface already set will be released. + Throws a RuntimeException if the source interface is <NULL/>. + + @param rRef an interface reference + @param dummy UNO_SET_THROW to force obvious distinction to other set methods + + @since UDK 3.2.8 + */ + inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ); + +#endif + + /** Assignment operator: Acquires given interface pointer and sets reference. + An interface already set will be released. + + @param pInterface an interface pointer + @return this reference + */ + inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface ) SAL_THROW( () ); + /** Assignment operator: Acquires given interface reference and sets reference. + An interface already set will be released. + + @param rRef an interface reference + @return this reference + */ + inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef ) SAL_THROW( () ); + + /** Queries given interface reference for type interface_type. + + @param rRef interface reference + @return interface reference of demanded type (may be null) + */ + inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ) SAL_THROW( (RuntimeException) ); + /** Queries given interface for type interface_type. + + @param pInterface interface pointer + @return interface reference of demanded type (may be null) + */ + inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface ) SAL_THROW( (RuntimeException) ); +}; + +/** @internal + Enables boost::mem_fn and boost::bind to recognize Reference. +*/ +template <typename T> +inline T * get_pointer( Reference<T> const& r ) +{ + return r.get(); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/Reference.hxx b/cppu/inc/com/sun/star/uno/Reference.hxx new file mode 100644 index 000000000000..39e9614f20d8 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Reference.hxx @@ -0,0 +1,432 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#define _COM_SUN_STAR_UNO_REFERENCE_HXX_ + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/XInterface.hdl> +#include <com/sun/star/uno/genfunc.hxx> + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +//__________________________________________________________________________________________________ +inline XInterface * BaseReference::iquery( + XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ) +{ + if (pInterface) + { + Any aRet( pInterface->queryInterface( rType ) ); + if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass) + { + XInterface * pRet = static_cast< XInterface * >( aRet.pReserved ); + aRet.pReserved = 0; + return pRet; + } + } + return 0; +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline XInterface * Reference< interface_type >::iquery( + XInterface * pInterface ) SAL_THROW( (RuntimeException) ) +{ + return BaseReference::iquery(pInterface, interface_type::static_type()); +} +#ifndef EXCEPTIONS_OFF +extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg( + typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C(); +extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg( + typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C(); +//__________________________________________________________________________________________________ +inline XInterface * BaseReference::iquery_throw( + XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ) +{ + XInterface * pQueried = iquery( pInterface, rType ); + if (pQueried) + return pQueried; + throw RuntimeException( + ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ), + Reference< XInterface >( pInterface ) ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline XInterface * Reference< interface_type >::iquery_throw( + XInterface * pInterface ) SAL_THROW( (RuntimeException) ) +{ + return BaseReference::iquery_throw( + pInterface, interface_type::static_type()); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline interface_type * Reference< interface_type >::iset_throw( + interface_type * pInterface ) SAL_THROW( (RuntimeException) ) +{ + if (pInterface) + { + pInterface->acquire(); + return pInterface; + } + throw RuntimeException( + ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ), + NULL ); +} +#endif + +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::~Reference() SAL_THROW( () ) +{ + if (_pInterface) + _pInterface->release(); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference() SAL_THROW( () ) +{ + _pInterface = 0; +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW( () ) +{ + _pInterface = rRef._pInterface; + if (_pInterface) + _pInterface->acquire(); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW( () ) +{ + _pInterface = castToXInterface(pInterface); + if (_pInterface) + _pInterface->acquire(); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ) +{ + _pInterface = castToXInterface(pInterface); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW( () ) +{ + _pInterface = castToXInterface(pInterface); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = iquery( rRef.get() ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = iquery( pInterface ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass + ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0); +} +#ifndef EXCEPTIONS_OFF +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = iquery_throw( rRef.get() ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = iquery_throw( pInterface ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass + ? static_cast< XInterface * >( rAny.pReserved ) : 0 ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = iset_throw( rRef.get() ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = iset_throw( pInterface ); +} +#endif + +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::clear() SAL_THROW( () ) +{ + if (_pInterface) + { + XInterface * const pOld = _pInterface; + _pInterface = 0; + pOld->release(); + } +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + interface_type * pInterface ) SAL_THROW( () ) +{ + if (pInterface) + castToXInterface(pInterface)->acquire(); + XInterface * const pOld = _pInterface; + _pInterface = castToXInterface(pInterface); + if (pOld) + pOld->release(); + return (0 != pInterface); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ) +{ + XInterface * const pOld = _pInterface; + _pInterface = castToXInterface(pInterface); + if (pOld) + pOld->release(); + return (0 != pInterface); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW( () ) +{ + return set( pInterface, SAL_NO_ACQUIRE ); +} + +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + const Reference< interface_type > & rRef ) SAL_THROW( () ) +{ + return set( castFromXInterface( rRef._pInterface ) ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE ); +} + +//______________________________________________________________________________ +template< class interface_type > +inline bool Reference< interface_type >::set( + Any const & rAny, UnoReference_Query ) +{ + return set( + castFromXInterface( + iquery( + rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE + ? static_cast< XInterface * >( rAny.pReserved ) : 0 )), + SAL_NO_ACQUIRE ); +} + +#ifndef EXCEPTIONS_OFF +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::set( + XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::set( + const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE ); +} + +//______________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::set( + Any const & rAny, UnoReference_QueryThrow ) +{ + set( castFromXInterface( + iquery_throw( + rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE + ? static_cast< XInterface * >( rAny.pReserved ) : 0 )), + SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::set( + interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) +{ + set( iset_throw( pInterface ), SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::set( + const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) ) +{ + set( rRef.get(), UNO_SET_THROW ); +} + +#endif + +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > & Reference< interface_type >::operator = ( + interface_type * pInterface ) SAL_THROW( () ) +{ + set( pInterface ); + return *this; +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > & Reference< interface_type >::operator = ( + const Reference< interface_type > & rRef ) SAL_THROW( () ) +{ + set( castFromXInterface( rRef._pInterface ) ); + return *this; +} + +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > Reference< interface_type >::query( + const BaseReference & rRef ) SAL_THROW( (RuntimeException) ) +{ + return Reference< interface_type >( + castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > Reference< interface_type >::query( + XInterface * pInterface ) SAL_THROW( (RuntimeException) ) +{ + return Reference< interface_type >( + castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE ); +} + +//################################################################################################## + +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW( () ) +{ + if (_pInterface == pInterface) + return sal_True; +#ifndef EXCEPTIONS_OFF + try + { +#endif + // only the query to XInterface must return the same pointer if they belong to same objects + Reference< XInterface > x1( _pInterface, UNO_QUERY ); + Reference< XInterface > x2( pInterface, UNO_QUERY ); + return (x1._pInterface == x2._pInterface); +#ifndef EXCEPTIONS_OFF + } + catch (RuntimeException &) + { + return sal_False; + } +#endif +} + +//______________________________________________________________________________ +inline sal_Bool BaseReference::operator < ( + const BaseReference & rRef ) const SAL_THROW( () ) +{ + if (_pInterface == rRef._pInterface) + return sal_False; +#if ! defined EXCEPTIONS_OFF + try + { +#endif + // only the query to XInterface must return the same pointer: + Reference< XInterface > x1( _pInterface, UNO_QUERY ); + Reference< XInterface > x2( rRef, UNO_QUERY ); + return (x1._pInterface < x2._pInterface); +#if ! defined EXCEPTIONS_OFF + } + catch (RuntimeException &) + { + return sal_False; + } +#endif +} + +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW( () ) +{ + return (! operator == ( pInterface )); +} +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW( () ) +{ + return operator == ( rRef._pInterface ); +} +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW( () ) +{ + return (! operator == ( rRef._pInterface )); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/Sequence.h b/cppu/inc/com/sun/star/uno/Sequence.h new file mode 100644 index 000000000000..68abc9d24748 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Sequence.h @@ -0,0 +1,291 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_ +#define _COM_SUN_STAR_UNO_SEQUENCE_H_ + +#include "typelib/typedescription.h" +#include "uno/sequence2.h" +#include "com/sun/star/uno/Type.h" +#include "rtl/alloc.h" + +#if ! defined EXCEPTIONS_OFF +#include <new> +#endif + + +namespace rtl +{ +class ByteSequence; +} + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** Template C++ class representing an IDL sequence. Template argument is the + sequence element type. C++ Sequences are reference counted and shared, + so the sequence keeps a handle to its data. To keep value semantics, + copies are only generated if the sequence is to be modified (new handle). + + @tplparam E element type of sequence +*/ +template< class E > +class Sequence +{ + /** sequence handle + @internal + */ + uno_Sequence * _pSequence; + +public: + // these are here to force memory de/allocation to sal lib. + /** @internal */ + inline static void * SAL_CALL operator new ( ::size_t nSize ) + SAL_THROW( () ) + { return ::rtl_allocateMemory( nSize ); } + /** @internal */ + inline static void SAL_CALL operator delete ( void * pMem ) + SAL_THROW( () ) + { ::rtl_freeMemory( pMem ); } + /** @internal */ + inline static void * SAL_CALL operator new ( ::size_t, void * pMem ) + SAL_THROW( () ) + { return pMem; } + /** @internal */ + inline static void SAL_CALL operator delete ( void *, void * ) + SAL_THROW( () ) + {} + + /** Static pointer to typelib type of sequence. + Don't use directly, call getCppuType(). + @internal + */ + static typelib_TypeDescriptionReference * s_pType; + + /** typedefs the element type of the sequence + */ + typedef E ElementType; + + /** Default constructor: Creates an empty sequence. + */ + inline Sequence() SAL_THROW( () ); + + /** Copy constructor: Creates a copy of given sequence. + + @param rSeq another sequence of same type + */ + inline Sequence( const Sequence< E > & rSeq ) SAL_THROW( () ); + + /** Constructor: Takes over ownership of given sequence. + + @param pSequence a sequence + @param dummy SAL_NO_ACQUIRE to force obvious distinction to other + constructors + */ + inline Sequence( uno_Sequence * pSequence, __sal_NoAcquire ) + SAL_THROW( () ); + + /** Constructor: Creates a copy of given elements. + + @param pElement an array of elements + @param len length of array + */ + inline Sequence( const E * pElements, sal_Int32 len ); + + /** Constructor: Creates a default constructed sequence of given length. + + @param len initial sequence length + */ + inline explicit Sequence( sal_Int32 len ); + + /** Destructor: Releases sequence handle. Last handle will destruct + elements and free memory. + */ + inline ~Sequence() SAL_THROW( () ); + + /** Assignment operator: Acquires given sequence handle and releases + previously set handle. + + @param rSeq another sequence of same type + @return this sequence + */ + inline Sequence< E > & SAL_CALL operator = ( const Sequence< E > & rSeq ) + SAL_THROW( () ); + + /** Gets length of the sequence. + + @return length of sequence + */ + inline sal_Int32 SAL_CALL getLength() const SAL_THROW( () ) + { return _pSequence->nElements; } + + /** Tests whether the sequence has elements, i.e. elements count is + greater than zero. + + @return true, if elements count is greater than zero + */ + inline sal_Bool SAL_CALL hasElements() const SAL_THROW( () ) + { return (_pSequence->nElements > 0); } + + /** Gets a pointer to elements array for reading. + If the sequence has a length of 0, then the returned pointer is + undefined. + + @return pointer to elements array + */ + inline const E * SAL_CALL getConstArray() const SAL_THROW( () ) + { return reinterpret_cast< const E * >( _pSequence->elements ); } + + /** Gets a pointer to elements array for reading and writing. + In general if the sequence has a handle acquired by other sequences + (reference count > 1), then a new sequence is created copy constructing + all elements to keep value semantics! + If the sequence has a length of 0, then the returned pointer is + undefined. + + @return pointer to elements array + */ + inline E * SAL_CALL getArray(); + + /** Non-const index operator: Obtains a reference to element indexed at + given position. + The implementation does not check for array bounds! + In general if the sequence has a handle acquired by other sequences + (reference count > 1), then a new sequence is created copy constructing + all elements to keep value semantics! + + @param nIndex index + @return non-const C++ reference to element + */ + inline E & SAL_CALL operator [] ( sal_Int32 nIndex ); + + /** Const index operator: Obtains a reference to element indexed at + given position. The implementation does not check for array bounds! + + @param nIndex index + @return const C++ reference to element + */ + inline const E & SAL_CALL operator [] ( sal_Int32 nIndex ) const + SAL_THROW( () ); + + /** Equality operator: Compares two sequences. + + @param rSeq another sequence of same type (right side) + @return true if both sequences are equal, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( const Sequence< E > & rSeq ) const + SAL_THROW( () ); + + /** Unequality operator: Compares two sequences. + + @param rSeq another sequence of same type (right side) + @return false if both sequences are equal, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( const Sequence< E > & rSeq ) const + SAL_THROW( () ); + + /** Reallocates sequence to new length. + If the new length is smaller than the former, then upper elements will + be destructed (and their memory freed). If the new length is greater + than the former, then upper (new) elements are default constructed. + If the sequence has a handle acquired by other sequences + (reference count > 1), then the remaining elements are copy constructed + to a new sequence handle to keep value semantics! + + @param nSize new size of sequence + */ + inline void SAL_CALL realloc( sal_Int32 nSize ); + + /** Provides UNacquired sequence handle. + + @return UNacquired sequence handle + */ + inline uno_Sequence * SAL_CALL get() const SAL_THROW( () ) + { return _pSequence; } +}; + +/** Creates a UNO byte sequence from a SAL byte sequence. + + @param rByteSequence a byte sequence + @return a UNO byte sequence +*/ +inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence( + const ::rtl::ByteSequence & rByteSequence ) SAL_THROW( () ); + +} +} +} +} + +/** Gets the meta type of IDL sequence. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @tplparam E element type of sequence + @param dummy typed pointer for function signature + @return type of IDL sequence +*/ +template< class E > +inline const ::com::sun::star::uno::Type & +SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< E > * ) + SAL_THROW( () ); + +/** Gets the meta type of IDL sequence. + This function has been introduced, because one cannot get the (templated) + cppu type out of C++ array types. Array types have special + getCppuArrayTypeN() functions. + + @attention + the given element type must be the same as the template argument type! + @tplparam E element type of sequence + @param rElementType element type of sequence + @return type of IDL sequence +*/ +template< class E > +inline const ::com::sun::star::uno::Type & +SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType ) + SAL_THROW( () ); + +/** Gets the meta type of IDL sequence< char >. + This function has been introduced due to ambiguities with unsigned short. + + @param dummy typed pointer for function signature + @return type of IDL sequence< char > +*/ +inline const ::com::sun::star::uno::Type & +SAL_CALL getCharSequenceCppuType() SAL_THROW( () ); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/Sequence.hxx b/cppu/inc/com/sun/star/uno/Sequence.hxx new file mode 100644 index 000000000000..8a9b43d1339e --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Sequence.hxx @@ -0,0 +1,310 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#define _COM_SUN_STAR_UNO_SEQUENCE_HXX_ + +#include "osl/diagnose.h" +#include "osl/interlck.h" +#include "com/sun/star/uno/Sequence.h" +#include "typelib/typedescription.h" +#include "uno/data.h" +#include "com/sun/star/uno/genfunc.hxx" +#include "cppu/unotype.hxx" + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +//______________________________________________________________________________ +template< class E > +typelib_TypeDescriptionReference * Sequence< E >::s_pType = 0; + +//______________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence() SAL_THROW( () ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); + ::uno_type_sequence_construct( + &_pSequence, rType.getTypeLibType(), + 0, 0, (uno_AcquireFunc)cpp_acquire ); + // no bad_alloc, because empty sequence is statically allocated in cppu +} + +//______________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW( () ) +{ + ::osl_incrementInterlockedCount( &rSeq._pSequence->nRefCount ); + _pSequence = rSeq._pSequence; +} + +//______________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence( + uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW( () ) + : _pSequence( pSequence ) +{ +} + +//______________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); +#if ! defined EXCEPTIONS_OFF + sal_Bool success = +#endif + ::uno_type_sequence_construct( + &_pSequence, rType.getTypeLibType(), + const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire ); +#if ! defined EXCEPTIONS_OFF + if (! success) + throw ::std::bad_alloc(); +#endif +} + +//______________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence( sal_Int32 len ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); +#if ! defined EXCEPTIONS_OFF + sal_Bool success = +#endif + ::uno_type_sequence_construct( + &_pSequence, rType.getTypeLibType(), + 0, len, (uno_AcquireFunc)cpp_acquire ); +#if ! defined EXCEPTIONS_OFF + if (! success) + throw ::std::bad_alloc(); +#endif +} + +//______________________________________________________________________________ +template< class E > +inline Sequence< E >::~Sequence() SAL_THROW( () ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); + ::uno_type_destructData( + this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release ); +} + +//______________________________________________________________________________ +template< class E > +inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW( () ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); + ::uno_type_sequence_assign( + &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release ); + return *this; +} + +//______________________________________________________________________________ +template< class E > +inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const + SAL_THROW( () ) +{ + if (_pSequence == rSeq._pSequence) + return sal_True; + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); + return ::uno_type_equalData( + const_cast< Sequence< E > * >( this ), rType.getTypeLibType(), + const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(), + (uno_QueryInterfaceFunc)cpp_queryInterface, + (uno_ReleaseFunc)cpp_release ); +} + +//______________________________________________________________________________ +template< class E > +inline sal_Bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const + SAL_THROW( () ) +{ + return (! operator == ( rSeq )); +} + +//______________________________________________________________________________ +template< class E > +inline E * Sequence< E >::getArray() +{ + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); +#if ! defined EXCEPTIONS_OFF + sal_Bool success = +#endif + ::uno_type_sequence_reference2One( + &_pSequence, rType.getTypeLibType(), + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); +#if ! defined EXCEPTIONS_OFF + if (! success) + throw ::std::bad_alloc(); +#endif + return reinterpret_cast< E * >( _pSequence->elements ); +} + +//______________________________________________________________________________ +template< class E > +inline E & Sequence< E >::operator [] ( sal_Int32 nIndex ) +{ + OSL_ENSURE( + nIndex >= 0 && nIndex < getLength(), + "### illegal index of sequence!" ); + return getArray()[ nIndex ]; +} + +//______________________________________________________________________________ +template< class E > +inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const + SAL_THROW( () ) +{ + OSL_ENSURE( + nIndex >= 0 && nIndex < getLength(), + "### illegal index of sequence!" ); + return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ]; +} + +//______________________________________________________________________________ +template< class E > +inline void Sequence< E >::realloc( sal_Int32 nSize ) +{ + const Type & rType = ::cppu::getTypeFavourUnsigned( this ); +#if !defined EXCEPTIONS_OFF + sal_Bool success = +#endif + ::uno_type_sequence_realloc( + &_pSequence, rType.getTypeLibType(), nSize, + (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); +#if !defined EXCEPTIONS_OFF + if (!success) + throw ::std::bad_alloc(); +#endif +} + +//------------------------------------------------------------------------------ +inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence( + const ::rtl::ByteSequence & rByteSequence ) SAL_THROW( () ) +{ + return ::com::sun::star::uno::Sequence< sal_Int8 >( + * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) ); +} + +} +} +} +} + +namespace cppu { + +template< typename T > inline ::com::sun::star::uno::Type const & +getTypeFavourUnsigned(::com::sun::star::uno::Sequence< T > const *) { + if (::com::sun::star::uno::Sequence< T >::s_pType == 0) { + ::typelib_static_sequence_type_init( + &::com::sun::star::uno::Sequence< T >::s_pType, + (::cppu::getTypeFavourUnsigned( + static_cast< + typename ::com::sun::star::uno::Sequence< T >::ElementType * >( + 0)). + getTypeLibType())); + } + return detail::getTypeFromTypeDescriptionReference( + &::com::sun::star::uno::Sequence< T >::s_pType); +} + +template< typename T > inline ::com::sun::star::uno::Type const & +getTypeFavourChar(::com::sun::star::uno::Sequence< T > const *) { + //TODO On certain platforms with weak memory models, the following code can + // result in some threads observing that td points to garbage: + static typelib_TypeDescriptionReference * td = 0; + if (td == 0) { + ::typelib_static_sequence_type_init( + &td, + (::cppu::getTypeFavourChar( + static_cast< + typename ::com::sun::star::uno::Sequence< T >::ElementType * >( + 0)). + getTypeLibType())); + } + return detail::getTypeFromTypeDescriptionReference(&td); +} + +} + +// generic sequence template +template< class E > +inline const ::com::sun::star::uno::Type & +SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< E > * ) + SAL_THROW( () ) +{ + return ::cppu::getTypeFavourUnsigned( + static_cast< ::com::sun::star::uno::Sequence< E > * >(0)); +} + +// generic sequence template for given element type (e.g. C++ arrays) +template< class E > +inline const ::com::sun::star::uno::Type & +SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType ) + SAL_THROW( () ) +{ + if (! ::com::sun::star::uno::Sequence< E >::s_pType) + { + ::typelib_static_sequence_type_init( + & ::com::sun::star::uno::Sequence< E >::s_pType, + rElementType.getTypeLibType() ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & ::com::sun::star::uno::Sequence< E >::s_pType ); +} + +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) +static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0; +#endif + +// char sequence +inline const ::com::sun::star::uno::Type & +SAL_CALL getCharSequenceCppuType() SAL_THROW( () ) +{ +#if !( defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) + static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0; +#endif + if (! s_pType_com_sun_star_uno_Sequence_Char) + { + const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType(); + ::typelib_static_sequence_type_init( + & s_pType_com_sun_star_uno_Sequence_Char, + rElementType.getTypeLibType() ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & s_pType_com_sun_star_uno_Sequence_Char ); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/Type.h b/cppu/inc/com/sun/star/uno/Type.h new file mode 100644 index 000000000000..6490fa4ab7f1 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Type.h @@ -0,0 +1,461 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_TYPE_H_ +#define _COM_SUN_STAR_UNO_TYPE_H_ + +#include <typelib/typedescription.h> +#ifndef _COM_SUN_STAR_UNO_TYPECLASS_HDL_ +#include <com/sun/star/uno/TypeClass.hdl> +#endif +#include <cppu/macros.hxx> +#include <rtl/ustring.hxx> +#include <rtl/alloc.h> + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** Enum defining UNO_TYPE_NO_ACQUIRE for type description reference transfer. +*/ +enum UnoType_NoAcquire +{ + /** This enum value can be used for creating a Type object granting a given type description + reference, i.e. transferring ownership to it. + */ + UNO_TYPE_NO_ACQUIRE +}; + +/** C++ class representing an IDL meta type. This class is used to represent a a type, + i.e. a type name and its type class. + Internally the type holds a C type description reference of the runtime. + You can obtain a full type description of a type by calling member function getDescription(). + + @see typelib_TypeDescriptionReference +*/ +class Type +{ + /** the C typelib reference pointer + @internal + */ + typelib_TypeDescriptionReference * _pType; + +public: + // these are here to force memory de/allocation to sal lib. + /** @internal */ + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) + { return ::rtl_allocateMemory( nSize ); } + /** @internal */ + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) + { ::rtl_freeMemory( pMem ); } + /** @internal */ + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) + { return pMem; } + /** @internal */ + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) + {} + + /** Default Constructor: Type is set to void. + */ + inline Type() SAL_THROW( () ); + + /** Constructor: Type is constructed by given name and type class. + + @param eTypeClass type class of type + @param rTypeName name of type + */ + inline Type( TypeClass eTypeClass, const ::rtl::OUString & rTypeName ) SAL_THROW( () ); + + /** Constructor: Type is constructed by given name and type class. + + @param eTypeClass type class of type + @param pTypeName name of type + */ + inline Type( TypeClass eTypeClass, const sal_Char * pTypeName ) SAL_THROW( () ); + + /** Constructor: Type is (copy) constructed by given C type description reference. + + @param pType C type description reference + */ + inline Type( typelib_TypeDescriptionReference * pType ) SAL_THROW( () ); + + /** Constructor: Type is (copy) constructed by given C type description reference + without acquiring it. + + @param pType C type description reference + @param dummy UNO_TYPE_NO_ACQUIRE to force obvious distinction to other constructors + */ + inline Type( typelib_TypeDescriptionReference * pType, UnoType_NoAcquire ) SAL_THROW( () ); + /** Constructor: Type is (copy) constructed by given C type description reference + without acquiring it. + + @param pType C type description reference + @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors + */ + inline Type( typelib_TypeDescriptionReference * pType, __sal_NoAcquire ) SAL_THROW( () ); + + /** Copy constructor: Type is copy constructed by given type. + + @param rType another type + */ + inline Type( const Type & rType ) SAL_THROW( () ); + + /** Destructor: Releases acquired C type description reference. + */ + inline ~Type() SAL_THROW( () ) + { ::typelib_typedescriptionreference_release( _pType ); } + + /** Assignment operator: Acquires right side type and releases previously set type. + + @param rType another type (right side) + @return this type + */ + inline Type & SAL_CALL operator = ( const Type & rType ) SAL_THROW( () ); + + /** Gets the type class of set type. + + @return type class of set type + */ + inline TypeClass SAL_CALL getTypeClass() const SAL_THROW( () ) + { return (TypeClass)_pType->eTypeClass; } + + /** Gets the name of the set type. + + @return name of the set type + */ + inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW( () ); + + /** Obtains a full type description of set type. + + @param ppDescr [inout] type description + */ + inline void SAL_CALL getDescription( typelib_TypeDescription ** ppDescr ) const SAL_THROW( () ) + { ::typelib_typedescriptionreference_getDescription( ppDescr, _pType ); } + + /** Gets the C typelib type description reference pointer. Does not acquire the reference! + + @return UNacquired type description reference + */ + inline typelib_TypeDescriptionReference * SAL_CALL getTypeLibType() const SAL_THROW( () ) + { return _pType; } + + /** Tests if values of this reflected type can be assigned by values of given type. + This includes widening conversion (e.g., long assignable from short), as long as there + is no data loss. + + @param rType another type + @return true if values of this type can be assigned from values of given type, + false otherwise + */ + inline sal_Bool SAL_CALL isAssignableFrom( const Type & rType ) const SAL_THROW( () ) + { return ::typelib_typedescriptionreference_isAssignableFrom( _pType, rType._pType ); } + + /** Compares two types. + + @param rType another type + @return true if both types refer the same type, false otherwise + */ + inline sal_Bool SAL_CALL equals( const Type & rType ) const SAL_THROW( () ) + { return ::typelib_typedescriptionreference_equals( _pType, rType._pType ); } + /** Equality operator: Compares two types. + + @param rType another type + @return true if both types refer the same type, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( const Type & rType ) const SAL_THROW( () ) + { return ::typelib_typedescriptionreference_equals( _pType, rType._pType ); } + /** Unequality operator: Compares two types. + + @param rType another type + @return false if both types refer the same type, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( const Type & rType ) const SAL_THROW( () ) + { return (! ::typelib_typedescriptionreference_equals( _pType, rType._pType )); } +}; + +/** Helper class to specify a type pointer for idl arrays. +*/ +template< class T > +class Array +{ +public: + static typelib_TypeDescriptionReference * s_pType; +}; + +} +} +} +} + +/** Gets the meta type of IDL type "type". + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type "type" +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Type * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type void. + @return type of IDL type void +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuVoidType() SAL_THROW( () ); +/** Gets the meta type of IDL type void. + + @return type of IDL type void +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getVoidCppuType() SAL_THROW( () ); + +/** Gets the meta type of IDL type boolean. + + @return type of IDL type boolean +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuBooleanType() SAL_THROW( () ); +/** Gets the meta type of IDL type boolean. + + @return type of IDL type boolean +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getBooleanCppuType() SAL_THROW( () ); +/** Gets the meta type of IDL type boolean. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type boolean +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Bool * ) SAL_THROW( () ); +/** Gets the meta type of IDL type boolean. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type boolean +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( + bool const * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type char. + + @return type of IDL type char +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCharCppuType() SAL_THROW( () ); +/** Gets the meta type of IDL type char. + + @return type of IDL type char +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuCharType() SAL_THROW( () ); + +/** Gets the meta type of IDL type byte. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type byte +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int8 * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type string. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type string +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::rtl::OUString * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type short. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type short +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int16 * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type unsigned short. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type unsigned short +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt16 * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type long. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type long +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int32 * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type unsigned long. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type unsigned long +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt32 * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type hyper. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type hyper +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int64 * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type unsigned hyper. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type unsigned hyper +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt64 * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type float. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type float +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const float * ) SAL_THROW( () ); + +/** Gets the meta type of IDL type double. + + There are cases (involving templates) where uses of getCppuType are known to + not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead. + + @param dummy typed pointer for function signature + @return type of IDL type double +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const double * ) SAL_THROW( () ); + +/** Array template function to get meta type for one-dimensional arrays. + + @param pT array pointer + @return type of array +*/ +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType1( T * pT ) SAL_THROW( () ); +/** Array template function to get meta type for two-dimensional arrays. + + @param pT array pointer + @return type of array +*/ +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType2( T * pT ) SAL_THROW( () ); +/** Array template function to get meta type for three-dimensional arrays. + + @param pT array pointer + @return type of array +*/ +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType3( T * pT ) SAL_THROW( () ); +/** Array template function to get meta type for four-dimensional arrays. + + @param pT array pointer + @return type of array +*/ +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType4( T * pT ) SAL_THROW( () ); +/** Array template function to get meta type for five-dimensional arrays. + + @param pT array pointer + @return type of array +*/ +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType5( T * pT ) SAL_THROW( () ); +/** Array template function to get meta type for six-dimensional arrays. + + @param pT array pointer + @return type of array +*/ +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType6( T * pT ) SAL_THROW( () ); + +/** Gets the meta type of an IDL type. + + The difference between this function template (with a type parameter) and + the overloaded getCppuType function with a single (dummy) parameter of a + specific type is that this function template may not work for the UNO type + "unsigned short" (sal_uInt16 in C++), while the overloaded one-parameter + function may not work for the UNO type "char" (sal_Unicode in C++, which may + have the same underlying C++ type as sal_uInt16 on certain platforms). + + @return type of the given IDL type + + @deprecated + Use cppu::UnoType instead (or the internal-only cppu::getTypeFavourChar). + Also note that getCppuType< com::sun::star::uno::Sequence< sal_Unicode > >() + does not work as expected. + + @since UDK 3.2.0 +*/ +template< typename T > inline const ::com::sun::star::uno::Type & SAL_CALL +getCppuType() SAL_THROW(()); + +/** Gets the meta type of IDL type char. + + @return type of IDL type char + + @deprecated + Use cppu::UnoType instead (or the internal-only cppu::getTypeFavourChar). + Also note that getCppuType< com::sun::star::uno::Sequence< sal_Unicode > >() + does not work as expected. + + @since UDK 3.2.0 +*/ +template<> inline const ::com::sun::star::uno::Type & SAL_CALL +getCppuType< sal_Unicode >() SAL_THROW(()); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/Type.hxx b/cppu/inc/com/sun/star/uno/Type.hxx new file mode 100644 index 000000000000..46fd86329424 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Type.hxx @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#define _COM_SUN_STAR_UNO_TYPE_HXX_ + +#include <osl/mutex.hxx> +#include <com/sun/star/uno/Type.h> +#include "cppu/unotype.hxx" + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +//__________________________________________________________________________________________________ +inline Type::Type() SAL_THROW( () ) +{ + _pType = reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID ) )->getTypeLibType(); + ::typelib_typedescriptionreference_acquire( _pType ); +} +//__________________________________________________________________________________________________ +inline Type::Type( TypeClass eTypeClass, const ::rtl::OUString & rTypeName ) SAL_THROW( () ) + : _pType( 0 ) +{ + ::typelib_typedescriptionreference_new( &_pType, (typelib_TypeClass)eTypeClass, rTypeName.pData ); +} +//__________________________________________________________________________________________________ +inline Type::Type( TypeClass eTypeClass, const sal_Char * pTypeName ) SAL_THROW( () ) + : _pType( 0 ) +{ + ::typelib_typedescriptionreference_newByAsciiName( &_pType, (typelib_TypeClass)eTypeClass, pTypeName ); +} +//__________________________________________________________________________________________________ +inline Type::Type( typelib_TypeDescriptionReference * pType ) SAL_THROW( () ) + : _pType( pType ) +{ + ::typelib_typedescriptionreference_acquire( _pType ); +} +//__________________________________________________________________________________________________ +inline Type::Type( typelib_TypeDescriptionReference * pType, UnoType_NoAcquire ) SAL_THROW( () ) + : _pType( pType ) +{ +} +//__________________________________________________________________________________________________ +inline Type::Type( typelib_TypeDescriptionReference * pType, __sal_NoAcquire ) SAL_THROW( () ) + : _pType( pType ) +{ +} +//__________________________________________________________________________________________________ +inline Type::Type( const Type & rType ) SAL_THROW( () ) + : _pType( rType._pType ) +{ + ::typelib_typedescriptionreference_acquire( _pType ); +} +//__________________________________________________________________________________________________ +inline ::rtl::OUString Type::getTypeName() const SAL_THROW( () ) +{ + return ::rtl::OUString( _pType->pTypeName ); +} +//__________________________________________________________________________________________________ +inline Type & Type::operator = ( const Type & rType ) SAL_THROW( () ) +{ + ::typelib_typedescriptionreference_assign( &_pType, rType._pType ); + return *this; +} + +//__________________________________________________________________________________________________ +template< class T > +typelib_TypeDescriptionReference * Array< T >::s_pType = 0; + +} +} +} +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Type * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::com::sun::star::uno::Type >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuVoidType() SAL_THROW( () ) +{ + return ::cppu::UnoType< ::cppu::UnoVoidType >::get(); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getVoidCppuType() SAL_THROW( () ) +{ + return ::cppu::UnoType< ::cppu::UnoVoidType >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuBooleanType() SAL_THROW( () ) +{ + return ::cppu::UnoType< bool >::get(); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getBooleanCppuType() SAL_THROW( () ) +{ + return ::cppu::UnoType< bool >::get(); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Bool * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< bool >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( + bool const * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< bool >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCharCppuType() SAL_THROW( () ) +{ + return ::cppu::UnoType< ::cppu::UnoCharType >::get(); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuCharType() SAL_THROW( () ) +{ + return ::cppu::UnoType< ::cppu::UnoCharType >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int8 * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::sal_Int8 >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::rtl::OUString * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::rtl::OUString >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int16 * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::sal_Int16 >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt16 * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int32 * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::sal_Int32 >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt32 * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::sal_uInt32 >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int64 * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::sal_Int64 >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt64 * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< ::sal_uInt64 >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const float * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< float >::get(); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const double * ) SAL_THROW( () ) +{ + return ::cppu::UnoType< double >::get(); +} + +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType1( T * pT ) SAL_THROW( () ) +{ + if (! ::com::sun::star::uno::Array< T >::s_pType) + { + const ::com::sun::star::uno::Type & rElementType = + ::cppu::getTypeFavourUnsigned( *pT ); + sal_Int32 size = sizeof( **pT ); + sal_Int32 dim1 = sizeof( *pT ) / size; + ::typelib_static_array_type_init( + & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(), + 1, dim1 ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & ::com::sun::star::uno::Array< T >::s_pType ); +} + +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType2( T * pT ) SAL_THROW( () ) +{ + if (! ::com::sun::star::uno::Array< T >::s_pType) + { + const ::com::sun::star::uno::Type & rElementType = + ::cppu::getTypeFavourUnsigned( **pT ); + sal_Int32 size = sizeof( ***pT ); + sal_Int32 dim2 = sizeof( **pT ) / size; + sal_Int32 dim1 = sizeof( *pT ) / dim2 / size; + ::typelib_static_array_type_init( + & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(), + 2, dim1, dim2 ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & ::com::sun::star::uno::Array< T >::s_pType ); +} + +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType3( T * pT ) SAL_THROW( () ) +{ + if (! ::com::sun::star::uno::Array< T >::s_pType) + { + const ::com::sun::star::uno::Type & rElementType = + ::cppu::getTypeFavourUnsigned( ***pT ); + sal_Int32 size = sizeof( ****pT ); + sal_Int32 dim3 = sizeof( ***pT ) / size; + sal_Int32 dim2 = sizeof( **pT ) / dim3 / size; + sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3)/ size; + ::typelib_static_array_type_init( + & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(), + 3, dim1, dim2, dim3 ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & ::com::sun::star::uno::Array< T >::s_pType ); +} + +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType4( T * pT ) SAL_THROW( () ) +{ + if (! ::com::sun::star::uno::Array< T >::s_pType) + { + const ::com::sun::star::uno::Type & rElementType = + ::cppu::getTypeFavourUnsigned( ****pT ); + sal_Int32 size = sizeof( *****pT ); + sal_Int32 dim4 = sizeof( ****pT ) / size; + sal_Int32 dim3 = sizeof( ***pT ) / dim4 / size; + sal_Int32 dim2 = sizeof( **pT ) / (dim3 * dim4) / size; + sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3 * dim4) / size; + ::typelib_static_array_type_init( + & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(), + 4, dim1, dim2, dim3, dim4 ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & ::com::sun::star::uno::Array< T >::s_pType ); +} + +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType5( T * pT ) SAL_THROW( () ) +{ + if (! ::com::sun::star::uno::Array< T >::s_pType) + { + const ::com::sun::star::uno::Type & rElementType = + ::cppu::getTypeFavourUnsigned( *****pT ); + sal_Int32 size = sizeof( ******pT ); + sal_Int32 dim5 = sizeof( *****pT ) / size; + sal_Int32 dim4 = sizeof( ****pT ) / dim5 / size; + sal_Int32 dim3 = sizeof( ***pT ) / (dim4 * dim5) / size; + sal_Int32 dim2 = sizeof( **pT ) / (dim3 * dim4 * dim5) / size; + sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3 * dim4 * dim5) / size; + ::typelib_static_array_type_init( + & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(), + 5, dim1, dim2, dim3, dim4, dim5 ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & ::com::sun::star::uno::Array< T >::s_pType ); +} + +template< class T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType6( T * pT ) SAL_THROW( () ) +{ + if (! ::com::sun::star::uno::Array< T >::s_pType) + { + const ::com::sun::star::uno::Type & rElementType = + ::cppu::getTypeFavourUnsigned( ******pT ); + sal_Int32 size = sizeof( *******pT ); + sal_Int32 dim6 = sizeof( ******pT ) / size; + sal_Int32 dim5 = sizeof( *****pT ) / dim6 / size; + sal_Int32 dim4 = sizeof( ****pT ) / (dim5 * dim6) / size; + sal_Int32 dim3 = sizeof( ***pT ) / (dim4 * dim5 * dim6) / size; + sal_Int32 dim2 = sizeof( **pT ) / (dim3 * dim4 * dim5 * dim6) / size; + sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3 * dim4 * dim5 * dim6) / size; + ::typelib_static_array_type_init( + & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(), + 6, dim1, dim2, dim3, dim4, dim5, dim6 ); + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + & ::com::sun::star::uno::Array< T >::s_pType ); +} + +template< typename T > +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType() SAL_THROW(()) +{ + return ::cppu::UnoType< T >::get(); +} + +template<> +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType< sal_Unicode >() + SAL_THROW(()) +{ + return ::cppu::UnoType< ::cppu::UnoCharType >::get(); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/genfunc.h b/cppu/inc/com/sun/star/uno/genfunc.h new file mode 100644 index 000000000000..1b0dbd2c4cce --- /dev/null +++ b/cppu/inc/com/sun/star/uno/genfunc.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_GENFUNC_H_ +#define _COM_SUN_STAR_UNO_GENFUNC_H_ + +#include "sal/types.h" + +typedef struct _typelib_TypeDescriptionReference typelib_TypeDescriptionReference; + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** Function to acquire a C++ interface. + + @param pCppI C++ interface pointer +*/ +inline void SAL_CALL cpp_acquire( void * pCppI ) + SAL_THROW( () ); +/** Function to release a C++ interface. + + @param pCppI C++ interface pointer +*/ +inline void SAL_CALL cpp_release( void * pCppI ) + SAL_THROW( () ); +/** Function to query for a C++ interface. + + @param pCppI C++ interface pointer + @param pType demanded interface type + @return acquired C++ interface pointer or null +*/ +inline void * SAL_CALL cpp_queryInterface( void * pCppI, typelib_TypeDescriptionReference * pType ) + SAL_THROW( () ); + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/com/sun/star/uno/genfunc.hxx b/cppu/inc/com/sun/star/uno/genfunc.hxx new file mode 100644 index 000000000000..88234bd81389 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/genfunc.hxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_GENFUNC_HXX_ +#define _COM_SUN_STAR_UNO_GENFUNC_HXX_ + +#include <com/sun/star/uno/genfunc.h> +#include <com/sun/star/uno/Any.hxx> + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +//================================================================================================== +inline void SAL_CALL cpp_acquire( void * pCppI ) + SAL_THROW( () ) +{ + reinterpret_cast< XInterface * >( pCppI )->acquire(); +} +//================================================================================================== +inline void SAL_CALL cpp_release( void * pCppI ) + SAL_THROW( () ) +{ + reinterpret_cast< XInterface * >( pCppI )->release(); +} +//================================================================================================== +inline void * SAL_CALL cpp_queryInterface( void * pCppI, typelib_TypeDescriptionReference * pType ) + SAL_THROW( () ) +{ + if (pCppI) + { +#ifndef EXCEPTIONS_OFF + try + { +#endif + Any aRet( reinterpret_cast< XInterface * >( pCppI )->queryInterface( + * reinterpret_cast< const Type * >( &pType ) ) ); + if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass) + { + XInterface * pRet = reinterpret_cast< XInterface * >( aRet.pReserved ); + aRet.pReserved = 0; + return pRet; + } +#ifndef EXCEPTIONS_OFF + } + catch (RuntimeException &) + { + } +#endif + } + return 0; +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/cppu/Enterable.hxx b/cppu/inc/cppu/Enterable.hxx new file mode 100644 index 000000000000..5ccfb9c4e2fb --- /dev/null +++ b/cppu/inc/cppu/Enterable.hxx @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#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.services.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 (void) = 0; + virtual void v_leave (void) = 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 int v_isValid (rtl::OUString * pReason) = 0; + + virtual ~Enterable() {} + +public: + inline explicit Enterable(void); + + inline void enter(void) {m_enter(this);} + inline void leave(void) {m_leave(this);} + + inline void callInto_v(uno_EnvCallee * pCallee, va_list * pParam) {m_callInto_v(this, pCallee, pParam);} + inline 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, ...); + + inline int isValid (rtl::OUString * pReason) {return m_isValid(this, (rtl_uString **)pReason);} + +private: + Enterable(Enterable const &); + Enterable & operator = (Enterable const &); +}; + +extern "C" inline void Enterable_call_enter (void * context) { ((Enterable *)context)->v_enter(); } +extern "C" inline void Enterable_call_leave (void * context) { ((Enterable *)context)->v_leave(); } +extern "C" inline void Enterable_call_callInto_v(void * context, uno_EnvCallee * pCallee, va_list * pParam) + { ((Enterable *)context)->v_callInto_v(pCallee, pParam); } +extern "C" inline void Enterable_call_callOut_v (void * context, uno_EnvCallee * pCallee, va_list * pParam) + { ((Enterable *)context)->v_callOut_v(pCallee, pParam); } +extern "C" inline int Enterable_call_isValid (void * context, rtl_uString ** pReason) + {return ((Enterable *)context)->v_isValid((rtl::OUString *)pReason);} + + +Enterable::Enterable(void) +{ + 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/cppu/inc/cppu/EnvDcp.hxx b/cppu/inc/cppu/EnvDcp.hxx new file mode 100644 index 000000000000..68adf63017c3 --- /dev/null +++ b/cppu/inc/cppu/EnvDcp.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#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.services.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.services.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/cppu/inc/cppu/EnvGuards.hxx b/cppu/inc/cppu/EnvGuards.hxx new file mode 100644 index 000000000000..07f65b2aced9 --- /dev/null +++ b/cppu/inc/cppu/EnvGuards.hxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_cppu_EnvGuards_hxx +#define INCLUDED_cppu_EnvGuards_hxx + +#include "uno/environment.hxx" +#include "uno/mapping.hxx" + + +namespace cssuno = com::sun::star::uno; + + +namespace cppu +{ + /** Environment Guard + The provided Environment becomes entered in the constructor and left + in the destructor. + (http://wiki.services.openoffice.org/wiki/Uno/Cpp/Spec/Environment_Guard) + + @since UDK 3.2.7 + */ + class EnvGuard + { + cssuno::Environment m_env; + + public: + explicit EnvGuard(cssuno::Environment const & env) + { + if (env.is()) + { + m_env = cssuno::Environment::getCurrent(); + env.enter(); + } + } + + ~EnvGuard() + { + m_env.enter(); + } + + /** Checks if the associated environment is non empty. + + @return 0 == empty, 1 == non empty + */ + sal_Bool SAL_CALL is() const SAL_THROW( () ) + { + 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.services.openoffice.org/wiki/Uno/Cpp/Spec/Environment_AntiGuard) + + @since UDK 3.2.7 + */ + class AntiEnvGuard + { + cssuno::Environment m_env; + + public: + explicit AntiEnvGuard() + : m_env(cssuno::Environment::getCurrent()) + { + uno_Environment_enter(NULL); + } + + ~AntiEnvGuard() + { + m_env.enter(); + } + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/cppu/FreeReference.hxx b/cppu/inc/cppu/FreeReference.hxx new file mode 100644 index 000000000000..5a8d22175921 --- /dev/null +++ b/cppu/inc/cppu/FreeReference.hxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_cppu_FreeReference_hxx +#define INCLUDED_cppu_FreeReference_hxx + +#include "uno/environment.hxx" +#include "cppu/Map.hxx" +#include "com/sun/star/uno/Reference.h" + + +namespace cssuno = com::sun::star::uno; + + +namespace cppu +{ + /** Freely (environment independent) usable Reference. + (http://wiki.services.openoffice.org/wiki/Uno/Cpp/Spec/FreeReference) + + @since UDK 3.2.7 + */ + template< class T > + class FreeReference + { + cssuno::Environment m_env; + T * m_pObject; + + public: + FreeReference() : m_pObject(NULL) {} + + FreeReference(T * pObject, __sal_NoAcquire) + : m_env(cssuno::Environment::getCurrent()), + m_pObject(pObject) + { + } + + FreeReference(T * pObject) + : m_env(cssuno::Environment::getCurrent()), + m_pObject(pObject) + { + if (m_pObject) + m_env.get()->pExtEnv->acquireInterface(m_env.get()->pExtEnv, m_pObject); + } + + explicit FreeReference(cssuno::Reference<T> const & xRef) + : m_env(cssuno::Environment::getCurrent()), + m_pObject(xRef.get()) + { + if (m_pObject) + m_env.get()->pExtEnv->acquireInterface(m_env.get()->pExtEnv, m_pObject); + } + + FreeReference(FreeReference<T> const & rOther) + : m_env (rOther.m_env), + m_pObject(rOther.m_pObject) + { + if (m_pObject) + m_env.get()->pExtEnv->acquireInterface(m_env.get()->pExtEnv, m_pObject); + } + + + ~FreeReference() + { + clear(); + } + + cssuno::Environment getEnv() const throw (cssuno::RuntimeException) + { + return m_env; + } + + cssuno::Reference<T> get() const throw (cssuno::RuntimeException) + { + return cssuno::Reference<T>(cppu::mapIn(m_pObject, m_env), SAL_NO_ACQUIRE); + } + + operator cssuno::Reference<T> () const throw (cssuno::RuntimeException) + { + return get(); + } + + cssuno::Reference<T> operator -> () const throw (cssuno::RuntimeException) + { + return get(); + } + + bool is() const throw (cssuno::RuntimeException) + { + return m_pObject != NULL; + } + + void clear() + { + if (m_pObject) + { + + m_env.get()->pExtEnv->releaseInterface(m_env.get()->pExtEnv, m_pObject); + m_pObject = NULL; + m_env.clear(); + } + } + + FreeReference<T> & operator = (FreeReference<T> const & rOther) + { + clear(); + + m_pObject = rOther.m_pObject; + if (m_pObject) + { + m_env = rOther.m_env; + m_env.get()->pExtEnv->acquireInterface(m_env.get()->pExtEnv, m_pObject); + } + + return *this; + } + + void set(cssuno::Reference<T> const & xRef) + { + clear(); + + m_pObject = xRef.get(); + if (m_pObject) + { + m_env = cssuno::Environment::getCurrent(); + + m_env.get()->pExtEnv->acquireInterface(m_env.get()->pExtEnv, m_pObject); + } + } + + bool operator == (FreeReference const & rOther) const + { + return get() == rOther.get(); + } + + bool operator != (FreeReference const & rOther) const + { + return !operator==(rOther); + } + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/cppu/Map.hxx b/cppu/inc/cppu/Map.hxx new file mode 100644 index 000000000000..a5922f830b5d --- /dev/null +++ b/cppu/inc/cppu/Map.hxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_cppu_Map_hxx +#define INCLUDED_cppu_Map_hxx + +#include <uno/mapping.hxx> + + +namespace cssu = com::sun::star::uno; + +namespace cppu +{ + /** Helpers for mapping objects relative to the current environment. + (http://wiki.services.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, cssu::Environment const & outerEnv) + { + cssu::Mapping curr2outer(cssu::Environment::getCurrent(), outerEnv); + + return reinterpret_cast<T *>(curr2outer.mapInterface(pT, getCppuType((cssu::Reference<T> *)NULL))); + } + + + /** 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, cssu::Environment const & outerEnv) + { + cssu::Mapping outer2curr(outerEnv, cssu::Environment::getCurrent()); + + return reinterpret_cast<T *>(outer2curr.mapInterface(pT, getCppuType((cssu::Reference<T> *)NULL))); + } + + + /** 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(cssu::Any const & any, cssu::Any * res, cssu::Environment const & outerEnv) + { + cssu::Mapping curr2outer(cssu::Environment::getCurrent(), outerEnv); + + uno_any_destruct(res, (uno_ReleaseFunc)cssu::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(cssu::Any const & any, cssu::Any * res, cssu::Environment const & outerEnv) + { + cssu::Mapping outer2curr(outerEnv, cssu::Environment::getCurrent()); + + uno_any_destruct(res, (uno_ReleaseFunc)cssu::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/cppu/inc/cppu/Shield.hxx b/cppu/inc/cppu/Shield.hxx new file mode 100644 index 000000000000..1e7221a210d3 --- /dev/null +++ b/cppu/inc/cppu/Shield.hxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_cppu_Shield_hxx +#define INCLUDED_cppu_Shield_hxx + +#include <cppu/Map.hxx> + + +namespace cssu = com::sun::star::uno; + +namespace cppu +{ + /** Helpers for mapping objects relative to the thread-safe and current environments. + (http://wiki.services.openoffice.org/wiki/Uno/Cpp/Spec/Shield_Helpers) + */ + + + /** Maps an object from the current to the thread-safe Environment, returns mapped object. + + @param pT the object to be mapped + @return the mapped object + @since UDK 3.2.7 + */ + template<class T> inline T * shield(T * pT) + { + return mapOut(pT, cssu::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))))); + } + + /** Maps an object from the thread-safe Environment to the current one, returns mapped object. + + @param pT the object to be mapped + @return the mapped object + @since UDK 3.2.7 + */ + template<class T> inline T * unshield(T * pT) + { + return mapIn(pT, cssu::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))))); + } + + + /** Maps an any from the current to the thread-safe Environment, fills the passed any. + + @param any the any to be mapped + @param the target any + @since UDK 3.2.7 + */ + inline void shieldAny(cssu::Any const & any, cssu::Any * res) + { + mapOutAny(any, res, cssu::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))))); + } + + + /** Maps an any from the thread-safe Environment to the current one, fills the passed any. + + @param any the any to be mapped + @param the target any + @since UDK 3.2.7 + */ + inline void unshieldAny(cssu::Any const & any, cssu::Any * res) + { + mapInAny(any, res, cssu::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))))); + } +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/cppu/helper/purpenv/Environment.hxx b/cppu/inc/cppu/helper/purpenv/Environment.hxx new file mode 100644 index 000000000000..25c9de8e8a6e --- /dev/null +++ b/cppu/inc/cppu/helper/purpenv/Environment.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_cppu_helper_purpenv_Environment_hxx +#define INCLUDED_cppu_helper_purpenv_Environment_hxx + +#include "uno/environment.h" +#include "cppu/Enterable.hxx" + + +namespace cppu { namespace helper { namespace purpenv { + +/** C++ helper for implementing Purpose Environments. + (http://wiki.services.openoffice.org/wiki/Uno/Cpp/Spec/Purpose_Bridge_Implementation_Helper) + + @since UDK 3.2.7 +*/ +void Environment_initWithEnterable(uno_Environment * pEnvironment, cppu::Enterable * pEnterable); + +}}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/cppu/helper/purpenv/Mapping.hxx b/cppu/inc/cppu/helper/purpenv/Mapping.hxx new file mode 100644 index 000000000000..6bdcd207987f --- /dev/null +++ b/cppu/inc/cppu/helper/purpenv/Mapping.hxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_cppu_helper_purpenv_Mapping_hxx +#define INCLUDED_cppu_helper_purpenv_Mapping_hxx + +#include "com/sun/star/uno/Any.h" + +#include "uno/environment.h" +#include "uno/mapping.h" + + +namespace cppu { namespace helper { namespace purpenv { + +/** C++ helper for implementing Purpose Environments. + (http://wiki.services.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 ); + + + +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/cppu/inc/cppu/macros.hxx b/cppu/inc/cppu/macros.hxx new file mode 100644 index 000000000000..5c123e7aecd9 --- /dev/null +++ b/cppu/inc/cppu/macros.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _CPPU_MACROS_HXX_ +#define _CPPU_MACROS_HXX_ + +#include <sal/types.h> +#include <uno/lbnames.h> + +/** Namespace name for compiler/ platform, e.g. gcc3, msci */ +#define CPPU_CURRENT_NAMESPACE CPPU_ENV + +/** Patching the GCC 3 incomatible 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.) + + @internal +*/ +#if defined(__GNUC__) && (__GNUC__ >= 3) +#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. + + @internal +*/ +#define CPPU_GCC_DLLPUBLIC_EXPORT SAL_EXCEPTION_DLLPUBLIC_EXPORT +#define CPPU_GCC_DLLPRIVATE SAL_EXCEPTION_DLLPRIVATE + +#endif // _CPPU_MACROS_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/cppu/unotype.hxx b/cppu/inc/cppu/unotype.hxx new file mode 100644 index 000000000000..b8df4e07a1b0 --- /dev/null +++ b/cppu/inc/cppu/unotype.hxx @@ -0,0 +1,380 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_CPPU_UNOTYPE_HXX +#define INCLUDED_CPPU_UNOTYPE_HXX + +#include "sal/config.h" +#include "com/sun/star/uno/Type.h" +#include "sal/types.h" +#include "typelib/typeclass.h" +#include "typelib/typedescription.h" + +namespace com { namespace sun { namespace star { namespace uno { + 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 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 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 ::com::sun::star::uno::Type const & getTypeFromTypeDescriptionReference( + ::typelib_TypeDescriptionReference * const * tdr) +{ + return *reinterpret_cast< ::com::sun::star::uno::Type const * >(tdr); +} + +inline ::com::sun::star::uno::Type const & +getTypeFromTypeClass(::typelib_TypeClass tc) { + return getTypeFromTypeDescriptionReference( + ::typelib_static_type_getByTypeClass(tc)); +} + +} + +} + +// For _MSC_VER 1310, define cppu_detail_getUnoType in the global namespace, to +// avoid spurious compiler errors in code that calls cppu_detail_getUnoType: +#if !defined _MSC_VER || _MSC_VER > 1310 +namespace cppu { namespace detail { +#endif + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::cppu::UnoVoidType const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_VOID); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(bool const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::sal_Bool const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BOOLEAN); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::sal_Int8 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_BYTE); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::sal_Int16 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_SHORT); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::cppu::UnoUnsignedShortType const *) { + return ::cppu::detail::getTypeFromTypeClass( + ::typelib_TypeClass_UNSIGNED_SHORT); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::sal_Int32 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_LONG); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::sal_uInt32 const *) { + return ::cppu::detail::getTypeFromTypeClass( + ::typelib_TypeClass_UNSIGNED_LONG); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::sal_Int64 const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_HYPER); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::sal_uInt64 const *) { + return ::cppu::detail::getTypeFromTypeClass( + ::typelib_TypeClass_UNSIGNED_HYPER); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(float const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_FLOAT); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(double const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_DOUBLE); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::cppu::UnoCharType const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_CHAR); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::rtl::OUString const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_STRING); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::com::sun::star::uno::Type const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_TYPE); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::com::sun::star::uno::Any const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_ANY); +} + +template< typename T > inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::cppu::UnoSequenceType< T > const *) { + //TODO: depending on memory model, the following might not work reliably + static typelib_TypeDescriptionReference * p = 0; + if (p == 0) { + ::typelib_static_sequence_type_init( + &p, ::cppu::UnoType< T >::get().getTypeLibType()); + } + return ::cppu::detail::getTypeFromTypeDescriptionReference(&p); +} + +template< typename T > inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::com::sun::star::uno::Sequence< T > const *) { + return cppu_detail_getUnoType( + static_cast< ::cppu::UnoSequenceType< T > * >(0)); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::com::sun::star::uno::Exception const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_EXCEPTION); +} + +inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::com::sun::star::uno::XInterface const *) { + return ::cppu::detail::getTypeFromTypeClass(::typelib_TypeClass_INTERFACE); +} + +template< typename T > inline ::com::sun::star::uno::Type const & +cppu_detail_getUnoType(::com::sun::star::uno::Reference< T > const *) { + return ::cppu::UnoType< T >::get(); +} + +#if !defined _MSC_VER || _MSC_VER > 1310 +} } +#endif + +namespace cppu { + +/** + Get the com::sun::star::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: 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 com::sun::star::uno::Reference with any appropriate template argument. + + @since UDK 3.2.2 +*/ +template< typename T > class UnoType { +public: + static inline ::com::sun::star::uno::Type const & get() { + using namespace ::cppu::detail; + return cppu_detail_getUnoType(static_cast< T * >(0)); + } + +private: + UnoType(UnoType &); // not defined + ~UnoType(); // not defined + void operator =(UnoType &); // not defined +}; + +/** + 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 ::com::sun::star::uno::Type const & +getTypeFavourUnsigned(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 ::com::sun::star::uno::Type const & +getTypeFavourUnsigned(::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 ::com::sun::star::uno::Type const & +getTypeFavourUnsigned(::com::sun::star::uno::Sequence< T > const *); + // defined in com/sun/star/uno/Sequence.hxx + +/** + 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. + + @internal + + @since UDK 3.2.3 +*/ +template< typename T > inline ::com::sun::star::uno::Type const & +getTypeFavourChar(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. + + @internal + + @since UDK 3.2.3 +*/ +inline ::com::sun::star::uno::Type const & +getTypeFavourChar(::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. + + @internal + + @since UDK 3.2.3 +*/ +template< typename T > inline ::com::sun::star::uno::Type const & +getTypeFavourChar(::com::sun::star::uno::Sequence< T > const *); + // defined in com/sun/star/uno/Sequence.hxx + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/makefile.mk b/cppu/inc/makefile.mk new file mode 100644 index 000000000000..47a2532efc68 --- /dev/null +++ b/cppu/inc/makefile.mk @@ -0,0 +1,48 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=.. + +PRJNAME=cppu +TARGET=inc + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + +.IF "$(ENABLE_PCH)"!="" +ALLTAR : \ + $(SLO)$/precompiled.pch \ + $(SLO)$/precompiled_ex.pch + +.ENDIF # "$(ENABLE_PCH)"!="" + diff --git a/cppu/inc/pch/precompiled_cppu.cxx b/cppu/inc/pch/precompiled_cppu.cxx new file mode 100644 index 000000000000..2a6a6cb94ae0 --- /dev/null +++ b/cppu/inc/pch/precompiled_cppu.cxx @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_cppu.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/pch/precompiled_cppu.hxx b/cppu/inc/pch/precompiled_cppu.hxx new file mode 100644 index 000000000000..c6624e57b5ca --- /dev/null +++ b/cppu/inc/pch/precompiled_cppu.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): Generated on 2006-09-01 17:49:37.030339 + +#ifdef PRECOMPILED_HEADERS +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/typelib/typeclass.h b/cppu/inc/typelib/typeclass.h new file mode 100644 index 000000000000..231c9d9f5fe3 --- /dev/null +++ b/cppu/inc/typelib/typeclass.h @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _TYPELIB_TYPECLASS_H_ +#define _TYPELIB_TYPECLASS_H_ + +#include <sal/types.h> + +/** This type class enum is binary compatible with the IDL enum com.sun.star.uno.TypeClass. +*/ +typedef enum _typelib_TypeClass +{ + /** type class of void */ + typelib_TypeClass_VOID = 0, + /** type class of char */ + typelib_TypeClass_CHAR = 1, + /** type class of boolean */ + typelib_TypeClass_BOOLEAN = 2, + /** type class of byte */ + typelib_TypeClass_BYTE = 3, + /** type class of short */ + typelib_TypeClass_SHORT = 4, + /** type class of unsigned short */ + typelib_TypeClass_UNSIGNED_SHORT = 5, + /** type class of long */ + typelib_TypeClass_LONG = 6, + /** type class of unsigned long */ + typelib_TypeClass_UNSIGNED_LONG = 7, + /** type class of hyper */ + typelib_TypeClass_HYPER = 8, + /** type class of unsigned hyper */ + typelib_TypeClass_UNSIGNED_HYPER = 9, + /** type class of float */ + typelib_TypeClass_FLOAT = 10, + /** type class of double */ + typelib_TypeClass_DOUBLE = 11, + /** type class of string */ + typelib_TypeClass_STRING = 12, + /** type class of type */ + typelib_TypeClass_TYPE = 13, + /** type class of any */ + typelib_TypeClass_ANY = 14, + /** type class of enum */ + typelib_TypeClass_ENUM = 15, + /** type class of typedef */ + typelib_TypeClass_TYPEDEF = 16, + /** type class of struct */ + typelib_TypeClass_STRUCT = 17, + /** type class of union (not implemented) */ + typelib_TypeClass_UNION = 18, + /** type class of exception */ + typelib_TypeClass_EXCEPTION = 19, + /** type class of sequence */ + typelib_TypeClass_SEQUENCE = 20, + /** type class of array (not implemented) */ + typelib_TypeClass_ARRAY = 21, + /** type class of interface */ + typelib_TypeClass_INTERFACE = 22, + /** type class of service (not implemented) */ + typelib_TypeClass_SERVICE = 23, + /** type class of module (not implemented) */ + typelib_TypeClass_MODULE = 24, + /** type class of interface method */ + typelib_TypeClass_INTERFACE_METHOD = 25, + /** type class of interface attribute */ + typelib_TypeClass_INTERFACE_ATTRIBUTE = 26, + /** type class of unknown type */ + typelib_TypeClass_UNKNOWN = 27, + /** type class of properties */ + typelib_TypeClass_PROPERTY = 28, + /** type class of constants */ + typelib_TypeClass_CONSTANT = 29, + /** type class of constants groups */ + typelib_TypeClass_CONSTANTS = 30, + /** type class of singletons */ + typelib_TypeClass_SINGLETON = 31, + /** fixing enum size */ + typelib_TypeClass_MAKE_FIXED_SIZE = SAL_MAX_ENUM +} typelib_TypeClass; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/typelib/typedescription.h b/cppu/inc/typelib/typedescription.h new file mode 100644 index 000000000000..a88894c723a7 --- /dev/null +++ b/cppu/inc/typelib/typedescription.h @@ -0,0 +1,1161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#define _TYPELIB_TYPEDESCRIPTION_H_ + +#include <sal/types.h> +#include <typelib/uik.h> +#include <typelib/typeclass.h> +#include <rtl/ustring.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescription; + +#if defined( SAL_W32) +#pragma pack(push, 8) +#endif + +/** Holds a weak reference to a type description. +*/ +typedef struct _typelib_TypeDescriptionReference +{ + /** reference count of type; don't ever modify this by yourself, use + typelib_typedescriptionreference_acquire() and typelib_typedescriptionreference_release() + */ + sal_Int32 nRefCount; + /** number of static references of type, because of the fact that some types are needed + until program termination and are commonly held static. + */ + sal_Int32 nStaticRefCount; + /** type class of type + */ + typelib_TypeClass eTypeClass; + /** fully qualified name of type + */ + rtl_uString * pTypeName; + /** pointer to full typedescription; this value is only valid if the type is never swapped out + */ + struct _typelib_TypeDescription * pType; + /** pointer to optimize the runtime; not for public use + */ + void * pUniqueIdentifier; + /** reserved for future use; 0 if not used + */ + void * pReserved; +} typelib_TypeDescriptionReference; + +/** Full type description of a type. Memory layout of this struct is identical to the + typelib_TypeDescriptionReference for the first six members. + So a typedescription can be used as type reference. +*/ +typedef struct _typelib_TypeDescription +{ + /** reference count; don't ever modify this by yourself, use + typelib_typedescription_acquire() and typelib_typedescription_release() + */ + sal_Int32 nRefCount; + /** number of static references of type, because of the fact that some types are needed + until program termination and are commonly held static. + */ + sal_Int32 nStaticRefCount; + /** type class of type + */ + typelib_TypeClass eTypeClass; + /** fully qualified name of type + */ + rtl_uString * pTypeName; + /** pointer to self to distinguish reference from description; for internal use only + */ + struct _typelib_TypeDescription * pSelf; + /** pointer to optimize the runtime; not for public use + */ + void * pUniqueIdentifier; + /** reserved for future use; 0 if not used + */ + void * pReserved; + + /** flag to determine whether the description is complete: + compound and union types lack of member names, enums lack of member types and names, + interfaces lack of members and table init. + Call typelib_typedescription_complete() if false. + */ + sal_Bool bComplete; + /** size of type + */ + sal_Int32 nSize; + /** alignment of type + */ + sal_Int32 nAlignment; + /** pointer to weak reference + */ + typelib_TypeDescriptionReference * pWeakRef; + /** determines, if type can be unloaded (and it is possible to reloaded it) + */ + sal_Bool bOnDemand; +} typelib_TypeDescription; + +/** Type description for exception types. +*/ +typedef struct _typelib_CompoundTypeDescription +{ + /** inherits all members of typelib_TypeDescription + */ + typelib_TypeDescription aBase; + + /** pointer to base type description, else 0 + */ + struct _typelib_CompoundTypeDescription * pBaseTypeDescription; + + /** number of members + */ + sal_Int32 nMembers; + /** byte offsets of each member including the size the base type + */ + sal_Int32 * pMemberOffsets; + /** members of the struct or exception + */ + typelib_TypeDescriptionReference ** ppTypeRefs; + /** member names of the struct or exception + */ + rtl_uString ** ppMemberNames; +} typelib_CompoundTypeDescription; + +/** + Type description for struct types. + + This is only used to represent plain struct types and instantiated + polymorphic struct types; there is no representation of polymorphic struct + type templates at this level. + + @since UDK 3.2.0 + */ +typedef struct _typelib_StructTypeDescription +{ + /** + Derived from typelib_CompoundTypeDescription. + */ + typelib_CompoundTypeDescription aBase; + + /** + Flags for direct members, specifying whether they are of parameterized + type (true) or explict type (false). + + For a plain struct type, this is a null pointer. + */ + sal_Bool * pParameterizedTypes; +} typelib_StructTypeDescription; + +/** Type description of a union. The type class of this description is typelib_TypeClass_UNION. +*/ +typedef struct _typelib_UnionTypeDescription +{ + /** inherits all members of typelib_TypeDescription + */ + typelib_TypeDescription aBase; + + /** type of the discriminant + */ + typelib_TypeDescriptionReference * pDiscriminantTypeRef; + + /** union default descriminant + */ + sal_Int64 nDefaultDiscriminant; + /** union default member type (may be 0) + */ + typelib_TypeDescriptionReference * pDefaultTypeRef; + /** number of union member types + */ + sal_Int32 nMembers; + /** union member discriminant values (same order as idl declaration) + */ + sal_Int64 * pDiscriminants; + /** union member value types (same order as idl declaration) + */ + typelib_TypeDescriptionReference ** ppTypeRefs; + /** union member value names (same order as idl declaration) + */ + rtl_uString ** ppMemberNames; + /** union value offset for data access + */ + sal_Int32 nValueOffset; +} typelib_UnionTypeDescription; + +/** Type description of an array or sequence. +*/ +typedef struct _typelib_IndirectTypeDescription +{ + /** inherits all members of typelib_TypeDescription + */ + typelib_TypeDescription aBase; + + /** array, sequence: pointer to element type + */ + typelib_TypeDescriptionReference * pType; +} typelib_IndirectTypeDescription; + +/** Type description of an array. +*/ +typedef struct _typelib_ArrayTypeDescription +{ + /** inherits all members of typelib_IndirectTypeDescription + */ + typelib_IndirectTypeDescription aBase; + + /** number of dimensions + */ + sal_Int32 nDimensions; + /** number of total array elements + */ + sal_Int32 nTotalElements; + /** array of dimensions + */ + sal_Int32 * pDimensions; +} typelib_ArrayTypeDescription; + +/** Type description of an enum. The type class of this description is typelib_TypeClass_ENUM. +*/ +typedef struct _typelib_EnumTypeDescription +{ + /** inherits all members of typelib_TypeDescription + */ + typelib_TypeDescription aBase; + + /** first value of the enum + */ + sal_Int32 nDefaultEnumValue; + /** number of enum values + */ + sal_Int32 nEnumValues; + /** names of enum values + */ + rtl_uString ** ppEnumNames; + /** values of enum (corresponding to names in similar order) + */ + sal_Int32 * pEnumValues; +} typelib_EnumTypeDescription; + +/** Description of an interface method parameter. +*/ +typedef struct _typelib_MethodParameter +{ + /** name of parameter + */ + rtl_uString * pName; + /** type of parameter + */ + typelib_TypeDescriptionReference * pTypeRef; + /** true: the call type of this parameter is [in] or [inout] + false: the call type of this parameter is [out] + */ + sal_Bool bIn; + /** true: the call type of this parameter is [out] or [inout] + false: the call type of this parameter is [in] + */ + sal_Bool bOut; +} typelib_MethodParameter; + +/** Common base type description of typelib_InterfaceMethodTypeDescription and + typelib_InterfaceAttributeTypeDescription. +*/ +typedef struct _typelib_InterfaceMemberTypeDescription +{ + /** inherits all members of typelib_TypeDescription + */ + typelib_TypeDescription aBase; + + /** position of member in the interface including the number of members of + any base interfaces + */ + sal_Int32 nPosition; + /** name of member + */ + rtl_uString * pMemberName; +} typelib_InterfaceMemberTypeDescription; + +/** Type description of an interface method. The type class of this description is + typelib_TypeClass_INTERFACE_METHOD. The size and the alignment are 0. +*/ +typedef struct _typelib_InterfaceMethodTypeDescription +{ + /** inherits all members of typelib_InterfaceMemberTypeDescription + */ + typelib_InterfaceMemberTypeDescription aBase; + + /** type of the return value + */ + typelib_TypeDescriptionReference * pReturnTypeRef; + /** number of parameters + */ + sal_Int32 nParams; + /** array of parameters + */ + typelib_MethodParameter * pParams; + /** number of exceptions + */ + sal_Int32 nExceptions; + /** array of exception types + */ + typelib_TypeDescriptionReference ** ppExceptions; + /** determines whether method is declared oneway + */ + sal_Bool bOneWay; + + /** the interface description this method is a member of + + @since #i21150# + */ + struct _typelib_InterfaceTypeDescription * pInterface; + /** the inherited direct base method (null for a method that is not + inherited) + + @since UDK 3.2.0 + */ + typelib_TypeDescriptionReference * pBaseRef; + /** if pBaseRef is null, the member position of this method within + pInterface, not counting members inherited from bases; if pBaseRef is + not null, the index of the direct base within pInterface from which this + method is inherited + + @since UDK 3.2.0 + */ + sal_Int32 nIndex; +} typelib_InterfaceMethodTypeDescription; + +/** The description of an interface attribute. The type class of this description is + typelib_TypeClass_INTERFACE_ATTRIBUTE. The size and the alignment are 0. +*/ +typedef struct _typelib_InterfaceAttributeTypeDescription +{ + /** inherits all members of typelib_InterfaceMemberTypeDescription + */ + typelib_InterfaceMemberTypeDescription aBase; + + /** determines whether attribute is read only + */ + sal_Bool bReadOnly; + /** type of the attribute + */ + typelib_TypeDescriptionReference * pAttributeTypeRef; + + /** the interface description this attribute is a member of + + @since #i21150# + */ + struct _typelib_InterfaceTypeDescription * pInterface; + /** the inherited direct base attribute (null for an attribute that is not + inherited) + + @since UDK 3.2.0 + */ + typelib_TypeDescriptionReference * pBaseRef; + /** if pBaseRef is null, the member position of this attribute within + pInterface, not counting members inherited from bases; if pBaseRef is + not null, the index of the direct base within pInterface from which this + attribute is inherited + + @since UDK 3.2.0 + */ + sal_Int32 nIndex; + /** number of getter exceptions + + @since UDK 3.2.0 + */ + sal_Int32 nGetExceptions; + /** array of getter exception types + + @since UDK 3.2.0 + */ + typelib_TypeDescriptionReference ** ppGetExceptions; + /** number of setter exceptions + + @since UDK 3.2.0 + */ + sal_Int32 nSetExceptions; + /** array of setter exception types + + @since UDK 3.2.0 + */ + typelib_TypeDescriptionReference ** ppSetExceptions; +} typelib_InterfaceAttributeTypeDescription; + +/// @HTML +/** Type description of an interface. + + <p>Not all members are always initialized (not yet initialized members being + null); there are three levels:</p> + <ul> + <li>Minimally, only <code>aBase</code>, + <code>pBaseTypeDescription</code>, <code>aUik</code>, + <code>nBaseTypes</code>, and <code>ppBaseTypes</code> are initialized; + <code>aBase.bComplete</code> is false. This only happens when an + interface type description is created with + <code>typelib_static_mi_interface_type_init</code> or + <code>typelib_static_interface_type_init</code>.</li> + + <li>At the next level, <code>nMembers</code>, <code>ppMembers</code>, + <code>nAllMembers</code>, <code>ppAllMembers</code> are also + initialized; <code>aBase.bComplete</code> is still false. This happens + when an interface type description is created with + <code>typelib_typedescription_newMIInterface</cocde> or + <code>typelib_typedescription_newInterface</code>.</li> + + <li>At the final level, <code>pMapMemberIndexToFunctionIndex</code>, + <code>nMapFunctionIndexToMemberIndex</code>, and + <code>pMapFunctionIndexToMemberIndex</code> are also initialized; + <code>aBase.bComplete</code> is true. This happens after a call to + <code>typelib_typedescription_complete</code>.</li> + </ul> +*/ +typedef struct _typelib_InterfaceTypeDescription +/// @NOHTML +{ + /** inherits all members of typelib_TypeDescription + */ + typelib_TypeDescription aBase; + + /** pointer to base type description, else 0 + + @deprecated + use nBaseTypes and ppBaseTypes instead + */ + struct _typelib_InterfaceTypeDescription * pBaseTypeDescription; + /** unique identifier of interface + */ + typelib_Uik aUik; + /** number of members + */ + sal_Int32 nMembers; + /** array of members; references attributes or methods + */ + typelib_TypeDescriptionReference ** ppMembers; + /** number of members including members of base interface + */ + sal_Int32 nAllMembers; + /** array of members including members of base interface; references attributes or methods + */ + typelib_TypeDescriptionReference ** ppAllMembers; + /** array mapping index of the member description to an index doubling for read-write + attributes (called function index); size of array is nAllMembers + */ + sal_Int32 * pMapMemberIndexToFunctionIndex; + /** number of members plus number of read-write attributes + */ + sal_Int32 nMapFunctionIndexToMemberIndex; + /** array mapping function index to member index; size of arry is nMapFunctionIndexToMemberIndex + */ + sal_Int32 * pMapFunctionIndexToMemberIndex; + /** number of base types + + @since UDK 3.2.0 + */ + sal_Int32 nBaseTypes; + /** array of base type descriptions + + @since UDK 3.2.0 + */ + struct _typelib_InterfaceTypeDescription ** ppBaseTypes; +} typelib_InterfaceTypeDescription; + +/** Init struct of compound members for typelib_typedescription_new(). +*/ +typedef struct _typelib_CompoundMember_Init +{ + /** type class of compound member + */ + typelib_TypeClass eTypeClass; + /** name of type of compound member + + For a member of an instantiated polymorphic struct type that is of + parameterized type, this will be a null pointer. + */ + rtl_uString * pTypeName; + /** name of compound member + */ + rtl_uString * pMemberName; +} typelib_CompoundMember_Init; + +/** + Init struct of members for typelib_typedescription_newStruct(). + + @since UDK 3.2.0 + */ +typedef struct _typelib_StructMember_Init +{ + /** + Derived from typelib_CompoundMember_Init; + */ + typelib_CompoundMember_Init aBase; + + /** + Flag specifying whether the member is of parameterized type (true) or + explict type (false). + */ + sal_Bool bParameterizedType; +} typelib_StructMember_Init; + +/** Init struct of interface methods for typelib_typedescription_new(). +*/ +typedef struct _typelib_Parameter_Init +{ + /** type class of parameter + */ + typelib_TypeClass eTypeClass; + /** name of parameter + */ + rtl_uString * pTypeName; + /** name of parameter + */ + rtl_uString * pParamName; + /** true, if parameter is [in] or [inout] + */ + sal_Bool bIn; + /** true, if parameter is [out] or [inout] + */ + sal_Bool bOut; +} typelib_Parameter_Init; + +/** Init struct of union types for typelib_typedescription_newUnion(). +*/ +typedef struct _typelib_Union_Init +{ + /** union member discriminant + */ + sal_Int64 nDiscriminant; + /** union member name + */ + rtl_uString * pMemberName; + /** union member type + */ + typelib_TypeDescriptionReference* pTypeRef; +} typelib_Union_Init; + +#if defined( SAL_W32) +#pragma pack(pop) +#endif + + +/** Creates a union type description. All discriminants are handled as int64 values. + The pDiscriminantTypeRef must be of type byte, short, ..., up to hyper. + + @param ppRet inout union type description + @param pTypeName name of union type + @param pDiscriminantTypeRef discriminant type + @param nDefaultDiscriminant default discriminant + @param pDefaultTypeRef default value type of union + @param nMembers number of union members + @param pMembers init members +*/ +void SAL_CALL typelib_typedescription_newUnion( + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName, + typelib_TypeDescriptionReference * pDiscriminantTypeRef, + sal_Int64 nDefaultDiscriminant, + typelib_TypeDescriptionReference * pDefaultTypeRef, + sal_Int32 nMembers, + typelib_Union_Init * pMembers ) + SAL_THROW_EXTERN_C(); + +/** Creates an enum type description. + + @param ppRet inout enum type description + @param pTypeName name of enum + @param nDefaultEnumValue default enum value + @param nEnumValues number of enum values + @param ppEnumNames names of enum values + @param pEnumValues enum values +*/ +void SAL_CALL typelib_typedescription_newEnum( + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName, + sal_Int32 nDefaultValue, + sal_Int32 nEnumValues, + rtl_uString ** ppEnumNames, + sal_Int32 * pEnumValues ) + SAL_THROW_EXTERN_C(); + +/** Creates an array type description. + + @param ppRet inout enum type description + @param pElementTypeRef element type + @param nDimensions number of dimensions + @param pDimensions dimensions +*/ +void SAL_CALL typelib_typedescription_newArray( + typelib_TypeDescription ** ppRet, + typelib_TypeDescriptionReference * pElementTypeRef, + sal_Int32 nDimensions, + sal_Int32 * pDimensions ) + SAL_THROW_EXTERN_C (); + +/** Creates a new type description. + + Since this function can only be used to create type descriptions for plain + struct types, not for instantiated polymorphic struct types, the function + typelib_typedescription_newStruct should be used instead for all struct + types. + + @param ppRet inout type description + @param eTypeClass type class + @param pTypeName name of type + @param pType sequence, array: element type; + struct, Exception: base type; + @param nMembers number of members if struct, exception + @param pMember array of members if struct, exception +*/ +void SAL_CALL typelib_typedescription_new( + typelib_TypeDescription ** ppRet, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName, + typelib_TypeDescriptionReference * pType, + sal_Int32 nMembers, + typelib_CompoundMember_Init * pMembers ) + SAL_THROW_EXTERN_C(); + +/** Creates a new struct type description. + + @param ppRet inout type description + @param pTypeName name of type + @param pType base type; + @param nMembers number of members + @param pMember array of members + + @since UDK 3.2.0 +*/ +void SAL_CALL typelib_typedescription_newStruct( + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName, + typelib_TypeDescriptionReference * pType, + sal_Int32 nMembers, + typelib_StructMember_Init * pMembers ) + SAL_THROW_EXTERN_C(); + +/** Creates an interface type description. + + @param ppRet inout interface type description + @param pTypeName the fully qualified name of the interface. + @param nUik1 uik part + @param nUik2 uik part + @param nUik3 uik part + @param nUik4 uik part + @param nUik5 uik part + @param pBaseInterface base interface type, else 0 + @param nMembers number of members + @param ppMembers members; attributes or methods + + @deprecated + use typelib_typedescription_newMIInterface instead +*/ +void SAL_CALL typelib_typedescription_newInterface( + typelib_InterfaceTypeDescription ** ppRet, + rtl_uString * pTypeName, + sal_uInt32 nUik1, sal_uInt16 nUik2, sal_uInt16 nUik3, sal_uInt32 nUik4, sal_uInt32 nUik5, + typelib_TypeDescriptionReference * pBaseInterface, + sal_Int32 nMembers, + typelib_TypeDescriptionReference ** ppMembers ) + SAL_THROW_EXTERN_C(); + +/** Creates a multiple-inheritance interface type description. + + @param ppRet inout interface type description + @param pTypeName the fully qualified name of the interface. + @param nUik1 uik part + @param nUik2 uik part + @param nUik3 uik part + @param nUik4 uik part + @param nUik5 uik part + @param nBaseInterfaces number of base interface types + @param ppBaseInterface base interface types + @param nMembers number of members + @param ppMembers members; attributes or methods + + @since UDK 3.2.0 +*/ +void SAL_CALL typelib_typedescription_newMIInterface( + typelib_InterfaceTypeDescription ** ppRet, + rtl_uString * pTypeName, + sal_uInt32 nUik1, sal_uInt16 nUik2, sal_uInt16 nUik3, sal_uInt32 nUik4, sal_uInt32 nUik5, + sal_Int32 nBaseInterfaces, + typelib_TypeDescriptionReference ** ppBaseInterfaces, + sal_Int32 nMembers, + typelib_TypeDescriptionReference ** ppMembers ) + SAL_THROW_EXTERN_C(); + +/** Creates an interface method type description. + + @param ppRet inout method type description + @param nAbsolutePosition position of member including all members of base interfaces + @param bOneWay determines whether method is declared oneway + @param pTypeName fully qualified name of method including interface name + @param eReturnTypeClass type class of return type + @param pReturnTypeName type name of the return type + @param nParams number of parameters + @param pParams parameter types + @param nExceptions number of exceptions + @param ppExceptionNames type names of exceptions +*/ +void SAL_CALL typelib_typedescription_newInterfaceMethod( + typelib_InterfaceMethodTypeDescription ** ppRet, + sal_Int32 nAbsolutePosition, + sal_Bool bOneWay, + rtl_uString * pMethodName, + typelib_TypeClass eReturnTypeClass, + rtl_uString * pReturnTypeName, + sal_Int32 nParams, + typelib_Parameter_Init * pParams, + sal_Int32 nExceptions, + rtl_uString ** ppExceptionNames ) + SAL_THROW_EXTERN_C(); + +/** Creates an interface attribute type description. + + @param ppRet inout attribute type description + @param nAbsolutePosition position of this attribute including all members of base interfaces + @param pAttributeName fully qualified name of attribute including interface + name + @param eAttributeTypeClass type class of attribute type + @param pAttributeTypeName type name of attribute type + @param bReadOnly determines whether attribute is read-only + + @deprecated + use typelib_typedescription_newExtendedInterfaceAttribute instead +*/ +void SAL_CALL typelib_typedescription_newInterfaceAttribute( + typelib_InterfaceAttributeTypeDescription ** ppRet, + sal_Int32 nAbsolutePosition, + rtl_uString * pAttributeName, + typelib_TypeClass eAttributeTypeClass, + rtl_uString * pAttributeTypeName, + sal_Bool bReadOnly ) + SAL_THROW_EXTERN_C(); + +/** Creates an extended interface attribute type description. + + @param ppRet inout attribute type description + @param nAbsolutePosition position of this attribute including all members of + base interfaces + @param pAttributeName fully qualified name of attribute including interface + name + @param eAttributeTypeClass type class of attribute type + @param pAttributeTypeName type name of attribute type + @param bReadOnly determines whether attribute is read-only + @param nGetExceptions number of getter exceptions + @param ppGetExceptionNames type names of getter exceptions + @param nSetExceptions number of setter exceptions + @param ppSetExceptionNames type names of setter exceptions + + @since UDK 3.2.0 +*/ +void SAL_CALL typelib_typedescription_newExtendedInterfaceAttribute( + typelib_InterfaceAttributeTypeDescription ** ppRet, + sal_Int32 nAbsolutePosition, + rtl_uString * pAttributeName, + typelib_TypeClass eAttributeTypeClass, + rtl_uString * pAttributeTypeName, + sal_Bool bReadOnly, + sal_Int32 nGetExceptions, rtl_uString ** ppGetExceptionNames, + sal_Int32 nSetExceptions, rtl_uString ** ppSetExceptionNames ) + SAL_THROW_EXTERN_C(); + +/** Increments reference count of given type description. + + @param pDesc type description +*/ +void SAL_CALL typelib_typedescription_acquire( + typelib_TypeDescription * pDesc ) + SAL_THROW_EXTERN_C(); + +/** Decrements reference count of given type. If reference count reaches 0, the trype description + is deleted. + + @param pDesc type description +*/ +void SAL_CALL typelib_typedescription_release( + typelib_TypeDescription * pDesc ) + SAL_THROW_EXTERN_C(); + +/** Registers a type description and creates a type description reference. Type descriptions + will be registered automatically if they are provided via the callback chain. + + @param ppNewDescription inout description to be registered; +*/ +void SAL_CALL typelib_typedescription_register( + typelib_TypeDescription ** ppNewDescription ) + SAL_THROW_EXTERN_C(); + +/** Tests whether two types descriptions are equal, i.e. type class and names are equal. + + @param p1 a type description + @param p2 another type description + @return true, if type descriptions are equal +*/ +sal_Bool SAL_CALL typelib_typedescription_equals( + const typelib_TypeDescription * p1, const typelib_TypeDescription * p2 ) + SAL_THROW_EXTERN_C(); + +/** Retrieves a type description via its fully qualified name. + + @param ppRet inout type description; *ppRet is 0, if type description was not found + @param pName name demanded type description +*/ +void SAL_CALL typelib_typedescription_getByName( + typelib_TypeDescription ** ppRet, rtl_uString * pName ) + SAL_THROW_EXTERN_C(); + +/** Sets size of type description cache. + + @param nNewSize new size of cache +*/ +void SAL_CALL typelib_setCacheSize( + sal_Int32 nNewSize ) + SAL_THROW_EXTERN_C(); + +/** Function pointer declaration of callback function get additional descriptions. Callbacks + must provide complete type descriptions (see typelib_typedescription_complete())! + + @param pContext callback context + @param ppRet inout type description + @param pTypeName name of demanded type description +*/ +typedef void (SAL_CALL * typelib_typedescription_Callback)( + void * pContext, typelib_TypeDescription ** ppRet, rtl_uString * pTypeName ); + +/** Registers callback function providing additional type descriptions. + + @param pContext callback context + @param pCallback callback function +*/ +void SAL_CALL typelib_typedescription_registerCallback( + void * pContext, typelib_typedescription_Callback pCallback ) + SAL_THROW_EXTERN_C(); + +/** Revokes a previously registered callback function. + + @param pContext callback context + @param pCallback registered callback function +*/ +void SAL_CALL typelib_typedescription_revokeCallback( + void * pContext, typelib_typedescription_Callback pCallback ) + SAL_THROW_EXTERN_C(); + + +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ + +/** Returns true, if the type description reference may lose the type description. Otherwise + pType is a valid pointer and cannot be discarded through the lifetime of this reference. + Remark: If the pWeakObj of the type is set too, you can avoid the call of + ...getDescription(...) and use the description directly. pWeakObj == 0 means, that the + description is not initialized. + @internal +*/ +#define TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( eTypeClass ) \ + ((eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || \ + (eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE) + +/** Gets a description from the reference. The description may not be locked by this call. + You must use the TYPELIB_DANGER_RELEASE macro to release the description fetched with + this macro. + @internal +*/ +#define TYPELIB_DANGER_GET( ppDescription, pTypeRef ) \ +{ \ + typelib_TypeDescriptionReference * pMacroTypeRef = (pTypeRef); \ + typelib_TypeDescription ** ppMacroTypeDescr = (ppDescription); \ + if (TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( pMacroTypeRef->eTypeClass )) \ + { \ + typelib_typedescriptionreference_getDescription( ppMacroTypeDescr, pMacroTypeRef ); \ + } \ + else if (!pMacroTypeRef->pType || !pMacroTypeRef->pType->pWeakRef) \ + { \ + typelib_typedescriptionreference_getDescription( ppMacroTypeDescr, pMacroTypeRef ); \ + if (*ppMacroTypeDescr) \ + typelib_typedescription_release( *ppMacroTypeDescr ); \ + } \ + else \ + { \ + *ppMacroTypeDescr = pMacroTypeRef->pType; \ + } \ +} + +/** Releases the description previouse fetched by TYPELIB_DANGER_GET. + @internal +*/ +#define TYPELIB_DANGER_RELEASE( pDescription ) \ +{ \ + if (TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( (pDescription)->eTypeClass )) \ + typelib_typedescription_release( pDescription ); \ +} + +/** Creates a type description reference. This is a weak reference not holding the description. + If the description is already registered, the previous one is returned. + + @param ppTDR inout type description reference + @param eTypeClass type class of type + @param pTypeName name of type +*/ +void SAL_CALL typelib_typedescriptionreference_new( + typelib_TypeDescriptionReference ** ppTDR, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName ) + SAL_THROW_EXTERN_C(); + +/** Creates a type description reference. This is a weak reference not holding the description. + If the description is already registered, the previous one is returned. + + @param ppTDR inout type description reference + @param eTypeClass type class of type + @param pTypeName ascii name of type +*/ +void SAL_CALL typelib_typedescriptionreference_newByAsciiName( + typelib_TypeDescriptionReference ** ppTDR, + typelib_TypeClass eTypeClass, + const sal_Char * pTypeName ) + SAL_THROW_EXTERN_C(); + +/** Increments reference count of type description reference. + + @param pRef type description reference +*/ +void SAL_CALL typelib_typedescriptionreference_acquire( + typelib_TypeDescriptionReference * pRef ) + SAL_THROW_EXTERN_C(); + +/** Increments reference count of type description reference. If the reference count reaches 0, + then the reference is deleted. + + @param pRef type description reference +*/ +void SAL_CALL typelib_typedescriptionreference_release( + typelib_TypeDescriptionReference * pRef ) + SAL_THROW_EXTERN_C(); + +/** Retrieves the type description for a given reference. If it is not possible to resolve the + reference, null is returned. + + @param ppRet inout type description +*/ +void SAL_CALL typelib_typedescriptionreference_getDescription( + typelib_TypeDescription ** ppRet, typelib_TypeDescriptionReference * pRef ) + SAL_THROW_EXTERN_C(); + +/** Tests whether two types description references are equal, i.e. type class and names are equal. + + @param p1 a type description reference + @param p2 another type description reference + @return true, if type description references are equal +*/ +sal_Bool SAL_CALL typelib_typedescriptionreference_equals( + const typelib_TypeDescriptionReference * p1, const typelib_TypeDescriptionReference * p2 ) + SAL_THROW_EXTERN_C(); + +/** Assigns a type. + + @param ppDest destination type + @param pSource source type +*/ +void SAL_CALL typelib_typedescriptionreference_assign( + typelib_TypeDescriptionReference ** ppDest, + typelib_TypeDescriptionReference * pSource ) + SAL_THROW_EXTERN_C(); + +/** Tests if values of type pAssignable can be assigned by values of type pFrom. This includes + widening conversion (e.g., long assignable from short), as long as there is no data loss. + + @param pAssignable type description of value to be assigned + @param pFrom type description of value +*/ +sal_Bool SAL_CALL typelib_typedescription_isAssignableFrom( + typelib_TypeDescription * pAssignable, + typelib_TypeDescription * pFrom ) + SAL_THROW_EXTERN_C(); + +/** Tests if values of type pAssignable can be assigned by values of type pFrom. This includes + widening conversion (e.g., long assignable from short), as long as there is no data loss. + + @param pAssignable type of value to be assigned + @param pFrom type of value +*/ +sal_Bool SAL_CALL typelib_typedescriptionreference_isAssignableFrom( + typelib_TypeDescriptionReference * pAssignable, + typelib_TypeDescriptionReference * pFrom ) + SAL_THROW_EXTERN_C(); + +/** Gets static type reference of standard types by type class. + ADDITIONAL OPT: provides Type com.sun.star.uno.Exception for typelib_TypeClass_EXCEPTION + and com.sun.star.uno.XInterface for typelib_TypeClass_INTERFACE. + + Thread synchronizes on typelib mutex. + + @param eTypeClass type class of basic type + @return pointer to type reference pointer +*/ +typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass( + typelib_TypeClass eTypeClass ) + SAL_THROW_EXTERN_C(); + +/** Inits static type reference. Thread synchronizes on typelib init mutex. + + @param ppRef pointer to type reference pointer + @param eTypeClass type class of type + @param pTypeName ascii name of type +*/ +void SAL_CALL typelib_static_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeClass eTypeClass, const sal_Char * pTypeName ) + SAL_THROW_EXTERN_C(); + +/** Inits static sequence type reference. Thread synchronizes on typelib init mutex. + + @param ppRef pointer to type reference pointer + @param pElementType element type of sequence +*/ +void SAL_CALL typelib_static_sequence_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeDescriptionReference * pElementType ) + SAL_THROW_EXTERN_C (); + +/** Inits static array type reference. Thread synchronizes on typelib init mutex. + + @param ppRef pointer to type reference pointer + @param pElementType element type of sequence + @param nDimensions number of dimensions + @param ... additional sal_Int32 parameter for each dimension +*/ +void SAL_CALL typelib_static_array_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeDescriptionReference * pElementType, + sal_Int32 nDimensions, ... ) + SAL_THROW_EXTERN_C (); + +/** Inits incomplete static compound type reference. Thread synchronizes on typelib init mutex. + + Since this function can only be used to create type descriptions for plain + struct types, not for instantiated polymorphic struct types, the function + typelib_static_struct_type_init should be used instead for all struct types. + + @param ppRef pointer to type reference pointer + @param eTypeClass typelib_TypeClass_STRUCT or typelib_TypeClass_EXCEPTION + @param pTypeName name of type + @param pBaseType base type + @param nMembers number of members + @param ppMembers member types +*/ +void SAL_CALL typelib_static_compound_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeClass eTypeClass, const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pBaseType, + sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers ) + SAL_THROW_EXTERN_C(); + +/** Inits incomplete static struct type reference. + + Thread synchronizes on typelib init mutex. + + @param ppRef pointer to type reference pointer + @param pTypeName name of type + @param pBaseType base type + @param nMembers number of members + @param ppMembers member types + @param pParameterizedTypes flags for direct members, specifying whether they + are of parameterized type (true) or explict type (false); must be null + for a plain struct type + + @since UDK 3.2.0 +*/ +void SAL_CALL typelib_static_struct_type_init( + typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pBaseType, + sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers, + sal_Bool const * pParameterizedTypes ) + SAL_THROW_EXTERN_C(); + +/** Inits incomplete static interface type reference. Thread synchronizes on typelib init mutex. + + @param ppRef pointer to type reference pointer + @param pTypeName name of interface + @param pBaseType base type +*/ +void SAL_CALL typelib_static_interface_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pBaseType ) + SAL_THROW_EXTERN_C(); + +/** Inits incomplete static multiple-inheritance interface type reference. + Thread synchronizes on typelib init mutex. + + @param ppRef pointer to type reference pointer + @param pTypeName name of interface + @param nBaseTypes number of base types + @param ppBaseTypes base types + + @since UDK 3.2.0 +*/ +void SAL_CALL typelib_static_mi_interface_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + sal_Int32 nBaseTypes, + typelib_TypeDescriptionReference ** ppBaseTypes ) + SAL_THROW_EXTERN_C(); + +/** Inits incomplete static enum type reference. Thread synchronizes on typelib init mutex. + + @param ppRef pointer to type reference pointer + @param pTypeName name of enum + @param nDefaultEnumValue default enum value +*/ +void SAL_CALL typelib_static_enum_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + sal_Int32 nDefaultValue ) + SAL_THROW_EXTERN_C(); + +/** Completes a typedescription to be used for, e.g., marshalling values. COMPOUND, UNION, + INTERFACE and ENUM type descriptions may be partly initialized (see typelib_static_...(), + typelib_TypeDescription::bComplete). For interface type descriptions, this will also + init index tables. + + @param ppTypeDescr [inout] type description to be completed (may be exchanged!) + @return true, if type description is complete +*/ +sal_Bool SAL_CALL typelib_typedescription_complete( + typelib_TypeDescription ** ppTypeDescr ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/typelib/typedescription.hxx b/cppu/inc/typelib/typedescription.hxx new file mode 100644 index 000000000000..3997f3d9c14d --- /dev/null +++ b/cppu/inc/typelib/typedescription.hxx @@ -0,0 +1,227 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _TYPELIB_TYPEDESCRIPTION_HXX_ +#define _TYPELIB_TYPEDESCRIPTION_HXX_ + +#include <rtl/alloc.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Type.h> +#include <typelib/typedescription.h> + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ wrapper for typelib_TypeDescription. + Constructors by name, type, type description reference will get the full type description. + + @see typelib_TypeDescription +*/ +class TypeDescription +{ + /** C typelib type description + */ + mutable typelib_TypeDescription * _pTypeDescr; + +public: + // these are here to force memory de/allocation to sal lib. + /** @internal */ + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) + { return ::rtl_allocateMemory( nSize ); } + /** @internal */ + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) + { ::rtl_freeMemory( pMem ); } + /** @internal */ + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) + { return pMem; } + /** @internal */ + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) + {} + + /** Constructor: + + @param pTypeDescr a type description + */ + inline TypeDescription( typelib_TypeDescription * pTypeDescr = 0 ) SAL_THROW( () ); + /** Constructor: + + @param pTypeDescrRef a type description reference + */ + inline TypeDescription( typelib_TypeDescriptionReference * pTypeDescrRef ) SAL_THROW( () ); + /** Constructor: + + @param rType a type + */ + inline TypeDescription( const ::com::sun::star::uno::Type & rType ) SAL_THROW( () ); + /** Copy constructor: + + @param rDescr another TypeDescription + */ + inline TypeDescription( const TypeDescription & rDescr ) SAL_THROW( () ); + /** Constructor: + + @param pTypeName a type name + */ + inline TypeDescription( rtl_uString * pTypeName ) SAL_THROW( () ); + /** Constructor: + + @param rTypeName a type name + */ + inline TypeDescription( const ::rtl::OUString & rTypeName ) SAL_THROW( () ); + /** Destructor: releases type description + */ + inline ~TypeDescription() SAL_THROW( () ); + + /** Assignment operator: acquires given type description and releases a set one. + + @param pTypeDescr another type description + @return this TypeDescription + */ + inline TypeDescription & SAL_CALL operator = ( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ); + /** Assignment operator: acquires given type description and releases a set one. + + @param rTypeDescr another type description + @return this TypeDescription + */ + inline TypeDescription & SAL_CALL operator =( const TypeDescription & rTypeDescr ) SAL_THROW( () ) + { return this->operator =( rTypeDescr.get() ); } + + /** Tests whether two type descriptions are equal. + + @param pTypeDescr another type description + @return true, if both type descriptions are equal, false otherwise + */ + inline sal_Bool SAL_CALL equals( const typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () ); + /** Tests whether two type descriptions are equal. + + @param rTypeDescr another type description + @return true, if both type descriptions are equal, false otherwise + */ + inline sal_Bool SAL_CALL equals( const TypeDescription & rTypeDescr ) const SAL_THROW( () ) + { return equals( rTypeDescr._pTypeDescr ); } + + /** Makes stored type description complete. + */ + inline void SAL_CALL makeComplete() const SAL_THROW( () ); + + /** Gets the UNacquired type description pointer. + + @return stored pointer of type description + */ + inline typelib_TypeDescription * SAL_CALL get() const SAL_THROW( () ) + { return _pTypeDescr; } + /** Tests if a type description is set. + + @return true, if a type description is set, false otherwise + */ + inline sal_Bool SAL_CALL is() const SAL_THROW( () ) + { return (_pTypeDescr != 0); } +}; +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ) + : _pTypeDescr( pTypeDescr ) +{ + if (_pTypeDescr) + typelib_typedescription_acquire( _pTypeDescr ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( typelib_TypeDescriptionReference * pTypeDescrRef ) SAL_THROW( () ) + : _pTypeDescr( 0 ) +{ + if (pTypeDescrRef) + typelib_typedescriptionreference_getDescription( &_pTypeDescr, pTypeDescrRef ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( const ::com::sun::star::uno::Type & rType ) SAL_THROW( () ) + : _pTypeDescr( 0 ) +{ + if (rType.getTypeLibType()) + typelib_typedescriptionreference_getDescription( &_pTypeDescr, rType.getTypeLibType() ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( const TypeDescription & rTypeDescr ) SAL_THROW( () ) + : _pTypeDescr( rTypeDescr._pTypeDescr ) +{ + if (_pTypeDescr) + typelib_typedescription_acquire( _pTypeDescr ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( rtl_uString * pTypeName ) SAL_THROW( () ) + : _pTypeDescr( 0 ) +{ + typelib_typedescription_getByName( &_pTypeDescr , pTypeName ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( const ::rtl::OUString & rTypeName ) SAL_THROW( () ) + : _pTypeDescr( 0 ) +{ + typelib_typedescription_getByName( &_pTypeDescr , rTypeName.pData ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::~TypeDescription() SAL_THROW( () ) +{ + if (_pTypeDescr) + typelib_typedescription_release( _pTypeDescr ); +} +//__________________________________________________________________________________________________ +inline TypeDescription & TypeDescription::operator = ( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ) +{ + if (pTypeDescr) + typelib_typedescription_acquire( pTypeDescr ); + if (_pTypeDescr) + typelib_typedescription_release( _pTypeDescr ); + _pTypeDescr = pTypeDescr; + return *this; +} +//__________________________________________________________________________________________________ +inline sal_Bool TypeDescription::equals( const typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () ) +{ + return (_pTypeDescr && pTypeDescr && + typelib_typedescription_equals( _pTypeDescr, pTypeDescr )); +} +//__________________________________________________________________________________________________ +inline void TypeDescription::makeComplete() const SAL_THROW( () ) +{ + if (_pTypeDescr && !_pTypeDescr->bComplete) + ::typelib_typedescription_complete( &_pTypeDescr ); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/typelib/uik.h b/cppu/inc/typelib/uik.h new file mode 100644 index 000000000000..f201407d7aa0 --- /dev/null +++ b/cppu/inc/typelib/uik.h @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _TYPELIB_UIK_H_ +#define _TYPELIB_UIK_H_ + +#include <sal/types.h> + +#if defined( SAL_W32) +#pragma pack(push, 8) +#endif + +/** Binary typelib uik struct. Internally not used anymore. +*/ +typedef struct _typelib_Uik +{ + sal_uInt32 m_Data1; + sal_uInt16 m_Data2; + sal_uInt16 m_Data3; + sal_uInt32 m_Data4; + sal_uInt32 m_Data5; +} typelib_Uik; + +#if defined( SAL_W32) +# pragma pack(pop) +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/Enterable.h b/cppu/inc/uno/Enterable.h new file mode 100644 index 000000000000..a769ede987f2 --- /dev/null +++ b/cppu/inc/uno/Enterable.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_uno_Enterable_h +#define INCLUDED_uno_Enterable_h + +#include "uno/environment.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/** Generic function type declaration for entering an Environment. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_enter (void * context); + + +/** Generic function type declaration for levaing an Environment. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_leave (void * context); + + +/** Generic function type declaration for calling into an Environment. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param pCallee the function to be called + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_callInto_v(void * context, uno_EnvCallee * pCallee, va_list * pParam); + + +/** Generic function type declaration for calling out of an Environment. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param pCallee the function to be called + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 +*/ +typedef void uno_Enterable_callOut_v (void * context, uno_EnvCallee * pCallee, va_list * pParam); + + +/** Generic function type declaration for checking if calling on managed object is + valid. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @param context + @param ppReason the reason, in case calling is not valid + @return 0 == calling is not valid, 1 == calling is valid + @since UDK 3.2.7 +*/ +typedef int uno_Enterable_isValid_v (void * context, rtl_uString ** ppReason); + + +/** A struct pReserved needs to point to, if implementing a purpose environment. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Stack) + + @since UDK 3.2.7 +*/ +typedef struct +{ + uno_Enterable_enter * m_enter; + uno_Enterable_leave * m_leave; + uno_Enterable_callInto_v * m_callInto_v; + uno_Enterable_callOut_v * m_callOut_v; + uno_Enterable_isValid_v * m_isValid; +} +uno_Enterable; + + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/EnvDcp.h b/cppu/inc/uno/EnvDcp.h new file mode 100644 index 000000000000..a2471815c179 --- /dev/null +++ b/cppu/inc/uno/EnvDcp.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_uno_EnvDcp_h +#define INCLUDED_uno_EnvDcp_h + +#include "rtl/ustring.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Get the OBI type part of an environment descriptor. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Descriptor) + + @param pEnvDcp the Environment Descriptor + @param ppEnvTypeName the OBI type + @since UDK 3.2.7 +*/ +void uno_EnvDcp_getTypeName(rtl_uString const * pEnvDcp, rtl_uString ** ppEnvTypeName); + + +/** Get the purpose part of an environment descriptor. + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Environment_Descriptor) + + @param pEnvDcp the Environment Descriptor + @param ppEnvPurpose the purpose + @since UDK 3.2.7 +*/ +void uno_EnvDcp_getPurpose (rtl_uString const * pEnvDcp, rtl_uString ** ppEnvPurpose); + + +#ifdef __cplusplus +} +#endif + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/any2.h b/cppu/inc/uno/any2.h new file mode 100644 index 000000000000..dbf64181002e --- /dev/null +++ b/cppu/inc/uno/any2.h @@ -0,0 +1,179 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_ANY2_H_ +#define _UNO_ANY2_H_ + +#include <sal/types.h> +#include <uno/data.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if defined( SAL_W32) +#pragma pack(push, 8) +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +struct _uno_Mapping; + +/** This is the binary specification of an UNO any. +*/ +typedef struct _uno_Any +{ + /** type of value + */ + struct _typelib_TypeDescriptionReference * pType; + /** pointer to value; this may point to pReserved and thus the uno_Any is not anytime + mem-copyable! You may have to correct the pData pointer to pReserved. Otherwise you need + not, because the data is stored in heap space. + */ + void * pData; + /** reserved space for storing value + */ + void * pReserved; +} uno_Any; + +#if defined( SAL_W32) +#pragma pack(pop) +#endif + +/** Assign an any with a given value. Interfaces are acquired or released by the given callback + functions. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +void SAL_CALL uno_any_assign( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assign an any with a given value. Interfaces are acquired or released by the given callback + functions. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +void SAL_CALL uno_type_any_assign( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Constructs an any with a given value. Interfaces are acquired by the given callback function. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +void SAL_CALL uno_any_construct( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Constructs an any with a given value. Interfaces are acquired by the given callback function. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +void SAL_CALL uno_type_any_construct( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Constructs an any with a given value and converts/ maps interfaces. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +void SAL_CALL uno_any_constructAndConvert( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, + struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); +/** Constructs an any with a given value and converts/ maps interfaces. + + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +void SAL_CALL uno_type_any_constructAndConvert( + uno_Any * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, + struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); + +/** Destructs an any. + + @param pValue pointer to any + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +void SAL_CALL uno_any_destruct( + uno_Any * pValue, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Sets value to void. + + @param pValue pointer to any + @param release function called each time an interface needs to be released; + defaults (0) to uno +*/ +void SAL_CALL uno_any_clear( + uno_Any * pValue, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/cuno.h b/cppu/inc/uno/cuno.h new file mode 100644 index 000000000000..f71c56854dd1 --- /dev/null +++ b/cppu/inc/uno/cuno.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_CUNO_H_ +#define _UNO_CUNO_H_ + +#include <sal/types.h> + +#define CUNO_ERROR_NONE 0 +#define CUNO_ERROR_CALL_FAILED (1 << 31) +#define CUNO_ERROR_EXCEPTION (1 | CUNO_ERROR_CALL_FAILED) + +/** macro to call on a C interface + + @param interface_pointer interface pointer +*/ +#define CUNO_CALL( interface_pointer ) (*interface_pointer) +/** macro to test if an exception was signalled. + + @param return_code return code of call +*/ +#define CUNO_EXCEPTION_OCCURRED( return_code ) (0 != ((return_code) & CUNO_ERROR_EXCEPTION)) + +typedef sal_Int32 cuno_ErrorCode; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/current_context.h b/cppu/inc/uno/current_context.h new file mode 100644 index 000000000000..7abd2771df07 --- /dev/null +++ b/cppu/inc/uno/current_context.h @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_CURRENT_CONTEXT_H_ +#define _UNO_CURRENT_CONTEXT_H_ + +#include <rtl/ustring.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Gets the current task's context. + @attention + Don't spread the returned interface around to other threads. Every thread has its own + current context. + + @param ppCurrentContext inout param current context of type com.sun.star.uno.XCurrentContext + @param pEnvDcp descriptor of returned interface's environment + @param pEnvContext context of returned interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) +*/ +sal_Bool SAL_CALL uno_getCurrentContext( + void ** ppCurrentContext, + rtl_uString * pEnvDcp, void * pEnvContext ) + SAL_THROW_EXTERN_C(); + +/** Sets the current task's context. + + @param pCurrentContext in param current context of type com.sun.star.uno.XCurrentContext + @param pEnvDcp descriptor of interface's environment + @param pEnvContext context of interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) +*/ +sal_Bool SAL_CALL uno_setCurrentContext( + void * pCurrentContext, + rtl_uString * pEnvDcp, void * pEnvContext ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/current_context.hxx b/cppu/inc/uno/current_context.hxx new file mode 100644 index 000000000000..01d59a460eca --- /dev/null +++ b/cppu/inc/uno/current_context.hxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_CURRENT_CONTEXT_HXX_ +#define _UNO_CURRENT_CONTEXT_HXX_ + +#include <uno/current_context.h> + +#include <com/sun/star/uno/XCurrentContext.hpp> + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** Getting the current context. + @attention + Don't spread the returned interface around to other threads. Every thread has its own + current context. + + @return current context or null ref, if none is set +*/ +inline Reference< XCurrentContext > SAL_CALL getCurrentContext() + SAL_THROW( () ) +{ + Reference< XCurrentContext > xRet; + ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + ::uno_getCurrentContext( (void **)&xRet, aEnvTypeName.pData, 0 ); + return xRet; +} +/** Setting the current context. + + @param xContext current context to be set + @return true, if context has been successfully set +*/ +inline bool SAL_CALL setCurrentContext( + Reference< XCurrentContext > const & xContext ) + SAL_THROW( () ) +{ + ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + return (::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, 0 ) != sal_False); +} + +/** Objects of this class are used for applying a current context until they are destructed, i.e. + the ctor of this class saves the previous and sets the given context while the dtor restores + the previous one upon destruction. +*/ +class ContextLayer +{ + /** this C++ environment type name. + @internal + */ + ::rtl::OUString m_aEnvTypeName; + /** previous context + @internal + */ + Reference< XCurrentContext > m_xPreviousContext; + +public: + /** Constructor: Saves the previous context and sets the new (given) one. + + @param xNewContext new context to be set + */ + inline ContextLayer( + Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() ) + SAL_THROW( () ); + /** Destructor: restores the previous context. + */ + inline ~ContextLayer() SAL_THROW( () ); + + /** Gets the previously set context. + + @return the previously set context + */ + inline Reference< XCurrentContext > SAL_CALL getPreviousContext() const + SAL_THROW( () ) + { return m_xPreviousContext; } +}; +//__________________________________________________________________________________________________ +inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext ) + SAL_THROW( () ) + : m_aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) +{ + ::uno_getCurrentContext( (void **)&m_xPreviousContext, m_aEnvTypeName.pData, 0 ); + ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, 0 ); +} +//__________________________________________________________________________________________________ +inline ContextLayer::~ContextLayer() + SAL_THROW( () ) +{ + ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, 0 ); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/data.h b/cppu/inc/uno/data.h new file mode 100644 index 000000000000..8a86b89841d7 --- /dev/null +++ b/cppu/inc/uno/data.h @@ -0,0 +1,260 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_DATA_H_ +#define _UNO_DATA_H_ + +#include <sal/types.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +struct _typelib_InterfaceTypeDescription; +struct _uno_Mapping; + +/** Generic function pointer declaration to query for an interface. + + @param pInterface interface + @param pTypedemanded interface type + @return interface pointer +*/ +typedef void * (SAL_CALL * uno_QueryInterfaceFunc)( + void * pInterface, struct _typelib_TypeDescriptionReference * pType ); +/** Generic function pointer declaration to acquire an interface. + + @param pInterface interface to be acquired +*/ +typedef void (SAL_CALL * uno_AcquireFunc)( + void * pInterface ); +/** Generic function pointer declaration to release an interface. + + @param pInterface interface to be release +*/ +typedef void (SAL_CALL * uno_ReleaseFunc)( + void * pInterface ); + +/** Tests if two values are equal. May compare different types (e.g., short to long). + + @param pVal1 pointer to a value + @param pVal1TypeDescr type description of pVal1 + @param pVal2 pointer to another value + @param pVal2TypeDescr type description of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +sal_Bool SAL_CALL uno_equalData( + void * pVal1, struct _typelib_TypeDescription * pVal1TypeDescr, + void * pVal2, struct _typelib_TypeDescription * pVal2TypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Tests if two values are equal. May compare different types (e.g., short to long). + + @param pVal1 pointer to a value + @param pVal1Type type of pVal1 + @param pVal2 pointer to another value + @param pVal2Type type of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +sal_Bool SAL_CALL uno_type_equalData( + void * pVal1, struct _typelib_TypeDescriptionReference * pVal1Type, + void * pVal2, struct _typelib_TypeDescriptionReference * pVal2Type, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +void SAL_CALL uno_copyData( + void * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno +*/ +void SAL_CALL uno_type_copyData( + void * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. Interfaces are converted/ mapped by mapping parameter. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param mapping mapping to convert/ map interfaces +*/ +void SAL_CALL uno_copyAndConvertData( + void * pDest, void * pSource, + struct _typelib_TypeDescription * pTypeDescr, struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); +/** Copy construct memory with given value. The size of the destination value must be larger + or equal to the size of the source value. Interfaces are converted/ mapped by mapping parameter. + + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param mapping mapping to convert/ map interfaces +*/ +void SAL_CALL uno_type_copyAndConvertData( + void * pDest, void * pSource, + struct _typelib_TypeDescriptionReference * pType, struct _uno_Mapping * mapping ) + SAL_THROW_EXTERN_C(); + +/** Destructs a given value; does NOT free its memory! + + @param pValue value to be destructed + @param pTypeDescr type description of value + @param release function called each time an interface pointer needs to be released; + defaults (0) to uno +*/ +void SAL_CALL uno_destructData( + void * pValue, struct _typelib_TypeDescription * pTypeDescr, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Destructs a given value; does NOT free its memory! + + @param pValue value to be destructed + @param pType type of value + @param release function called each time an interface pointer needs to be released; + defaults (0) to uno +*/ +void SAL_CALL uno_type_destructData( + void * pValue, struct _typelib_TypeDescriptionReference * pType, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Default constructs a value. All simple types are set to 0, enums are set to their default value. + + @param pMem pointer to memory of value to be constructed + @param pTypeDescr type description of value to be constructed +*/ +void SAL_CALL uno_constructData( + void * pMem, struct _typelib_TypeDescription * pTypeDescr ) + SAL_THROW_EXTERN_C(); +/** Default constructs a value. All simple types are set to 0, enums are set to their default value. + + @param pMem pointer to memory of value to be constructed + @param pType type of value to be constructed +*/ +void SAL_CALL uno_type_constructData( + void * pMem, struct _typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C(); + +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pDest pointer to destination value + @param pDestTypeDescr type description of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned + to default value + @param pSourceTypeDescr type destination of source value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if destination has been successfully assigned +*/ +sal_Bool SAL_CALL uno_assignData( + void * pDest, struct _typelib_TypeDescription * pDestTypeDescr, + void * pSource, struct _typelib_TypeDescription * pSourceTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pDest pointer to destination value + @param pDestType type of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned + to default value + @param pSourceType type of source value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if destination has been successfully assigned +*/ +sal_Bool SAL_CALL uno_type_assignData( + void * pDest, struct _typelib_TypeDescriptionReference * pDestType, + void * pSource, struct _typelib_TypeDescriptionReference * pSourceType, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Tests whether a value of given type is assignable from given value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pAssignable type + @param pFrom pointer to value + @param pFromType type of value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if value is destination has been successfully assigned +*/ +sal_Bool SAL_CALL uno_type_isAssignableFromData( + struct _typelib_TypeDescriptionReference * pAssignable, + void * pFrom, struct _typelib_TypeDescriptionReference * pFromType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/dispatcher.h b/cppu/inc/uno/dispatcher.h new file mode 100644 index 000000000000..297dece16003 --- /dev/null +++ b/cppu/inc/uno/dispatcher.h @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_DISPATCHER_H_ +#define _UNO_DISPATCHER_H_ + +#include <sal/types.h> +#include <rtl/ustring.h> +#include <uno/any2.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescription; +struct _uno_Interface; + +/** Function pointer declaration for the binary C uno dispatch function. Any pure out or return + value will be constructed by the callee, iff no exception is signalled. + If an exception is signalled, the any *ppException is properly constructed by the callee, + otherwise the pointer *ppException is set to 0. + An attribute get call is indicated by a non-null return pointer. + + @param pUnoI uno interface the call is performed on + @param pMemberType member type description of a method or attribute + @param pReturn pointer to return value memory; + pointer may be undefined if void method, null if attribute set call. + @param pArgs an array of pointers to arguments values. + (remark: the value of an interface reference stores a + uno_interface *, so you get it by *(uno_Interface **)pArgs[n]) + @param ppException pointer to pointer to unconstructed any to signal an exception. +*/ +typedef void (SAL_CALL * uno_DispatchMethod)( + struct _uno_Interface * pUnoI, + const struct _typelib_TypeDescription * pMemberType, + void * pReturn, + void * pArgs[], + uno_Any ** ppException ); + +#if defined( SAL_W32) +#pragma pack(push, 8) +#endif + +/** The binary C uno interface description. +*/ +typedef struct _uno_Interface +{ + /** Acquires uno interface. + + @param pInterface uno interface + */ + void (SAL_CALL * acquire)( struct _uno_Interface * pInterface ); + /** Releases uno interface. + + @param pInterface uno interface + */ + void (SAL_CALL * release)( struct _uno_Interface * pInterface ); + /** dispatch function + */ + uno_DispatchMethod pDispatcher; +} uno_Interface; + +#if defined( SAL_W32) +#pragma pack(pop) +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/dispatcher.hxx b/cppu/inc/uno/dispatcher.hxx new file mode 100644 index 000000000000..90fdb3db6df7 --- /dev/null +++ b/cppu/inc/uno/dispatcher.hxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_UNO_DISPATCHER_HXX +#define INCLUDED_UNO_DISPATCHER_HXX + +#include "uno/dispatcher.h" + + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ holder reference for binary C uno_Interface. Not for public use, may be + subject to changes. + + @see uno_Interface + @internal + not for public use! +*/ +class UnoInterfaceReference +{ +public: + uno_Interface * m_pUnoI; + + inline bool is() const + { return m_pUnoI != 0; } + + inline ~UnoInterfaceReference(); + inline UnoInterfaceReference(); + inline UnoInterfaceReference( uno_Interface * pUnoI, __sal_NoAcquire ); + inline UnoInterfaceReference( uno_Interface * pUnoI ); + inline UnoInterfaceReference( UnoInterfaceReference const & ref ); + + inline uno_Interface * get() const + { return m_pUnoI; } + + inline UnoInterfaceReference & set( + uno_Interface * pUnoI ); + inline UnoInterfaceReference & set( + uno_Interface * pUnoI, __sal_NoAcquire ); + inline void clear(); + + inline UnoInterfaceReference & operator = ( + UnoInterfaceReference const & ref ) + { return set( ref.m_pUnoI ); } + inline UnoInterfaceReference & operator = ( + uno_Interface * pUnoI ) + { return set( pUnoI ); } + + inline void dispatch( + struct _typelib_TypeDescription const * pMemberType, + void * pReturn, void * pArgs [], uno_Any ** ppException ) const; + +private: + inline bool operator == ( UnoInterfaceReference const & ); // not impl + inline bool operator != ( UnoInterfaceReference const & ); // not impl + inline bool operator == ( uno_Interface * ); // not impl + inline bool operator != ( uno_Interface * ); // not impl +}; + +//______________________________________________________________________________ +inline UnoInterfaceReference::~UnoInterfaceReference() +{ + if (m_pUnoI != 0) + (*m_pUnoI->release)( m_pUnoI ); +} + +//______________________________________________________________________________ +inline UnoInterfaceReference::UnoInterfaceReference() + : m_pUnoI( 0 ) +{ +} + +//______________________________________________________________________________ +inline UnoInterfaceReference::UnoInterfaceReference( + uno_Interface * pUnoI, __sal_NoAcquire ) + : m_pUnoI( pUnoI ) +{ +} + +//______________________________________________________________________________ +inline UnoInterfaceReference::UnoInterfaceReference( uno_Interface * pUnoI ) + : m_pUnoI( pUnoI ) +{ + if (m_pUnoI != 0) + (*m_pUnoI->acquire)( m_pUnoI ); +} + +//______________________________________________________________________________ +inline UnoInterfaceReference::UnoInterfaceReference( + UnoInterfaceReference const & ref ) + : m_pUnoI( ref.m_pUnoI ) +{ + if (m_pUnoI != 0) + (*m_pUnoI->acquire)( m_pUnoI ); +} + +//______________________________________________________________________________ +inline UnoInterfaceReference & UnoInterfaceReference::set( + uno_Interface * pUnoI ) +{ + if (pUnoI != 0) + (*pUnoI->acquire)( pUnoI ); + if (m_pUnoI != 0) + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = pUnoI; + return *this; +} + +//______________________________________________________________________________ +inline UnoInterfaceReference & UnoInterfaceReference::set( + uno_Interface * pUnoI, __sal_NoAcquire ) +{ + if (m_pUnoI != 0) + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = pUnoI; + return *this; +} + +//______________________________________________________________________________ +inline void UnoInterfaceReference::clear() +{ + if (m_pUnoI != 0) + { + (*m_pUnoI->release)( m_pUnoI ); + m_pUnoI = 0; + } +} + +//______________________________________________________________________________ +inline void UnoInterfaceReference::dispatch( + struct _typelib_TypeDescription const * pMemberType, + void * pReturn, void * pArgs [], uno_Any ** ppException ) const +{ + (*m_pUnoI->pDispatcher)( + m_pUnoI, pMemberType, pReturn, pArgs, ppException ); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/environment.h b/cppu/inc/uno/environment.h new file mode 100644 index 000000000000..5ef4a5de5323 --- /dev/null +++ b/cppu/inc/uno/environment.h @@ -0,0 +1,390 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_ENVIRONMENT_H_ +#define _UNO_ENVIRONMENT_H_ + +#include <sal/types.h> +#include <rtl/ustring.h> + +#include <stdarg.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _uno_ExtEnvironment; +struct _typelib_InterfaceTypeDescription; + +#if defined( SAL_W32) +#pragma pack(push, 8) +#endif + +/** The binary specification of an UNO environment. +*/ +typedef struct _uno_Environment +{ + /** reserved for future use (0 if not used) + */ + void * pReserved; + + /** type name of environment + */ + rtl_uString * pTypeName; + + /** free context pointer to be used for specific classes of environments (e.g., a jvm pointer) + */ + void * pContext; + + /** pointer to extended environment (interface registration functionality), if supported + */ + struct _uno_ExtEnvironment * pExtEnv; + + /** Acquires this environment. + + @param pEnv this environment + */ + void (SAL_CALL * acquire)( struct _uno_Environment * pEnv ); + + /** Releases this environment; last release of environment will revoke the environment from + runtime. + + @param pEnv this environment + */ + void (SAL_CALL * release)( struct _uno_Environment * pEnv ); + + /** Acquires this environment weakly. You can only harden a weakly held environment if it + is still acquired hard (acquire()). + + @param pEnv this environment + */ + void (SAL_CALL * acquireWeak)( struct _uno_Environment * pEnv ); + + /** Releases this environment weakly in correspondence to acquireWeak(). + + @param pEnv this environment + */ + void (SAL_CALL * releaseWeak)( struct _uno_Environment * pEnv ); + + /** Makes hard reference out of weak referenced environment. You can only harden a weakly + held environment if it is still acquired hard (acquire()). + + @param ppHardEnv inout hard referenced environment (has to be released via release()) + @param pEnv environment (may be weak referenced) + */ + void (SAL_CALL * harden)( + struct _uno_Environment ** ppHardEnv, + struct _uno_Environment * pEnv ); + + /** Call this function to EXPLICITLY dispose this environment (e.g., release all + interfaces). You may want to call this function before shutting down due to a runtime error. + + @param pEnv this environment + */ + void (SAL_CALL * dispose)( struct _uno_Environment * pEnv ); + + /* ===== the following part will be late initialized by a matching bridge ===== * + * ===== and is NOT for public use. ===== */ + + /** CALLBACK function pointer: Disposing callback function pointer that can be set to get + signalled before the environment is destroyed. + + @param pEnv environment that is being disposed + */ + void (SAL_CALL * environmentDisposing)( struct _uno_Environment * pEnv ); +} uno_Environment; + +/** Generic function pointer declaration to free a proxy object if it is not needed by the + environment anymore. + Any proxy object must register itself on first acquire() call and revoke itself on last + release() call. This can happen several times because the environment caches proxy objects + until the environment explicitly frees the proxy object calling this function. + + @param pEnv environment + @param pProxy proxy pointer +*/ +typedef void (SAL_CALL * uno_freeProxyFunc)( struct _uno_ExtEnvironment * pEnv, void * pProxy ); + +/** Generic function pointer declaration to allocate memory. Used with getRegisteredInterfaces(). + + @param nBytes amount of memory in bytes + @return pointer to allocated memory +*/ +typedef void * (SAL_CALL * uno_memAlloc)( sal_Size nBytes ); + +/** The binary specification of an UNO environment supporting interface registration. +*/ +typedef struct _uno_ExtEnvironment +{ + /** inherits all members of an uno_Environment + */ + uno_Environment aBase; + + /** Registers an interface of this environment. + + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Registers a proxy interface of this environment that can be reanimated and is freed + explicitly by this environment. + + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param freeProxy function to free proxy object + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerProxyInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppProxy, + uno_freeProxyFunc freeProxy, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Revokes an interface from this environment. You have to revoke any interface that has + been registered via this method. + + @param pEnv this environment + @param pInterface interface to be revoked + */ + void (SAL_CALL * revokeInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + + /** Provides the object id of a given interface. + + @param ppOut inout oid + @param pInterface interface of object + */ + void (SAL_CALL * getObjectIdentifier)( + struct _uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, + void * pInterface ); + + /** Retrieves an interface identified by its object id and type from this environment. + Interfaces are retrieved in the same order as they are registered. + + @param pEnv this environment + @param ppInterface inout parameter for the registered interface; (0) if none was found + @param pOId object id of interface to be retrieved + @param pTypeDescr type description of interface to be retrieved + */ + void (SAL_CALL * getRegisteredInterface)( + struct _uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + struct _typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Returns all currently registered interfaces of this environment. The memory block + allocated might be slightly larger than (*pnLen * sizeof(void *)). + + @param pEnv this environment + @param pppInterfaces out param; pointer to array of interface pointers + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + */ + void (SAL_CALL * getRegisteredInterfaces)( + struct _uno_ExtEnvironment * pEnv, + void *** pppInterfaces, + sal_Int32 * pnLen, + uno_memAlloc memAlloc ); + + /* ===== the following part will be late initialized by a matching bridge ===== */ + + /** Computes an object id of the given interface; is called by the environment implementation. + + @param pEnv corresponding environment + @param ppOId out param: computed id + @param pInterface an interface + */ + void (SAL_CALL * computeObjectIdentifier)( + struct _uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, void * pInterface ); + + /** Function to acquire an interface. + + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * acquireInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + + /** Function to release an interface. + + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * releaseInterface)( + struct _uno_ExtEnvironment * pEnv, + void * pInterface ); + +} uno_ExtEnvironment; + +#if defined( SAL_W32) +#pragma pack(pop) +#endif + +/** Function exported by some bridge library providing acquireInterface(), releaseInterface(); + may set a disposing callback. + + @param pEnv environment to be initialized +*/ +typedef void (SAL_CALL * uno_initEnvironmentFunc)( uno_Environment * pEnv ); +#define UNO_INIT_ENVIRONMENT "uno_initEnvironment" + +/** Gets a specific environment. If the specified environment does not exist, then a default one + is created and registered. The environment revokes itself on last release() call. + + @param ppEnv inout parameter of environment; given environment will be released + @param pEnvDcp descriptor of environment + @param pContext some context pointer (e.g., to distinguish java vm; set 0 if not needed) +*/ +void SAL_CALL uno_getEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext ) + SAL_THROW_EXTERN_C(); + +/** Gets all specified environments. Caller has to release returned environments and free allocated + memory. + + @param pppEnvs out param; pointer to array of environments + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + @param pEnvDcp descriptor of environments; 0 defaults to all +*/ +void SAL_CALL uno_getRegisteredEnvironments( + uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc, + rtl_uString * pEnvDcp ) + SAL_THROW_EXTERN_C(); + +/** Creates an environment. The new environment is anonymous (NOT publicly registered/ accessible). + + @param ppEnv out parameter of environment; given environment will be released + @param pEnvDcp descriptor of environment + @param pContext context pointer (e.g., to distinguish java vm); set 0 if not needed +*/ +void SAL_CALL uno_createEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext ) + SAL_THROW_EXTERN_C(); + +/** Dumps out environment information, i.e. registered interfaces. + + @param stream output stream (FILE *) + @param pEnv environment to be dumped + @param pFilter if not null, filters output +*/ +void SAL_CALL uno_dumpEnvironment( + void * stream, uno_Environment * pEnv, const sal_Char * pFilter ) + SAL_THROW_EXTERN_C(); +/** Dumps out environment information, i.e. registered interfaces. + + @param stream output stream (FILE *) + @param pEnvDcp descritpro of environment to be dumped + @param pFilter if not null, filters output +*/ +void SAL_CALL uno_dumpEnvironmentByName( + void * stream, rtl_uString * pEnvDcp, const sal_Char * pFilter ) + SAL_THROW_EXTERN_C(); + + + +/** Returns the current Environment. + In case no Environment has explicitly been entered, a purpose free + default environment gets returned (e.g. the "uno" or "gcc3" Environment). + + @param ppEnv inout parameter; a given environment will be released + @param pTypeName the optional type of the environment, falls back to "uno" + @since UDK 3.2.7 +*/ +void SAL_CALL uno_getCurrentEnvironment(uno_Environment ** ppEnv, rtl_uString * pTypeName) + SAL_THROW_EXTERN_C(); + +/** Typedef for variable argument function. + */ +typedef void SAL_CALL uno_EnvCallee(va_list * pParam); + +/** Invoke the passed function in the given environment. + + @param pEnv the target environment + @param pCallee the function to call + @param pParam the parameter pointer passed to the function + @since UDK 3.2.7 + */ +void SAL_CALL uno_Environment_invoke_v(uno_Environment * pEnv, uno_EnvCallee * pCallee, va_list * pParam) + SAL_THROW_EXTERN_C(); + +/** Invoke the passed function in the given environment. + + @param pEnv the target environment + @param pCallee the function to call + @param ... the parameters passed to the function + @since UDK 3.2.7 +*/ +void SAL_CALL uno_Environment_invoke (uno_Environment * pEnv, uno_EnvCallee * pCallee, ...) + SAL_THROW_EXTERN_C(); + +/** Enter an environment explicitly. + + @param pEnv the environment to enter; NULL leaves all environments + @since UDK 3.2.7 +*/ +void SAL_CALL uno_Environment_enter(uno_Environment * pEnv) + SAL_THROW_EXTERN_C(); + +/** Check if a particular environment is currently valid, so + that objects of that environment might be called. + + @param pEnv the environment + @param rtl_uString ** pReason the reason, if it is not valid + @return 1 == valid, 0 == invalid + @since UDK 3.2.7 +*/ +int SAL_CALL uno_Environment_isValid(uno_Environment * pEnv, rtl_uString ** pReason) + SAL_THROW_EXTERN_C(); + +#ifdef IOS +/* We link statically on iOS and have just one kind of environment */ +void SAL_CALL gcc3_uno_initEnvironment(uno_Environment *pCppEnv) + SAL_THROW_EXTERN_C(); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/environment.hxx b/cppu/inc/uno/environment.hxx new file mode 100644 index 000000000000..8fa4f3ea5063 --- /dev/null +++ b/cppu/inc/uno/environment.hxx @@ -0,0 +1,281 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_ENVIRONMENT_HXX_ +#define _UNO_ENVIRONMENT_HXX_ + +#include <rtl/alloc.h> +#include <rtl/ustring.hxx> +#include <uno/environment.h> + +#include "uno/lbnames.h" + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** C++ wrapper for binary C uno_Environment. + + @see uno_Environment +*/ +class Environment +{ + /** binary C uno_Environment + */ + uno_Environment * _pEnv; + +public: + /** Returns the current Environment. + + @param env_type the optional type of the Environment, falls back to "uno" in case being empty, + respectively to current C++ Environment. + @since UDK 3.2.7 + */ + inline static Environment getCurrent(rtl::OUString const & typeName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV)))) SAL_THROW( () ); + + // these are here to force memory de/allocation to sal lib. + /** @internal */ + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) + { return ::rtl_allocateMemory( nSize ); } + /** @internal */ + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) + { ::rtl_freeMemory( pMem ); } + /** @internal */ + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) + { return pMem; } + /** @internal */ + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) + {} + + /** Constructor: acquires given environment + + @param pEnv environment + */ + inline Environment( uno_Environment * pEnv = 0 ) SAL_THROW( () ); + + /** Gets a specific environment. If the specified environment does not exist, then a default one + is created and registered. + + @param envDcp descriptor of the environment + @param pContext context pointer + */ + inline explicit Environment( rtl::OUString const & envDcp, void * pContext = NULL ) SAL_THROW( () ); + + + /** Copy constructor: acquires given environment + + @param rEnv another environment + */ + inline Environment( const Environment & rEnv ) SAL_THROW( () ); + + /** Destructor: releases a set environment. + */ + inline ~Environment() SAL_THROW( () ); + + /** Sets a given environment, i.e. acquires given one and releases a set one. + + @param pEnv another environment + @return this environment + */ + inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ) SAL_THROW( () ); + /** Sets a given environment, i.e. acquires given one and releases a set one. + + @param rEnv another environment + @return this environment + */ + inline Environment & SAL_CALL operator = ( const Environment & rEnv ) SAL_THROW( () ) + { return operator = ( rEnv._pEnv ); } + + /** Provides UNacquired pointer to the set C environment. + + @return UNacquired pointer to the C environment struct + */ + inline uno_Environment * SAL_CALL get() const SAL_THROW( () ) + { return _pEnv; } + + /** Gets type name of set environment. + + @return type name of set environment + */ + inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW( () ) + { return _pEnv->pTypeName; } + + /** Gets free context pointer of set environment. + + @return free context pointer of set environment + */ + inline void * SAL_CALL getContext() const SAL_THROW( () ) + { return _pEnv->pContext; } + + /** Tests if a environment is set. + + @return true, if a environment is set, false otherwise + */ + inline sal_Bool SAL_CALL is() const SAL_THROW( () ) + { return (_pEnv != 0); } + + /** Releases a set environment. + */ + inline void SAL_CALL clear() SAL_THROW( () ); + + /** Invoke the passed function in this environment. + + @param pCallee the function to call + @param pParam the parameter pointer to be passed to the function + @since UDK 3.2.7 + */ + inline void SAL_CALL invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW( () ); + + /** Invoke the passed function in this environment. + + @param pCallee the function to call + @param ... the parameters to be passed to the function + @since UDK 3.2.7 + */ + inline void SAL_CALL invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW( () ); + + /** Enter this environment explicitly. + + @since UDK 3.2.7 + */ + inline void SAL_CALL enter() const SAL_THROW( () ); + + /** Checks, if it is valid to currently call objects + belonging to this environment. + + @since UDK 3.2.7 + */ + inline int SAL_CALL isValid(rtl::OUString * pReason) const SAL_THROW( () ); +}; +//__________________________________________________________________________________________________ +inline Environment::Environment( uno_Environment * pEnv ) SAL_THROW( () ) + : _pEnv( pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} +//__________________________________________________________________________________________________ +inline Environment::Environment( rtl::OUString const & rEnvDcp, void * pContext ) SAL_THROW( () ) + : _pEnv(NULL) +{ + uno_getEnvironment(&_pEnv, rEnvDcp.pData, pContext); +} +//__________________________________________________________________________________________________ +inline Environment::Environment( const Environment & rEnv ) SAL_THROW( () ) + : _pEnv( rEnv._pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} +//__________________________________________________________________________________________________ +inline Environment::~Environment() SAL_THROW( () ) +{ + if (_pEnv) + (*_pEnv->release)( _pEnv ); +} +//__________________________________________________________________________________________________ +inline void Environment::clear() SAL_THROW( () ) +{ + if (_pEnv) + { + (*_pEnv->release)( _pEnv ); + _pEnv = 0; + } +} +//__________________________________________________________________________________________________ +inline Environment & Environment::operator = ( uno_Environment * pEnv ) SAL_THROW( () ) +{ + if (pEnv != _pEnv) + { + if (pEnv) + (*pEnv->acquire)( pEnv ); + if (_pEnv) + (*_pEnv->release)( _pEnv ); + _pEnv = pEnv; + } + return *this; +} +//__________________________________________________________________________________________________ +inline void SAL_CALL Environment::invoke_v(uno_EnvCallee * pCallee, va_list * pParam) const SAL_THROW( () ) +{ + if (_pEnv) + uno_Environment_invoke_v(_pEnv, pCallee, pParam); +} +//__________________________________________________________________________________________________ +inline void SAL_CALL Environment::invoke(uno_EnvCallee * pCallee, ...) const SAL_THROW( () ) +{ + if (_pEnv) + { + va_list param; + + va_start(param, pCallee); + uno_Environment_invoke_v(_pEnv, pCallee, ¶m); + va_end(param); + } + +} +//__________________________________________________________________________________________________ +inline void SAL_CALL Environment::enter() const SAL_THROW( () ) +{ + uno_Environment_enter(_pEnv); +} +//__________________________________________________________________________________________________ +inline int SAL_CALL Environment::isValid(rtl::OUString * pReason) const SAL_THROW( () ) +{ + return uno_Environment_isValid(_pEnv, (rtl_uString **)pReason); +} +//__________________________________________________________________________________________________ +inline Environment Environment::getCurrent(rtl::OUString const & typeName) SAL_THROW( () ) +{ + Environment environment; + + uno_Environment * pEnv = NULL; + uno_getCurrentEnvironment(&pEnv, typeName.pData); + environment = pEnv; + if (pEnv) + pEnv->release(pEnv); + + return environment; +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/lbnames.h b/cppu/inc/uno/lbnames.h new file mode 100644 index 000000000000..f9e32a957312 --- /dev/null +++ b/cppu/inc/uno/lbnames.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_LBNAMES_H_ +#define _UNO_LBNAMES_H_ + +#ifdef __cplusplus + +#ifdef CPPU_ENV + +#define CPPU_STRINGIFY_EX( x ) #x +#define CPPU_STRINGIFY( x ) CPPU_STRINGIFY_EX( x ) + +/** Name for C++ compiler/ platform, e.g. "gcc3", "msci" */ +#define CPPU_CURRENT_LANGUAGE_BINDING_NAME CPPU_STRINGIFY( CPPU_ENV ) + +#else + +#error "No supported C++ compiler environment." +provoking error here, because PP ignores #error + +#endif /* CPPU_ENV */ + +#endif /* __cplusplus */ + +/** Environment type name for binary C UNO. */ +#define UNO_LB_UNO "uno" +/** Environment type name for ANSI C compilers. */ +#define UNO_LB_C "c" +/** Environment type name for Java 1.3.1 compatible virtual machine. */ +#define UNO_LB_JAVA "java" +/** Environment type name for CLI (Common Language Infrastructure). */ +#define UNO_LB_CLI "cli" + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/mapping.h b/cppu/inc/uno/mapping.h new file mode 100644 index 000000000000..53ea250dd31d --- /dev/null +++ b/cppu/inc/uno/mapping.h @@ -0,0 +1,204 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_MAPPING_H_ +#define _UNO_MAPPING_H_ + +#include <sal/types.h> +#include <rtl/ustring.h> + + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_InterfaceTypeDescription; +struct _uno_Mapping; +struct _uno_Environment; + +/** + Function pointer declaration to acquire a UNO mapping. +*/ +typedef void (SAL_CALL * uno_AcquireMappingFunc)(struct _uno_Mapping *); + +/** + Function pointer declaration to release a UNO mapping. +*/ +typedef void (SAL_CALL * uno_ReleaseMappingFunc)(struct _uno_Mapping *); + +/** Function pointer declaration to map an interface from one environment to another. + + @param pMapping mapping + @param ppOut [inout] destination interface; existing interfaces are released + @param pInterface source interface + @param pInterfaceTypeDescr type description of the interface +*/ +typedef void (SAL_CALL * uno_MapInterfaceFunc)( + struct _uno_Mapping * pMapping, + void ** ppOut, void * pInterface, + struct _typelib_InterfaceTypeDescription * pInterfaceTypeDescr ); + + +#if defined( SAL_W32) +#pragma pack(push, 8) +#endif + +/** This is the binary specification of a mapping. +*/ +typedef struct _uno_Mapping +{ + /** Acquires mapping + */ + uno_AcquireMappingFunc acquire; + + /** Releases mapping. The last release may unload bridges. + */ + uno_ReleaseMappingFunc release; + + /** mapping function + */ + uno_MapInterfaceFunc mapInterface; +} uno_Mapping; + +#if defined( SAL_W32) +#pragma pack(pop) +#endif + +/** Gets an interface mapping from one environment to another. + + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment + @param pTo destination environment + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +void SAL_CALL uno_getMapping( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo, + rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/** Callback function pointer declaration to get a mapping. + + @param ppMapping inout mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose +*/ +typedef void (SAL_CALL * uno_getMappingFunc)( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo, + rtl_uString * pAddPurpose ); + +/** Registers a callback being called each time a mapping is demanded. + + @param pCallback callback function +*/ +void SAL_CALL uno_registerMappingCallback( + uno_getMappingFunc pCallback ) + SAL_THROW_EXTERN_C(); + +/** Revokes a mapping callback registration. + + @param pCallback callback function +*/ +void SAL_CALL uno_revokeMappingCallback( + uno_getMappingFunc pCallback ) + SAL_THROW_EXTERN_C(); + +/** Function pointer declaration to free a mapping. + + @param pMapping mapping to be freed +*/ +typedef void (SAL_CALL * uno_freeMappingFunc)( struct _uno_Mapping * pMapping ); + +/** Registers a mapping. A mapping registers itself on first acquire and revokes itself on last + release. The given freeMapping function is called by the runtime to cleanup any resources. + + @param ppMapping inout mapping to be registered + @param freeMapping called by runtime to delete mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose string; defaults to 0 +*/ +void SAL_CALL uno_registerMapping( + struct _uno_Mapping ** ppMapping, uno_freeMappingFunc freeMapping, + struct _uno_Environment * pFrom, struct _uno_Environment * pTo, rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/** Revokes a mapping. A mapping registers itself on first acquire and revokes itself on last + release. + + @param pMapping mapping to be revoked +*/ +void SAL_CALL uno_revokeMapping( + struct _uno_Mapping * pMapping ) + SAL_THROW_EXTERN_C(); + +/** Gets an interface mapping from one language environment to another by corresponding environment + type names. + + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment type name + @param pTo destination environment type name + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +void SAL_CALL uno_getMappingByName( + struct _uno_Mapping ** ppMapping, + rtl_uString * pFrom, + rtl_uString * pTo, + rtl_uString * pAddPurpose ) + SAL_THROW_EXTERN_C(); + +/* symbol exported by each language binding library */ +#define UNO_EXT_GETMAPPING "uno_ext_getMapping" + +/** Function pointer declaration to get a mapping from a loaded bridge. Bridges export a function + called uno_ext_getMapping() of this signature. + + @param ppMapping [inout] mapping; existing mapping will be released + @pFrom source environment + @pTo destination environment +*/ +typedef void (SAL_CALL * uno_ext_getMappingFunc)( + struct _uno_Mapping ** ppMapping, + struct _uno_Environment * pFrom, + struct _uno_Environment * pTo ); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/mapping.hxx b/cppu/inc/uno/mapping.hxx new file mode 100644 index 000000000000..a183cf089de3 --- /dev/null +++ b/cppu/inc/uno/mapping.hxx @@ -0,0 +1,357 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_MAPPING_HXX_ +#define _UNO_MAPPING_HXX_ + +#include <cppu/macros.hxx> +#include <rtl/alloc.h> +#include <rtl/ustring.hxx> +#include <uno/mapping.h> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include "cppu/unotype.hxx" +#include "uno/environment.hxx" + +typedef struct _typelib_TypeDescription typelib_TypeDescription; +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; +typedef struct _uno_Interface uno_Interface; + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace uno +{ + +/** C++ wrapper for C uno_Mapping. + + @see uno_Mapping +*/ +class Mapping +{ + uno_Mapping * _pMapping; + +public: + // these are here to force memory de/allocation to sal lib. + /** @internal */ + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) + { return ::rtl_allocateMemory( nSize ); } + /** @internal */ + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) + { ::rtl_freeMemory( pMem ); } + /** @internal */ + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) + { return pMem; } + /** @internal */ + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) + {} + + /** Holds a mapping from the specified source to the specified destination by environment + type names. + + @param rFrom type name of source environment + @param rTo type name of destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( + const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ) + SAL_THROW( () ); + + /** Holds a mapping from the specified source to the specified destination. + + @param pFrom source environment + @param pTo destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( + uno_Environment * pFrom, uno_Environment * pTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ) + SAL_THROW( () ); + + /** Holds a mapping from the specified source to the specified destination + environment. + + @param from source environment + @param to destination environment + @param rAddPurpose additional purpose + */ + inline Mapping(const Environment & rFrom, const Environment & rTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ) + SAL_THROW( () ); + + /** Constructor. + + @param pMapping another mapping + */ + inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW( () ); + + /** Copy constructor. + + @param rMapping another mapping + */ + inline Mapping( const Mapping & rMapping ) SAL_THROW( () ); + + /** Destructor. + */ + inline ~Mapping() SAL_THROW( () ); + + /** Sets a given mapping. + + @param pMapping another mapping + @return this mapping + */ + inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW( () ); + /** Sets a given mapping. + + @param rMapping another mapping + @return this mapping + */ + inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW( () ) + { return operator = ( rMapping._pMapping ); } + + /** Provides a pointer to the C mapping. The returned mapping is NOT acquired! + + @return UNacquired C mapping + */ + inline uno_Mapping * SAL_CALL get() const SAL_THROW( () ) + { return _pMapping; } + + /** Tests if a mapping is set. + + @return true if a mapping is set + */ + inline sal_Bool SAL_CALL is() const SAL_THROW( () ) + { return (_pMapping != 0); } + + /** Releases a set mapping. + */ + inline void SAL_CALL clear() SAL_THROW( () ); + + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW( () ); + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () ) + { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); } + + /** Maps an interface from one environment to another. + + @param pInterface source interface + @param rType type of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( + void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW( () ); + + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW( () ) + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); } + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () ) + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); } + + /** Maps an interface from one environment to another. + + @param ppOut inout mapped interface + @param pInterface source interface + @param rType type of interface to be mapped + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW( () ); +}; +//__________________________________________________________________________________________________ +inline Mapping::Mapping( + const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose ) + SAL_THROW( () ) + : _pMapping( 0 ) +{ + uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData ); +} +//__________________________________________________________________________________________________ +inline Mapping::Mapping( + uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose ) + SAL_THROW( () ) + : _pMapping( 0 ) +{ + uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData ); +} +//__________________________________________________________________________________________________ +inline Mapping::Mapping( + const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose ) + SAL_THROW( () ) + : _pMapping(0) +{ + uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData ); +} +//__________________________________________________________________________________________________ +inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW( () ) + : _pMapping( pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} +//__________________________________________________________________________________________________ +inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW( () ) + : _pMapping( rMapping._pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} +//__________________________________________________________________________________________________ +inline Mapping::~Mapping() SAL_THROW( () ) +{ + if (_pMapping) + (*_pMapping->release)( _pMapping ); +} +//__________________________________________________________________________________________________ +inline void Mapping::clear() SAL_THROW( () ) +{ + if (_pMapping) + { + (*_pMapping->release)( _pMapping ); + _pMapping = 0; + } +} +//__________________________________________________________________________________________________ +inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) SAL_THROW( () ) +{ + if (pMapping) + (*pMapping->acquire)( pMapping ); + if (_pMapping) + (*_pMapping->release)( _pMapping ); + _pMapping = pMapping; + return *this; +} +//__________________________________________________________________________________________________ +inline void Mapping::mapInterface( + void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const + SAL_THROW( () ) +{ + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + if (pTD) + { + (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD ); + TYPELIB_DANGER_RELEASE( pTD ); + } +} +//__________________________________________________________________________________________________ +inline void * Mapping::mapInterface( + void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const + SAL_THROW( () ) +{ + void * pOut = 0; + (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr ); + return pOut; +} +//__________________________________________________________________________________________________ +inline void * Mapping::mapInterface( + void * pInterface, const ::com::sun::star::uno::Type & rType ) const + SAL_THROW( () ) +{ + void * pOut = 0; + mapInterface( &pOut, pInterface, rType ); + return pOut; +} + +/** Deprecated. This function DOES NOT WORK with Purpose Environments + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) + + Maps an binary C UNO interface to be used in the currently used compiler environment. + + @tplparam C interface type + @param ppRet inout returned interface pointer + @param pUnoI binary C UNO interface + @return true if successful, false otherwise + + @deprecated +*/ +template< class C > +inline sal_Bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) SAL_THROW( () ) +{ + Mapping aMapping( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( + (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) ); + return (0 != *ppRet); +} +/** Deprecated. This function DOES NOT WORK with Purpose Environments + (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) + + Maps an UNO interface of the currently used compiler environment to binary C UNO. + + @tplparam C interface type + @param ppRet inout returned interface pointer + @param x interface reference + @return true if successful, false otherwise + + @deprecated +*/ +template< class C > +inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW( () ) +{ + Mapping aMapping( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( + (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) ); + return (0 != *ppRet); +} + +} +} +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/sequence2.h b/cppu/inc/uno/sequence2.h new file mode 100644 index 000000000000..d1a50a3743f5 --- /dev/null +++ b/cppu/inc/uno/sequence2.h @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _UNO_SEQUENCE2_H_ +#define _UNO_SEQUENCE2_H_ + +#include <sal/types.h> +#include <uno/data.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct _typelib_TypeDescriptionReference; +struct _typelib_TypeDescription; +typedef sal_Sequence uno_Sequence; + +/** Assigns a sequence. + + @param ppDest destinstaion sequence + @param pSource source sequence + @param pTypeDescr type description of the sequence and NOT of an element + @param release function called each time an interface needs to + be released; defaults (0) to uno +*/ +void SAL_CALL uno_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + struct _typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assigns a sequence. + + @param ppDest destinstaion sequence + @param pSource source sequence + @param pType type of the sequence and NOT of an element + @param release function called each time an interface needs to + be released; defaults (0) to uno +*/ +void SAL_CALL uno_type_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + struct _typelib_TypeDescriptionReference * pType, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Constructs a new sequence with given elements. + + @param ppSequence out parameter sequence; + 0 if memory allocation has failed + @param pTypeDescr type description of the sequence and NOT of an + element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +sal_Bool SAL_CALL uno_sequence_construct( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); +/** Constructs a new sequence with given elements. + + @param ppSequence out parameter sequence; + 0 if memory allocation has failed + @param pType type of the sequence and NOT of an element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +sal_Bool SAL_CALL uno_type_sequence_construct( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) + SAL_THROW_EXTERN_C(); + +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count + of one. + + @param ppSequence inout sequence + @param pTypeDescr type description of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +sal_Bool SAL_CALL uno_sequence_reference2One( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count + of one. + + @param ppSequence inout sequence + @param pType type of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +sal_Bool SAL_CALL uno_type_sequence_reference2One( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +/** Reallocates length of a sequence. This truncates a sequence or enlarges + it default constructing appended elements. + + @param ppSequence inout sequence + @param pTypeDescr type description of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +sal_Bool SAL_CALL uno_sequence_realloc( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescription * pTypeDescr, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); +/** Reallocates length of a sequence. This truncates a sequence or enlarges + it default constructing appended elements. + + @param ppSequence inout sequence + @param pType type of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to + be acquired; defaults (0) to uno + @param release function called each time an interface needs to + be released; defaults (0) to uno + @return false, if memoray allocation has failed +*/ +sal_Bool SAL_CALL uno_type_sequence_realloc( + uno_Sequence ** ppSequence, + struct _typelib_TypeDescriptionReference * pType, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppu/inc/uno/threadpool.h b/cppu/inc/uno/threadpool.h new file mode 100644 index 000000000000..0c647442e377 --- /dev/null +++ b/cppu/inc/uno/threadpool.h @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <sal/types.h> +#include <rtl/byteseq.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/*** + * Thread identifier administration. + ***/ +/** + Establishs an association between the current thread and the given thread identifier. + There can be only one association at a time. The association must be broken by + uno_releaseIdFromCurrentThread(). + This method is in general called by a bridge, that wants to bind a remote threadId + to a new thread. + + @param pThreadId a byte sequence, that contains the identifier of the current thread. + @return true, when the identifier was registered. + false, when the thread has already an identifier. The identifier was not + altered. ( This is in general a bug ). + + @see uno_releaseIdFromCurrentThread() + */ +sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ) + SAL_THROW_EXTERN_C(); + + +/** + Get the identifier of the current thread. + If no id has been bound for the thread before, a new one is generated and bound + to the thread. + For each call to uno_getIdOfCurrentThread(), a call to uno_releaseIdFromCurrentThread() + must be done. + + @param ppThreadId [out] Contains the (acquired) ThreadId. + @see uno_releaseIdFromCurrentThread() + */ +void SAL_CALL uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ) + SAL_THROW_EXTERN_C(); + + +/** + If the internal refcount drops to zero, the association betwen threadId and + thread is broken. + */ +void SAL_CALL uno_releaseIdFromCurrentThread() + SAL_THROW_EXTERN_C(); + + +struct _uno_ThreadPool; +typedef struct _uno_ThreadPool * uno_ThreadPool; + +/** + Creates a threadpool handle. Typically each remote bridge instances creates one + handle. + */ +uno_ThreadPool SAL_CALL +uno_threadpool_create() SAL_THROW_EXTERN_C(); + + +/** + Makes the current thread known to the threadpool. This function must be + called, BEFORE uno_threadpool_enter() is called and BEFORE a job for this + thread is put into the threadpool (avoid a race between this thread and + an incoming request/reply). + For every call to uno_threadpool_attach, a corrosponding call to + uno_threadpool_detach must be done. + + @param hPool The bridge threadpool handle previously created by uno_threadpool_create. + +*/ +void SAL_CALL +uno_threadpool_attach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +/** + This method is called to wait for a reply of a previously sent request. This is a + blocking method. uno_threadpool_attach() must have been called before. + + @param hPool the handle that was previously created by uno_threadpool_create(). + @param ppJob [out] the pointer, that was given by uno_threadpool_putJob + 0, when uno_threadpool_dispose() was the reason to fall off from threadpool. + @see uno_threadpool_dispose() + **/ +void SAL_CALL +uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob ) + SAL_THROW_EXTERN_C(); + +/** + Detaches the current thread from the threadpool. Must be called for + every call to uno_threadpool_attach. +*/ +void SAL_CALL +uno_threadpool_detach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +/** + Puts a job into the pool. A job may eiter be a request or a reply + (replies have a 0 in the doRequest parameter). This function is non-blocking. + + A request may either be synchronous or asynchronous. + If the request is synchronous, it is first looked up, + if there exists a handle with the given + identifier. If this is the case, the thread is woken up and the doRequest + function is called with the given pJob. If no handle exists, + a new thread is created and the given threadId is bound to the new thread. + + If the request is asynchronous, it is put into the queue of asynchronous + requests for the current threadid. The requests are always executed in a new + thread, even if the thread with the given id is waiting in the pool. No id is bound + to the newly created thread. The responsibilty is left to the bridge ( if it + wishes to bind a name). + + If pJob is a reply, there MUST be a thread with the given threadId waiting + for this reply. + + @param pThreadId The Id of the thread, that initialized this request. (In general a + remote threadid). + @param pJob The argument, that doRequest will get or that will be returned by + uno_threadpool_enter(). + @param doRequest The function, that shall be called to execute the request. + 0 if pJob is a reply. + @param bIsOneway True, if the request is asynchrons. False, if it is synchronous. + Set to sal_False, if pJob is a reply. + */ +void SAL_CALL +uno_threadpool_putJob( + uno_ThreadPool hPool, + sal_Sequence *pThreadId, + void *pJob, + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), + sal_Bool bIsOneway ) SAL_THROW_EXTERN_C(); + +/** + All threads, that are waiting on the hPool handle, are forced out of the pool. + The threads waiting with uno_threadpool_enter() will return with *ppJob == 0 + + Later calls to uno_threadpool_enter() using the hPool handle will also + return immeadiatly with *ppJob == 0. + + @param hPool The handle to be disposed. + In case, hPool is 0, this function joins on all threads created + by the threadpool administration. This may e.g. used to ensure, that + no threads are inside the cppu library anymore, in case it needs to get + unloaded. + + This function is called i.e. by a bridge, that is forced to dispose itself. + */ +void SAL_CALL +uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + + +/** Releases the previously with uno_threadpool_create() created handle. + The handle thus becomes invalid. It is an error to use the handle after + uno_threadpool_destroy(). + @see uno_threadpool_create() + */ +void SAL_CALL +uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); + +#ifdef __cplusplus +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |