LCOV - code coverage report
Current view: top level - forms/source/inc - forms_module_impl.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 51 98.0 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 26 48 54.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : #ifndef FORMS_MODULE_IMPLEMENTATION_INCLUDE_CONTEXT
       3                 :            :     #error "not to be included directly! use 'foo_module.hxx instead'!"
       4                 :            : #endif
       5                 :            : 
       6                 :            : #ifndef FORMS_MODULE_NAMESPACE
       7                 :            :     #error "set FORMS_MODULE_NAMESPACE to your namespace identifier!"
       8                 :            : #endif
       9                 :            : 
      10                 :            : #include <comphelper/sequence.hxx>
      11                 :            : 
      12                 :            : //.........................................................................
      13                 :            : namespace FORMS_MODULE_NAMESPACE
      14                 :            : {
      15                 :            : //.........................................................................
      16                 :            : 
      17                 :            :     using namespace ::com::sun::star::uno;
      18                 :            :     using namespace ::com::sun::star::lang;
      19                 :            :     using namespace ::com::sun::star::registry;
      20                 :            :     using namespace ::comphelper;
      21                 :            :     using namespace ::cppu;
      22                 :            : 
      23                 :            :     //=========================================================================
      24                 :            :     //= OFormsModule
      25                 :            :     //=========================================================================
      26                 :            : 
      27                 :            :     //--------------------------------------------------------------------------
      28                 :            :     //- registration helper
      29                 :            :     //--------------------------------------------------------------------------
      30                 :            : 
      31                 :            :     Sequence< ::rtl::OUString >*                OFormsModule::s_pImplementationNames = NULL;
      32                 :            :     Sequence< Sequence< ::rtl::OUString > >*    OFormsModule::s_pSupportedServices = NULL;
      33                 :            :     Sequence< sal_Int64 >*                      OFormsModule::s_pCreationFunctionPointers = NULL;
      34                 :            :     Sequence< sal_Int64 >*                      OFormsModule::s_pFactoryFunctionPointers = NULL;
      35                 :            : 
      36                 :            :     //--------------------------------------------------------------------------
      37                 :        300 :     void OFormsModule::registerComponent(
      38                 :            :         const ::rtl::OUString& _rImplementationName,
      39                 :            :         const Sequence< ::rtl::OUString >& _rServiceNames,
      40                 :            :         ComponentInstantiation _pCreateFunction,
      41                 :            :         FactoryInstantiation _pFactoryFunction)
      42                 :            :     {
      43         [ +  + ]:        300 :         if (!s_pImplementationNames)
      44                 :            :         {
      45                 :            :             OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
      46                 :            :                 "OFormsModule::registerComponent : inconsistent state (the pointers (1)) !");
      47         [ +  - ]:         30 :             s_pImplementationNames = new Sequence< ::rtl::OUString >;
      48         [ +  - ]:         30 :             s_pSupportedServices = new Sequence< Sequence< ::rtl::OUString > >;
      49         [ +  - ]:         30 :             s_pCreationFunctionPointers = new Sequence< sal_Int64 >;
      50         [ +  - ]:         30 :             s_pFactoryFunctionPointers = new Sequence< sal_Int64 >;
      51                 :            :         }
      52                 :            :         OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      53                 :            :             "OFormsModule::registerComponent : inconsistent state (the pointers (2)) !");
      54                 :            : 
      55                 :            :         OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
      56                 :            :                     &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
      57                 :            :                     &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
      58                 :            :             "OFormsModule::registerComponent : inconsistent state !");
      59                 :            : 
      60                 :        300 :         sal_Int32 nOldLen = s_pImplementationNames->getLength();
      61                 :        300 :         s_pImplementationNames->realloc(nOldLen + 1);
      62                 :        300 :         s_pSupportedServices->realloc(nOldLen + 1);
      63                 :        300 :         s_pCreationFunctionPointers->realloc(nOldLen + 1);
      64                 :        300 :         s_pFactoryFunctionPointers->realloc(nOldLen + 1);
      65                 :            : 
      66                 :        300 :         s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
      67                 :        300 :         s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
      68                 :        300 :         s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
      69                 :        300 :         s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
      70                 :        300 :     }
      71                 :            : 
      72                 :            :     //--------------------------------------------------------------------------
      73                 :        300 :     void OFormsModule::revokeComponent(const ::rtl::OUString& _rImplementationName)
      74                 :            :     {
      75         [ -  + ]:        300 :         if (!s_pImplementationNames)
      76                 :            :         {
      77                 :            :             OSL_FAIL("OFormsModule::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
      78                 :        300 :             return;
      79                 :            :         }
      80                 :            :         OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
      81                 :            :             "OFormsModule::revokeComponent : inconsistent state (the pointers) !");
      82                 :            :         OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
      83                 :            :                     &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
      84                 :            :                     &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
      85                 :            :             "OFormsModule::revokeComponent : inconsistent state !");
      86                 :            : 
      87                 :        300 :         sal_Int32 nLen = s_pImplementationNames->getLength();
      88                 :        300 :         const ::rtl::OUString* pImplNames = s_pImplementationNames->getConstArray();
      89         [ +  - ]:       1650 :         for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
      90                 :            :         {
      91         [ +  + ]:       1650 :             if (pImplNames->equals(_rImplementationName))
      92                 :            :             {
      93                 :        300 :                 removeElementAt(*s_pImplementationNames, i);
      94                 :        300 :                 removeElementAt(*s_pSupportedServices, i);
      95                 :        300 :                 removeElementAt(*s_pCreationFunctionPointers, i);
      96                 :        300 :                 removeElementAt(*s_pFactoryFunctionPointers, i);
      97                 :        300 :                 break;
      98                 :            :             }
      99                 :            :         }
     100                 :            : 
     101         [ +  + ]:        300 :         if (s_pImplementationNames->getLength() == 0)
     102                 :            :         {
     103         [ +  - ]:         30 :             delete s_pImplementationNames; s_pImplementationNames = NULL;
     104         [ +  - ]:         30 :             delete s_pSupportedServices; s_pSupportedServices = NULL;
     105         [ +  - ]:         30 :             delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
     106         [ +  - ]:         30 :             delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
     107                 :            :         }
     108                 :            :     }
     109                 :            : 
     110                 :            :     //--------------------------------------------------------------------------
     111                 :         72 :     Reference< XInterface > OFormsModule::getComponentFactory(
     112                 :            :         const ::rtl::OUString& _rImplementationName,
     113                 :            :         const Reference< XMultiServiceFactory >& _rxServiceManager)
     114                 :            :     {
     115                 :            :         OSL_ENSURE(_rxServiceManager.is(), "OFormsModule::getComponentFactory : invalid argument (service manager) !");
     116                 :            :         OSL_ENSURE(!_rImplementationName.isEmpty(), "OFormsModule::getComponentFactory : invalid argument (implementation name) !");
     117                 :            : 
     118         [ -  + ]:         72 :         if (!s_pImplementationNames)
     119                 :            :         {
     120                 :            :             OSL_FAIL("OFormsModule::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
     121         [ #  # ]:          0 :             return NULL;
     122                 :            :         }
     123                 :            :         OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
     124                 :            :             "OFormsModule::getComponentFactory : inconsistent state (the pointers) !");
     125                 :            :         OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
     126                 :            :                     &&  (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
     127                 :            :                     &&  (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
     128                 :            :             "OFormsModule::getComponentFactory : inconsistent state !");
     129                 :            : 
     130                 :            : 
     131                 :         72 :         Reference< XInterface > xReturn;
     132                 :            : 
     133                 :            : 
     134                 :         72 :         sal_Int32 nLen = s_pImplementationNames->getLength();
     135                 :         72 :         const ::rtl::OUString* pImplName = s_pImplementationNames->getConstArray();
     136                 :         72 :         const Sequence< ::rtl::OUString >* pServices = s_pSupportedServices->getConstArray();
     137                 :         72 :         const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
     138                 :         72 :         const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
     139                 :            : 
     140         [ +  - ]:        336 :         for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
     141                 :            :         {
     142         [ +  + ]:        336 :             if (pImplName->equals(_rImplementationName))
     143                 :            :             {
     144                 :         72 :                 const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
     145                 :         72 :                 const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
     146                 :            : 
     147 [ +  - ][ +  - ]:         72 :                 xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
     148         [ +  - ]:         72 :                 if (xReturn.is())
     149                 :            :                 {
     150         [ +  - ]:         72 :                     xReturn->acquire();
     151 [ +  - ][ +  - ]:         72 :                     return xReturn.get();
     152                 :            :                 }
     153                 :            :             }
     154                 :            :         }
     155                 :            : 
     156         [ #  # ]:         72 :         return NULL;
     157                 :            :     }
     158                 :            : 
     159                 :            : //.........................................................................
     160                 :            : }   // namespace FORMS_MODULE_NAMESPACE
     161                 :            : //.........................................................................
     162                 :            : 
     163                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10