LCOV - code coverage report
Current view: top level - comphelper/source/misc - servicedecl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 38 78.9 %
Date: 2012-08-25 Functions: 8 12 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 26 61.5 %

           Branch data     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                 :            : 
      21                 :            : #include "comphelper/servicedecl.hxx"
      22                 :            : #include "osl/diagnose.h"
      23                 :            : #include "rtl/string.hxx"
      24                 :            : #include "rtl/ustrbuf.hxx"
      25                 :            : #include "cppuhelper/implbase2.hxx"
      26                 :            : #include "comphelper/sequence.hxx"
      27                 :            : #include "com/sun/star/lang/XSingleComponentFactory.hpp"
      28                 :            : #include <vector>
      29                 :            : 
      30                 :            : using namespace com::sun::star;
      31                 :            : 
      32                 :            : namespace comphelper {
      33                 :            : namespace service_decl {
      34                 :            : 
      35                 :            : class ServiceDecl::Factory :
      36                 :            :         public cppu::WeakImplHelper2<lang::XSingleComponentFactory,
      37                 :            :                                      lang::XServiceInfo>,
      38                 :            :         private boost::noncopyable
      39                 :            : {
      40                 :            : public:
      41                 :       1150 :     explicit Factory( ServiceDecl const& rServiceDecl )
      42                 :       1150 :         : m_rServiceDecl(rServiceDecl) {}
      43                 :            : 
      44                 :            :     // XServiceInfo:
      45                 :            :     virtual rtl::OUString SAL_CALL getImplementationName()
      46                 :            :         throw (uno::RuntimeException);
      47                 :            :     virtual sal_Bool SAL_CALL supportsService( rtl::OUString const& name )
      48                 :            :         throw (uno::RuntimeException);
      49                 :            :     virtual uno::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames()
      50                 :            :         throw (uno::RuntimeException);
      51                 :            :     // XSingleComponentFactory:
      52                 :            :     virtual uno::Reference<uno::XInterface> SAL_CALL createInstanceWithContext(
      53                 :            :         uno::Reference<uno::XComponentContext> const& xContext )
      54                 :            :         throw (uno::Exception);
      55                 :            :     virtual uno::Reference<uno::XInterface> SAL_CALL
      56                 :            :     createInstanceWithArgumentsAndContext(
      57                 :            :     uno::Sequence<uno::Any> const& args,
      58                 :            :     uno::Reference<uno::XComponentContext> const& xContext )
      59                 :            :         throw (uno::Exception);
      60                 :            : 
      61                 :            : private:
      62                 :            :     virtual ~Factory();
      63                 :            : 
      64                 :            :     ServiceDecl const& m_rServiceDecl;
      65                 :            : };
      66                 :            : 
      67                 :       1150 : ServiceDecl::Factory::~Factory()
      68                 :            : {
      69         [ -  + ]:       2300 : }
      70                 :            : 
      71                 :            : // XServiceInfo:
      72                 :          0 : rtl::OUString ServiceDecl::Factory::getImplementationName()
      73                 :            :     throw (uno::RuntimeException)
      74                 :            : {
      75                 :          0 :     return m_rServiceDecl.getImplementationName();
      76                 :            : }
      77                 :            : 
      78                 :          0 : sal_Bool ServiceDecl::Factory::supportsService( rtl::OUString const& name )
      79                 :            :     throw (uno::RuntimeException)
      80                 :            : {
      81                 :          0 :     return m_rServiceDecl.supportsService(name);
      82                 :            : }
      83                 :            : 
      84                 :          0 : uno::Sequence<rtl::OUString> ServiceDecl::Factory::getSupportedServiceNames()
      85                 :            :     throw (uno::RuntimeException)
      86                 :            : {
      87                 :          0 :     return m_rServiceDecl.getSupportedServiceNames();
      88                 :            : }
      89                 :            : 
      90                 :            : // XSingleComponentFactory:
      91                 :        262 : uno::Reference<uno::XInterface> ServiceDecl::Factory::createInstanceWithContext(
      92                 :            :     uno::Reference<uno::XComponentContext> const& xContext )
      93                 :            :     throw (uno::Exception)
      94                 :            : {
      95                 :            :     return m_rServiceDecl.m_createFunc(
      96         [ +  - ]:        262 :         m_rServiceDecl, uno::Sequence<uno::Any>(), xContext );
      97                 :            : }
      98                 :            : 
      99                 :            : uno::Reference<uno::XInterface>
     100                 :       2599 : ServiceDecl::Factory::createInstanceWithArgumentsAndContext(
     101                 :            :     uno::Sequence<uno::Any > const& args,
     102                 :            :     uno::Reference<uno::XComponentContext> const& xContext )
     103                 :            :     throw (uno::Exception)
     104                 :            : {
     105                 :            :     return m_rServiceDecl.m_createFunc(
     106                 :       2599 :         m_rServiceDecl, args, xContext );
     107                 :            : }
     108                 :            : 
     109                 :       5778 : void * ServiceDecl::getFactory( sal_Char const* pImplName ) const
     110                 :            : {
     111         [ +  + ]:       5778 :     if (rtl_str_compare(m_pImplName, pImplName) == 0) {
     112 [ +  - ][ +  - ]:       1150 :         lang::XSingleComponentFactory * const pFac( new Factory(*this) );
     113                 :       1150 :         pFac->acquire();
     114                 :       1150 :         return pFac;
     115                 :            :     }
     116                 :       5778 :     return 0;
     117                 :            : }
     118                 :            : 
     119                 :        246 : uno::Sequence<rtl::OUString> ServiceDecl::getSupportedServiceNames() const
     120                 :            : {
     121         [ +  - ]:        246 :     std::vector<rtl::OUString> vec;
     122                 :            : 
     123                 :        246 :     rtl::OString const str(m_pServiceNames);
     124                 :        246 :     sal_Int32 nIndex = 0;
     125         [ -  + ]:        246 :     do {
     126                 :        246 :         rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) );
     127                 :            :         vec.push_back( rtl::OUString( token.getStr(), token.getLength(),
     128 [ +  - ][ +  - ]:        246 :                                       RTL_TEXTENCODING_ASCII_US ) );
     129                 :            :     }
     130                 :            :     while (nIndex >= 0);
     131                 :            : 
     132         [ +  - ]:        246 :     return comphelper::containerToSequence(vec);
     133                 :            : }
     134                 :            : 
     135                 :         20 : bool ServiceDecl::supportsService( ::rtl::OUString const& name ) const
     136                 :            : {
     137                 :         20 :     rtl::OString const str(m_pServiceNames);
     138                 :         20 :     sal_Int32 nIndex = 0;
     139         [ -  + ]:         20 :     do {
     140                 :         20 :         rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) );
     141         [ +  + ]:         20 :         if (name.equalsAsciiL( token.getStr(), token.getLength() ))
     142         [ +  + ]:         20 :             return true;
     143                 :            :     }
     144                 :            :     while (nIndex >= 0);
     145                 :         20 :     return false;
     146                 :            : }
     147                 :            : 
     148                 :          0 : rtl::OUString ServiceDecl::getImplementationName() const
     149                 :            : {
     150                 :          0 :     return rtl::OUString::createFromAscii(m_pImplName);
     151                 :            : }
     152                 :            : 
     153                 :            : } // namespace service_decl
     154                 :            : } // namespace comphelper
     155                 :            : 
     156                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10