LCOV - code coverage report
Current view: top level - include/comphelper - types.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 15 18 83.3 %
Date: 2014-11-03 Functions: 40 67 59.7 %
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_TYPES_HXX
      21             : #define INCLUDED_COMPHELPER_TYPES_HXX
      22             : 
      23             : #include <com/sun/star/uno/Any.hxx>
      24             : #include <com/sun/star/uno/Reference.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      27             : #include <com/sun/star/lang/XTypeProvider.hpp>
      28             : #include <com/sun/star/lang/XComponent.hpp>
      29             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      30             : #include <comphelper/comphelperdllapi.h>
      31             : #include <cppu/unotype.hxx>
      32             : 
      33             : namespace com { namespace sun { namespace star { namespace awt {
      34             :     struct FontDescriptor;
      35             : } } } }
      36             : 
      37             : 
      38             : namespace comphelper
      39             : {
      40             : 
      41             :     typedef css::uno::Reference< css::uno::XInterface >           InterfaceRef;
      42             :     typedef css::uno::Sequence< OUString >                StringSequence;
      43             : 
      44             : 
      45             :     /** compare the two given Anys
      46             :         The comparison is deep, means if one of the Any's contains an Any which contains an Any ..., this is resolved <br/>
      47             :         Other types recognized currently : FontDescriptor, ::com::sun::star::util::Date/Tim/DateTime, css::uno::Sequence<sal_Int8>
      48             :     */
      49             :     COMPHELPER_DLLPUBLIC bool compare(const css::uno::Any& rLeft, const css::uno::Any& rRight);
      50             : 
      51             : 
      52             :     /** compare two FontDescriptor's
      53             :     */
      54             :     COMPHELPER_DLLPUBLIC bool   operator ==(const css::awt::FontDescriptor& _rLeft, const css::awt::FontDescriptor& _rRight);
      55          93 :     inline  bool    operator !=(const css::awt::FontDescriptor& _rLeft, const css::awt::FontDescriptor& _rRight)
      56             :     {
      57          93 :         return !(_rLeft == _rRight);
      58             :     }
      59             : 
      60             : 
      61             :     /// returns sal_True if objects of the types given are "compatible"
      62             :     COMPHELPER_DLLPUBLIC bool isAssignableFrom(const css::uno::Type& _rAssignable, const css::uno::Type& _rFrom);
      63             : 
      64             : 
      65             :     /** just a small shortcut ...
      66             :         check if a type you have at hand at runtime is equal to another type you have at compile time
      67             :         if all our compiler would accept function calls with explicit template arguments (like
      68             :         isA<classFoo>(runtimeType)), we wouldn't need the second parameter. But unfortunately at
      69             :         least the current solaris compiler doesn't allow this ....
      70             :         So this function is nearly senseless ....
      71             :     */
      72             :     template <class TYPE>
      73       11426 :     bool isA(const css::uno::Type& _rType, TYPE* pDummy)
      74             :     {
      75       11426 :         return  _rType.equals(cppu::getTypeFavourUnsigned(pDummy));
      76             :     }
      77             : 
      78             : 
      79             :     /** check if a type you have at hand at runtime is equal to another type you have at compile time
      80             :         same comment as for the other isA ....
      81             :     */
      82             :     template <class TYPE>
      83           0 :     bool isA(const css::uno::Any& _rVal, TYPE* pDummy)
      84             :     {
      85           0 :         return  _rVal.getValueType().equals(
      86           0 :             cppu::getTypeFavourUnsigned(pDummy));
      87             :     }
      88             : 
      89             : 
      90             :     /** check if a type you have at hand at runtime is equal to another type you have at compile time
      91             :     */
      92             :     template <class TYPE>
      93             :     bool isAReference(const css::uno::Any& _rVal, TYPE*)
      94             :     {
      95             :         return  _rVal.getValueType().equals(
      96             :             cppu::getTypeFavourUnsigned(
      97             :                 static_cast<css::uno::Reference<TYPE>*>(NULL)));
      98             :     }
      99             : 
     100             : 
     101             :     /** ask the given object for an XComponent interface and dispose on it
     102             :     */
     103             :     template <class TYPE>
     104       15697 :     void disposeComponent(css::uno::Reference<TYPE>& _rxComp)
     105             :     {
     106       15697 :         css::uno::Reference<css::lang::XComponent> xComp(_rxComp, css::uno::UNO_QUERY);
     107       15697 :         if (xComp.is())
     108             :         {
     109        3548 :             xComp->dispose();
     110        3544 :             _rxComp = NULL;
     111       15697 :         }
     112       15693 :     }
     113             : 
     114             :     template <class TYPE>
     115             :     bool getImplementation(TYPE*& _pObject, const css::uno::Reference< css::uno::XInterface >& _rxIFace)
     116             :     {
     117             :         _pObject = NULL;
     118             :         css::uno::Reference< css::lang::XUnoTunnel > xTunnel(_rxIFace, css::uno::UNO_QUERY);
     119             :         if (xTunnel.is())
     120             :             _pObject = reinterpret_cast< TYPE* >(xTunnel->getSomething(TYPE::getUnoTunnelImplementationId()));
     121             : 
     122             :         return (_pObject != NULL);
     123             :     }
     124             : 
     125             : 
     126             : 
     127             :     /** get a com::sun::star::awt::FontDescriptor that is fully initialized with
     128             :         the XXX_DONTKNOW enum values (which isn't the case if you instantiate it
     129             :         via the default constructor)
     130             :     */
     131             :     COMPHELPER_DLLPUBLIC css::awt::FontDescriptor    getDefaultFont();
     132             : 
     133             :     /** examine a sequence for the com.sun.star.uno::Type of it's elements.
     134             :     */
     135             :     COMPHELPER_DLLPUBLIC css::uno::Type getSequenceElementType(const css::uno::Type& _rSequenceType);
     136             : 
     137             : 
     138             : //= replacement of the former UsrAny.getXXX methods
     139             : 
     140             :     // may be used if you need the return value just as temporary, else it's may be too inefficient ....
     141             : 
     142             :     // no, we don't use templates here. This would lead to a lot of implicit uses of the conversion methods,
     143             :     // which would be difficult to trace ...
     144             : 
     145             :     COMPHELPER_DLLPUBLIC sal_Int64      getINT64(const css::uno::Any& _rAny);
     146             :     COMPHELPER_DLLPUBLIC sal_Int32      getINT32(const css::uno::Any& _rAny);
     147             :     COMPHELPER_DLLPUBLIC sal_Int16      getINT16(const css::uno::Any& _rAny);
     148             :     COMPHELPER_DLLPUBLIC double         getDouble(const css::uno::Any& _rAny);
     149             :     COMPHELPER_DLLPUBLIC float          getFloat(const css::uno::Any& _rAny);
     150             :     COMPHELPER_DLLPUBLIC OUString    getString(const css::uno::Any& _rAny);
     151             :     COMPHELPER_DLLPUBLIC bool       getBOOL(const css::uno::Any& _rAny);
     152             : 
     153             :     COMPHELPER_DLLPUBLIC sal_Int32      getEnumAsINT32(const css::uno::Any& _rAny) throw(css::lang::IllegalArgumentException);
     154             : 
     155             : //= replacement of some former UsrAny.setXXX methods - can be used with rvalues
     156         977 :     inline void setBOOL(css::uno::Any& _rAny, bool _b)
     157         977 :     { _rAny.setValue(&_b, ::getBooleanCppuType()); }
     158             : 
     159             : //= extension of ::cppu::makeAny()
     160        1340 :     inline css::uno::Any makeBoolAny(bool _b)
     161        1340 :     { return css::uno::Any(&_b, ::getBooleanCppuType()); }
     162             : 
     163             : 
     164             : }   // namespace comphelper
     165             : 
     166             : 
     167             : #endif // INCLUDED_COMPHELPER_TYPES_HXX
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10