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

Generated by: LCOV version 1.10