LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/connectivity - CommonTools.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 28 100.0 %
Date: 2013-07-09 Functions: 42 46 91.3 %
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             : #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
      20             : #define _CONNECTIVITY_COMMONTOOLS_HXX_
      21             : 
      22             : #include <rtl/ref.hxx>
      23             : #include <rtl/ustring.hxx>
      24             : #include <com/sun/star/lang/DisposedException.hpp>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #ifndef _VECTOR_
      27             : #include <vector>
      28             : #endif
      29             : #include <cppuhelper/weakref.hxx>
      30             : #include <comphelper/stl_types.hxx>
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      33             : #include <osl/interlck.h>
      34             : #include <com/sun/star/uno/XComponentContext.hpp>
      35             : #include "connectivity/dbtoolsdllapi.hxx"
      36             : 
      37             : namespace com { namespace sun { namespace star { namespace util {
      38             :     struct Date;
      39             :     struct DateTime;
      40             :     struct Time;
      41             : }
      42             : }}}
      43             : 
      44             : #ifdef SOLAR_JAVA
      45             : namespace jvmaccess { class VirtualMachine; }
      46             : #endif
      47             : 
      48             : namespace connectivity
      49             : {
      50             :     //------------------------------------------------------------------------------
      51             :     OOO_DLLPUBLIC_DBTOOLS sal_Bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape);
      52        3153 :     inline sal_Bool match(const OUString &rWild, const OUString &rStr, const sal_Unicode cEscape)
      53             :     {
      54        3153 :         return match(rWild.getStr(), rStr.getStr(), cEscape);
      55             :     }
      56             :     // typedefs
      57             :     typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
      58             :     typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>    OSQLTable;
      59             : 
      60             :     DECLARE_STL_MAP(OUString,OSQLTable,comphelper::UStringMixLess,  OSQLTables);
      61             : 
      62             :     // -------------------------------------------------------------------------
      63             :     // class ORefVector allows reference counting on a std::vector
      64             :     // -------------------------------------------------------------------------
      65             :     template< class VectorVal > class ORefVector
      66             :     {
      67             :         std::vector< VectorVal > m_vector;
      68             :         oslInterlockedCount         m_refCount;
      69             : 
      70             :     protected:
      71        5541 :         virtual ~ORefVector(){}
      72             :     public:
      73             :         typedef std::vector< VectorVal > Vector;
      74             : 
      75        2313 :         ORefVector() : m_refCount(0) {}
      76         732 :         ORefVector(size_t _st) : m_vector(_st) , m_refCount(0) {}
      77         240 :         ORefVector(const ORefVector& _rRH) : m_vector(_rRH.m_vector),m_refCount(0)
      78             :         {
      79         240 :         }
      80           5 :         ORefVector& operator=(const ORefVector& _rRH)
      81             :         {
      82           5 :             if ( &_rRH != this )
      83             :             {
      84           5 :                 m_vector = _rRH.m_vector;
      85             :             }
      86           5 :             return *this;
      87             :         }
      88             : 
      89      139532 :         std::vector< VectorVal > & get() { return m_vector; }
      90        7444 :         std::vector< VectorVal > const & get() const { return m_vector; }
      91             : 
      92        2939 :         inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
      93        2939 :             { return ::rtl_allocateMemory( nSize ); }
      94        2923 :         inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
      95        2923 :             { ::rtl_freeMemory( pMem ); }
      96             :         inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW(())
      97             :             { return pMem; }
      98             :         inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW(())
      99             :             {}
     100             : 
     101        6147 :         void acquire()
     102             :         {
     103        6147 :             osl_atomic_increment( &m_refCount );
     104        6147 :         }
     105        6125 :         void release()
     106             :         {
     107        6125 :             if (! osl_atomic_decrement( &m_refCount ))
     108        2923 :                 delete this;
     109        6125 :         }
     110             : 
     111             :     };
     112             :     // -------------------------------------------------------------------------
     113             :     // class ORowVector incudes refcounting and initialze himself
     114             :     // with at least one element. This first element is reserved for
     115             :     // the bookmark
     116             :     // -------------------------------------------------------------------------
     117        1627 :     template< class VectorVal > class ORowVector : public  ORefVector< VectorVal >
     118             :     {
     119             :     public:
     120         392 :         ORowVector() : ORefVector< VectorVal >(1){}
     121         340 :         ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
     122         340 :             {}
     123             :     };
     124             : 
     125             :     typedef ORefVector< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > OSQLColumns;
     126             : 
     127             :     // =======================================================================================
     128             :     // search from __first to __last the column with the name _rVal
     129             :     // when no such column exist __last is returned
     130             :     OOO_DLLPUBLIC_DBTOOLS
     131             :     OSQLColumns::Vector::const_iterator find(   OSQLColumns::Vector::const_iterator __first,
     132             :                                         OSQLColumns::Vector::const_iterator __last,
     133             :                                         const OUString& _rVal,
     134             :                                         const ::comphelper::UStringMixEqual& _rCase);
     135             :     // =======================================================================================
     136             :     // search from __first to __last the column with the realname _rVal
     137             :     // when no such column exist __last is returned
     138             :     OOO_DLLPUBLIC_DBTOOLS
     139             :     OSQLColumns::Vector::const_iterator findRealName(   OSQLColumns::Vector::const_iterator __first,
     140             :                                                 OSQLColumns::Vector::const_iterator __last,
     141             :                                                 const OUString& _rVal,
     142             :                                                 const ::comphelper::UStringMixEqual& _rCase);
     143             : 
     144             :     // =======================================================================================
     145             :     // the first two find methods are much faster than the one below
     146             :     // =======================================================================================
     147             :     // search from __first to __last the column with the property _rProp equals the value _rVal
     148             :     // when no such column exist __last is returned
     149             :     OOO_DLLPUBLIC_DBTOOLS
     150             :     OSQLColumns::Vector::const_iterator find(   OSQLColumns::Vector::const_iterator __first,
     151             :                                         OSQLColumns::Vector::const_iterator __last,
     152             :                                         const OUString& _rProp,
     153             :                                         const OUString& _rVal,
     154             :                                         const ::comphelper::UStringMixEqual& _rCase);
     155             : 
     156             :     OOO_DLLPUBLIC_DBTOOLS void checkDisposed(sal_Bool _bThrow) throw ( ::com::sun::star::lang::DisposedException );
     157             : 
     158             : #ifdef SOLAR_JAVA
     159             :     /** creates a java virtual machine
     160             :         @param  _rxContext
     161             :             The ORB.
     162             :         @return
     163             :             The JavaVM.
     164             :     */
     165             :     OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
     166             : 
     167             :     /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
     168             :         @param  _pJVM
     169             :             The JavaVM.
     170             :         @param  _sClassName
     171             :             The class name to look for.
     172             :     */
     173             :     OOO_DLLPUBLIC_DBTOOLS sal_Bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName );
     174             : #endif
     175             : }
     176             : 
     177             : //==================================================================================
     178             : 
     179             : #define DECLARE_SERVICE_INFO()  \
     180             :     virtual OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException); \
     181             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
     182             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException) \
     183             : 
     184             : #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname)  \
     185             :     OUString SAL_CALL classname::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)   \
     186             :     {   \
     187             :         return OUString::createFromAscii(implasciiname); \
     188             :     }   \
     189             :     ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)  \
     190             :     {   \
     191             :         ::com::sun::star::uno::Sequence< OUString > aSupported(1);   \
     192             :         aSupported[0] = OUString::createFromAscii(serviceasciiname); \
     193             :         return aSupported;  \
     194             :     }   \
     195             :     sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
     196             :     {   \
     197             :         Sequence< OUString > aSupported(getSupportedServiceNames());             \
     198             :         const OUString* pSupported = aSupported.getConstArray();                 \
     199             :         const OUString* pEnd = pSupported + aSupported.getLength();              \
     200             :         for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)   \
     201             :             ;                                                                           \
     202             :                                                                                         \
     203             :         return pSupported != pEnd;                                                      \
     204             :     }   \
     205             : 
     206             : //==================================================================================
     207             : 
     208             : #endif // _CONNECTIVITY_COMMONTOOLS_HXX_
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10