LCOV - code coverage report
Current view: top level - include/comphelper - uno3.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 18 0.0 %
Date: 2014-04-14 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_COMPHELPER_UNO3_HXX
      21             : #define INCLUDED_COMPHELPER_UNO3_HXX
      22             : 
      23             : #include <osl/interlck.h>
      24             : #include <rtl/instance.hxx>
      25             : #include <comphelper/types.hxx>
      26             : #include <com/sun/star/uno/XAggregation.hpp>
      27             : #include <comphelper/sequence.hxx>
      28             : #include <cppuhelper/typeprovider.hxx>
      29             : 
      30             : 
      31             : namespace comphelper
      32             : {
      33             : 
      34             : 
      35             : 
      36             : 
      37             :     /// manipulate ref counts without calling acquire/release
      38           0 :     inline oslInterlockedCount increment(oslInterlockedCount& _counter) { return osl_atomic_increment(&_counter); }
      39           0 :     inline oslInterlockedCount decrement(oslInterlockedCount& _counter) { return osl_atomic_decrement(&_counter); }
      40             : 
      41             : 
      42             : 
      43             :     /** used for declaring UNO3-Defaults, i.e. acquire/release
      44             :     */
      45             :     #define DECLARE_UNO3_DEFAULTS(classname, baseclass) \
      46             :         virtual void    SAL_CALL acquire() throw() SAL_OVERRIDE { baseclass::acquire(); }    \
      47             :         virtual void    SAL_CALL release() throw() SAL_OVERRIDE { baseclass::release(); }
      48             : 
      49             :     /** used for declaring UNO3-Defaults, i.e. acquire/release if you want to forward all queryInterfaces to the base class,
      50             :         (e.g. if you overload queryAggregation)
      51             :     */
      52             :     #define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass) \
      53             :         virtual void            SAL_CALL acquire() throw() SAL_OVERRIDE { baseclass::acquire(); } \
      54             :         virtual void            SAL_CALL release() throw() SAL_OVERRIDE { baseclass::release(); }    \
      55             :         virtual ::com::sun::star::uno::Any  SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
      56             :             { return baseclass::queryInterface(_rType); }
      57             : 
      58             :     /** Use this macro to forward XComponent methods to base class
      59             : 
      60             :         When using the ::cppu::WeakComponentImplHelper base classes to
      61             :         implement a UNO interface, a problem occurs when the interface
      62             :         itself already derives from XComponent (like e.g. awt::XWindow
      63             :         or awt::XControl): ::cppu::WeakComponentImplHelper is then
      64             :         still abstract. Using this macro in the most derived class
      65             :         definition provides overrides for the XComponent methods,
      66             :         forwarding them to the given baseclass.
      67             : 
      68             :         @param classname
      69             :         Name of the class this macro is issued within
      70             : 
      71             :         @param baseclass
      72             :         Name of the baseclass that should have the XInterface methods
      73             :         forwarded to - that's usually the WeakComponentImplHelperN base
      74             : 
      75             :         @param implhelper
      76             :         Name of the baseclass that should have the XComponent methods
      77             :         forwarded to - in the case of the WeakComponentImplHelper,
      78             :         that would be ::cppu::WeakComponentImplHelperBase
      79             :     */
      80             :     #define DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS(classname, baseclass, implhelper) \
      81             :         virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { baseclass::acquire(); }   \
      82             :         virtual void SAL_CALL release() throw() SAL_OVERRIDE { baseclass::release(); }   \
      83             :         virtual ::com::sun::star::uno::Any  SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
      84             :             { return baseclass::queryInterface(_rType); }                               \
      85             :         virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
      86             :         {                                                                               \
      87             :             implhelper::dispose();                                                      \
      88             :         }                                                                               \
      89             :         virtual void SAL_CALL addEventListener(                                         \
      90             :             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
      91             :         {                                                                               \
      92             :             implhelper::addEventListener(xListener);                                        \
      93             :         }                                                                               \
      94             :         virtual void SAL_CALL removeEventListener(                                      \
      95             :             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
      96             :         {                                                                               \
      97             :             implhelper::removeEventListener(xListener);                                 \
      98             :         }
      99             : 
     100             :     //= deriving from multiple XInterface-derived classes
     101             : 
     102             :     //= forwarding/merging XInterface funtionality
     103             : 
     104             :     #define DECLARE_XINTERFACE( )   \
     105             :         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
     106             :         virtual void SAL_CALL acquire() throw() SAL_OVERRIDE; \
     107             :         virtual void SAL_CALL release() throw() SAL_OVERRIDE;
     108             : 
     109             :     #define IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
     110             :         void SAL_CALL classname::acquire() throw() { refcountbase::acquire(); } \
     111             :         void SAL_CALL classname::release() throw() { refcountbase::release(); }
     112             : 
     113             :     #define IMPLEMENT_FORWARD_XINTERFACE2( classname, refcountbase, baseclass2 ) \
     114             :         IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
     115             :         ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
     116             :         { \
     117             :             ::com::sun::star::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
     118             :             if ( !aReturn.hasValue() ) \
     119             :                 aReturn = baseclass2::queryInterface( _rType ); \
     120             :             return aReturn; \
     121             :         }
     122             : 
     123             :     #define IMPLEMENT_FORWARD_XINTERFACE3( classname, refcountbase, baseclass2, baseclass3 ) \
     124             :         IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \
     125             :         ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
     126             :         { \
     127             :             ::com::sun::star::uno::Any aReturn = refcountbase::queryInterface( _rType ); \
     128             :             if ( !aReturn.hasValue() ) \
     129             :             { \
     130             :                 aReturn = baseclass2::queryInterface( _rType ); \
     131             :                 if ( !aReturn.hasValue() ) \
     132             :                     aReturn = baseclass3::queryInterface( _rType ); \
     133             :             } \
     134             :             return aReturn; \
     135             :         }
     136             : 
     137             : 
     138             :     //= forwarding/merging XTypeProvider funtionality
     139             : 
     140             :     #define DECLARE_XTYPEPROVIDER( )    \
     141             :         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
     142             :         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     143             : 
     144             :     #define IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) \
     145             :         ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL classname::getImplementationId(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
     146             :         { \
     147             :             return css::uno::Sequence<sal_Int8>(); \
     148             :         }
     149             : 
     150             :     #define IMPLEMENT_FORWARD_XTYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
     151             :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL classname::getTypes(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
     152             :         { \
     153             :             return ::comphelper::concatSequences( \
     154             :                 baseclass1::getTypes(), \
     155             :                 baseclass2::getTypes() \
     156             :             ); \
     157             :         } \
     158             :         \
     159             :         IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
     160             : 
     161             :     #define IMPLEMENT_FORWARD_XTYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \
     162             :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL classname::getTypes(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
     163             :         { \
     164             :             return ::comphelper::concatSequences( \
     165             :                 baseclass1::getTypes(), \
     166             :                 baseclass2::getTypes(), \
     167             :                 baseclass3::getTypes() \
     168             :             ); \
     169             :         } \
     170             :         \
     171             :         IMPLEMENT_GET_IMPLEMENTATION_ID( classname )
     172             : 
     173             : 
     174             : 
     175             :     /** ask for an iface of an aggregated object
     176             :         usage:<br/>
     177             :             Reference<XFoo> xFoo;<br/>
     178             :             if (query_aggregation(xAggregatedObject, xFoo))<br/>
     179             :                 ....
     180             :     */
     181             :     template <class iface>
     182           0 :     bool query_aggregation(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation >& _rxAggregate, ::com::sun::star::uno::Reference<iface>& _rxOut)
     183             :     {
     184           0 :         _rxOut = static_cast<iface*>(NULL);
     185           0 :         if (_rxAggregate.is())
     186             :         {
     187             :             ::com::sun::star::uno::Any aCheck = _rxAggregate->queryAggregation(
     188           0 :                 cppu::UnoType<iface>::get());
     189           0 :             if (aCheck.hasValue())
     190           0 :                 _rxOut = *(::com::sun::star::uno::Reference<iface>*)aCheck.getValue();
     191             :         }
     192           0 :         return _rxOut.is();
     193             :     }
     194             : 
     195             :     /** ask for an iface of an object
     196             :         usage:<br/>
     197             :             Reference<XFoo> xFoo;<br/>
     198             :             if (query_interface(xAnything, xFoo))<br/>
     199             :                 ....
     200             :     */
     201             :     template <class iface>
     202           0 :     bool query_interface(const InterfaceRef& _rxObject, ::com::sun::star::uno::Reference<iface>& _rxOut)
     203             :     {
     204           0 :         _rxOut = static_cast<iface*>(NULL);
     205           0 :         if (_rxObject.is())
     206             :         {
     207             :             ::com::sun::star::uno::Any aCheck = _rxObject->queryInterface(
     208           0 :                 cppu::UnoType<iface>::get());
     209           0 :             if(aCheck.hasValue())
     210             :             {
     211           0 :                 _rxOut = *(::com::sun::star::uno::Reference<iface>*)aCheck.getValue();
     212           0 :                 return _rxOut.is();
     213           0 :             }
     214             :         }
     215           0 :         return false;
     216             :     }
     217             : 
     218             : 
     219             : }   // namespace comphelper
     220             : 
     221             : 
     222             : #endif // INCLUDED_COMPHELPER_UNO3_HXX
     223             : 
     224             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10